Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Redux.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default class Redux {
setState(nextState) {
this.state = nextState;
this.listeners.forEach(listener => listener());
return nextState;
}

subscribe(listener) {
Expand Down
6 changes: 2 additions & 4 deletions src/createDispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import compose from './utils/composeMiddleware';

export default function createDispatcher(store, middlewares = []) {
return function dispatcher(initialState, setState) {
let state = store(initialState, {});
setState(state);
let state = setState(store(initialState, {}));

function dispatch(action) {
state = store(state, action);
setState(state);
state = setState(store(state, action));
return action;
}

Expand Down
8 changes: 6 additions & 2 deletions test/createDispatcher.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ const { ADD_TODO } = constants;
describe('createDispatcher', () => {

it('should handle sync and async dispatches', done => {
const spy = expect.createSpy(() => {});
const spy = expect.createSpy(
nextState => nextState
).andCallThrough();

const dispatcher = createDispatcher(
composeStores({ todoStore }),
// we need this middleware to handle async actions
getState => [thunkMiddleware(getState)]);
getState => [thunkMiddleware(getState)]
);

expect(dispatcher).toBeA('function');

Expand Down