Skip to content

Commit

Permalink
Add subscribe to Middleware API
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnyreeves committed Oct 21, 2015
1 parent 0d30e9b commit 8c9dfc0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/utils/applyMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export default function applyMiddleware(...middlewares) {

var middlewareAPI = {
getState: store.getState,
dispatch: (action) => dispatch(action)
dispatch: (action) => dispatch(action),
subscribe: store.subscribe
};
chain = middlewares.map(middleware => middleware(middlewareAPI));
dispatch = compose(...chain)(store.dispatch);
Expand Down
10 changes: 8 additions & 2 deletions test/utils/applyMiddleware.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ describe('applyMiddleware', () => {

expect(spy.calls.length).toEqual(1);

expect(Object.keys(spy.calls[0].arguments[0])).toEqual([
const middlewareAPI = spy.calls[0].arguments[0];

expect(Object.keys(middlewareAPI)).toEqual([
'getState',
'dispatch'
'dispatch',
'subscribe'
]);

expect(middlewareAPI.getState).toEqual(store.getState);
expect(middlewareAPI.subscribe).toEqual(store.subscribe);

expect(store.getState()).toEqual([ { id: 1, text: 'Use Redux' }, { id: 2, text: 'Flux FTW!' } ]);
});

Expand Down

0 comments on commit 8c9dfc0

Please sign in to comment.