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
2 changes: 1 addition & 1 deletion src/applyMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import compose from './compose'
export default function applyMiddleware(...middlewares) {
return (createStore) => (reducer, initialState, enhancer) => {
var store = createStore(reducer, initialState, enhancer)
var dispatch
var dispatch = store.dispatch
var chain = []

var middlewareAPI = {
Expand Down
18 changes: 18 additions & 0 deletions test/applyMiddleware.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,22 @@ describe('applyMiddleware', () => {
done()
})
})

it('keeps unwrapped dispatch available while middleware is initializing', () => {
// This is documenting the existing behavior in Redux 3.x.
// We plan to forbid this in Redux 4.x.

function earlyDispatch({ dispatch }) {
dispatch(addTodo('Hello'))
return () => action => action
}

const store = createStore(reducers.todos, applyMiddleware(earlyDispatch))
expect(store.getState()).toEqual([
{
id: 1,
text: 'Hello'
}
])
})
})