Skip to content

Commit 1111414

Browse files
committed
Finished create_store tests
1 parent c3be668 commit 1111414

File tree

3 files changed

+431
-9
lines changed

3 files changed

+431
-9
lines changed

python_redux/create_store.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def get_state():
8383
* @param {Function} listener A callback to be invoked on every dispatch.
8484
* @returns {Function} A function to remove this change listener.
8585
"""
86-
def subscribe(listener):
86+
def subscribe(listener=None):
8787
nonlocal next_listeners
8888
if not hasattr(listener, '__call__'):
8989
raise Exception('Expected listener to be a function')
@@ -128,12 +128,12 @@ def unsubscribe():
128128
* Note that, if you use a custom middleware, it may wrap `dispatch()` to
129129
* return something else (for example, a Promise you can await).
130130
"""
131-
def dispatch(action):
131+
def dispatch(action=None):
132132
nonlocal is_dispatching, current_state, current_listeners, next_listeners
133133
if not type(action) == dict:
134134
raise Exception('Actions must be plain dictionaries. Consider adding middleware to change this')
135-
if not action.get('type'):
136-
raise Exception('Actions may not have have an undefined "type" property.\n Have you misspelled a constants?')
135+
if action.get('type') is None:
136+
raise Exception('Actions may not have an undefined "type" property.\n Have you misspelled a constants?')
137137
if is_dispatching:
138138
raise Exception('Reducers may not dispatch actions')
139139

@@ -158,16 +158,14 @@ def dispatch(action):
158158
* @param {Function} nextReducer The reducer for the store to use instead.
159159
* @returns {void}
160160
"""
161-
def replace_reducer(next_reducer):
161+
def replace_reducer(next_reducer=None):
162162
nonlocal current_reducer
163163
if not hasattr(next_reducer, '__call__'):
164164
raise Exception('Expected next_reducer to be a function')
165165
current_reducer = next_reducer
166166
dispatch({ 'type': ACTION_TYPES['INIT'] })
167167

168-
"""
169-
TODO: Figure out how to add the observables
170-
"""
168+
# TODO: Figure out how to add the observables
171169

172170
# When a store is created, an "INIT" action is dispatched so that every
173171
# reducer returns their initial state. This effectively populates

test/helpers/reducers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
def id(state = []):
44
id = 0
55
for item in state:
6-
id = item.get('id')
6+
id = item.get('id') if item.get('id') > id else id
77
return id + 1
88

99
def todos(state=None, action={}):

0 commit comments

Comments
 (0)