Skip to content

Commit

Permalink
passing the action down the middleware chain, fixing #3
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkis committed Mar 8, 2016
1 parent c2168d2 commit 1db8084
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ export default (...sagas) => {
});

return next => action => {
next(action);
const result = next(action);
subject.next({action, state: store.getState()});
return result;
};
};
};
14 changes: 14 additions & 0 deletions test/sagaMiddleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,18 @@ describe('SagaMiddleware test', () => {
assert.equal(ex.message, 'Invariant violation: It is not allowed to provide identity (empty) saga');
}
});

it('should pass the action down the middleware chain', () => {
const saga = iterable => iterable
.filter(({ action }) => action.type === 'FOO')
.map(() => ({type: 'BAR'}));

const identity = input => input;
const store = { getState: identity, dispatch: identity };
const action = { type: 'FOO' };

const result = sagaMiddleware(saga)(store)(identity)(action)

assert.equal(result, action);
});
});

0 comments on commit 1db8084

Please sign in to comment.