Skip to content

Commit

Permalink
update of wrapDispatch to be backward compatible to v2 api (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
kovcic authored and yesmeck committed Oct 20, 2016
1 parent 4e87e0e commit baeb2e4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/wrapDispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export default function wrapDispatch(dispatch, reducerKey) {
const wrappedDispatch = (action) => {
let wrappedAction;
if (typeof action === 'function') {
wrappedAction = (_, getState) => action(wrappedDispatch, getState);
wrappedAction = (globalDispatch, getState) =>
action(wrappedDispatch, getState, globalDispatch, reducerKey);
} else if (typeof action === 'object') {
wrappedAction = wrapAction(action, reducerKey);
}
Expand Down
4 changes: 3 additions & 1 deletion test/wrapDispatch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('wrapDispatch', () => {

it('dispatch thunk action', () => {
const getState = () => {};
const dispatch = createSpy().andCall(action => action(null, getState));
const dispatch = createSpy().andCall(action => action(dispatch, getState));
const action = createSpy();
const wrappedDispatch = wrapDispatch(dispatch, 'additional');
wrappedDispatch(action);
Expand All @@ -27,6 +27,8 @@ describe('wrapDispatch', () => {
expect(action.calls[0].arguments).toEqual([
wrappedDispatch,
getState,
dispatch,
'additional'
]);
});
});

0 comments on commit baeb2e4

Please sign in to comment.