8000 Make setState return the state that was set by gaearon · Pull Request #77 · reduxjs/redux · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
< 8000 diff-file-filter>

Make setState return the state that was set #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2015
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
0