def create_store(reducer, initial_state=None, enhancer=None):
if enhancer is not None:<EOL><INDENT>if not hasattr(enhancer, '<STR_LIT>'):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>return enhancer(create_store)(reducer, initial_state)<EOL><DEDENT>if not hasattr(reducer, '<STR_LIT>'):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>current_reducer = [reducer]<EOL>current_state = [initial_state]<EOL>current_listeners = [[]]<EOL>next_listeners = [current_listeners[<NUM_LIT:0>]]<EOL>is_dispatching = [False]<EOL>def ensure_can_mutate_next_listeners():<EOL><INDENT>if next_listeners[<NUM_LIT:0>] == current_listeners[<NUM_LIT:0>]:<EOL><INDENT>next_listeners[<NUM_LIT:0>] = current_listeners[<NUM_LIT:0>][:]<EOL><DEDENT><DEDENT>def get_state():<EOL><INDENT>return current_state[<NUM_LIT:0>]<EOL><DEDENT>def subscribe(listener):<EOL><INDENT>if not hasattr(listener, '<STR_LIT>'):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>is_subscribed = [True]  <EOL>ensure_can_mutate_next_listeners()<EOL>next_listeners[<NUM_LIT:0>].append(listener)<EOL>def unsubcribe():<EOL><INDENT>if not is_subscribed[<NUM_LIT:0>]:<EOL><INDENT>return<EOL><DEDENT>is_subscribed[<NUM_LIT:0>] = False<EOL>ensure_can_mutate_next_listeners()<EOL>index = next_listeners[<NUM_LIT:0>].index(listener)<EOL>next_listeners[<NUM_LIT:0>].pop(index)<EOL><DEDENT>return unsubcribe<EOL><DEDENT>def dispatch(action):<EOL><INDENT>if not isinstance(action, dict):<EOL><INDENT>raise TypeError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if action.get('<STR_LIT:type>') is None:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if is_dispatching[<NUM_LIT:0>]:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>try:<EOL><INDENT>is_dispatching[<NUM_LIT:0>] = True<EOL>current_state[<NUM_LIT:0>] = current_reducer[<NUM_LIT:0>](current_state[<NUM_LIT:0>], action)<EOL><DEDENT>finally:<EOL><INDENT>is_dispatching[<NUM_LIT:0>] = False<EOL><DEDENT>listeners = current_listeners[<NUM_LIT:0>] = next_listeners[<NUM_LIT:0>]<EOL>for listener in listeners:<EOL><INDENT>listener()<EOL><DEDENT>return action<EOL><DEDENT>def replace_reducer(next_reducer):<EOL><INDENT>if not hasattr(next_reducer, '<STR_LIT>'):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>current_reducer[<NUM_LIT:0>] = next_reducer<EOL>dispatch({'<STR_LIT:type>': ActionTypes.INIT})<EOL><DEDENT>dispatch({'<STR_LIT:type>': ActionTypes.INIT})<EOL>return StoreDict(<EOL>dispatch=dispatch,<EOL>subscribe=subscribe,<EOL>get_state=get_state,<EOL>replace_reducer=replace_reducer,<EOL>)<EOL>
redux in a nutshell.

observable has been omitted.

Args:
    reducer: root reducer function for the state tree
    initial_state: optional initial state data
    enhancer: optional enhancer function for middleware etc.

Returns:
    a Pydux store