Skip to content

Commit c672862

Browse files
committed
Upgrade the warning to an error.
1 parent 50dd790 commit c672862

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/applyMiddleware.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import compose from './compose'
2-
import warning from './utils/warning'
32

43
/**
54
* Creates a store enhancer that applies middleware to the dispatch method
@@ -20,12 +19,11 @@ import warning from './utils/warning'
2019
export default function applyMiddleware(...middlewares) {
2120
return (createStore) => (reducer, initialState, enhancer) => {
2221
var store = createStore(reducer, initialState, enhancer)
23-
var dispatch = (...args) => {
24-
warning(
25-
`Calling dispatch while constructing your middleware is discouraged. ` +
26-
`Other middleware will not be applied to this dispatch.`
22+
var dispatch = () => {
23+
throw new Error(
24+
`Dispatching while constructing your middleware is not allowed. ` +
25+
`Other middleware would not be applied to this dispatch.`
2726
)
28-
store.dispatch(...args)
2927
}
3028
var chain = []
3129

test/applyMiddleware.spec.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@ describe('applyMiddleware', () => {
1111
return next => action => next(action)
1212
}
1313

14-
const spy = expect.spyOn(console, 'error')
15-
16-
applyMiddleware(dispatchingMiddleware)(createStore)(reducers.todos)
17-
18-
expect(spy.calls.length).toEqual(1)
19-
spy.restore()
14+
expect(() =>
15+
applyMiddleware(dispatchingMiddleware)(createStore)(reducers.todos)
16+
).toThrow()
2017
})
2118

2219
it('wraps dispatch method with middleware once', () => {

0 commit comments

Comments
 (0)