Skip to content

Commit

Permalink
remove initial assignment of dispatch in applyMiddleware to make it…
Browse files Browse the repository at this point in the history
… more expressive

* separate local variables in applyMiddleware to make it more expressive

In the original version, the `dispatch` local variable in applyMiddleware stands for
different things before and after the `compose` call.
It'd be more expressive to separate "the original one on store" and "the
one with middlewares applied"

* refactor to make `applyMiddleware` clearer

pass `store.dispatch` to `compose`, not through another local variable
  • Loading branch information
mz026 authored and gaearon committed Apr 9, 2016
1 parent 7784b74 commit 9496fd7
Showing 1 changed file with 1 addition and 1 deletion.
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 = store.dispatch
var dispatch
var chain = []

var middlewareAPI = {
Expand Down

2 comments on commit 9496fd7

@acgourley
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaearon Just wanted to let you know that this change hit npm and broke our build (which stupidly was referencing the version "^3.3.1") with an error about _dispatch not being a function. I only say this in case it's helpful feedback, as we resolved it on our end by ceasing use of the carrot in the version.

@gaearon
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, thanks. Fixed this in 3.5.1.

Please sign in to comment.