diff --git a/src/applyMiddleware.js b/src/applyMiddleware.js index 4a2a4e97b7..c885a2dfa9 100644 --- a/src/applyMiddleware.js +++ b/src/applyMiddleware.js @@ -19,16 +19,17 @@ import compose from './compose' export default function applyMiddleware(...middlewares) { return createStore => (...args) => { const store = createStore(...args) - let dispatch = () => { - throw new Error( - `Dispatching while constructing your middleware is not allowed. ` + - `Other middleware would not be applied to this dispatch.` + let dispatch = (...args) => { + console.warn( + `You are attempting to dispatch from within a middleware during "applyMiddleware". ` + + `Other middleware will not be applied to this dispatch.` ) + store.dispatch(...args) } const middlewareAPI = { getState: store.getState, - dispatch: (...args) => dispatch(...args) + dispatch } const chain = middlewares.map(middleware => middleware(middlewareAPI)) dispatch = compose(...chain)(store.dispatch) diff --git a/test/applyMiddleware.spec.js b/test/applyMiddleware.spec.js index 2efdc9f83f..42501bd54b 100644 --- a/test/applyMiddleware.spec.js +++ b/test/applyMiddleware.spec.js @@ -4,17 +4,6 @@ import { addTodo, addTodoAsync, addTodoIfEmpty } from './helpers/actionCreators' import { thunk } from './helpers/middleware' describe('applyMiddleware', () => { - it('warns when dispatching during middleware setup', () => { - function dispatchingMiddleware(store) { - store.dispatch(addTodo('Dont dispatch in middleware setup')) - return next => action => next(action) - } - - expect(() => - applyMiddleware(dispatchingMiddleware)(createStore)(reducers.todos) - ).toThrow() - }) - it('wraps dispatch method with middleware once', () => { function test(spyOnMethods) { return methods => {