Skip to content

Commit 8707973

Browse files
committed
fix(createMiddleware): fix potential performance problem in createMiddleware
1 parent b575016 commit 8707973

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/createMiddleware.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
import mapValues from 'lodash.mapvalues'
2-
31
export default function createMiddleware(actionHandlers) {
4-
const result = store => {
5-
const handlersForStore = mapValues(actionHandlers, handler => handler(store))
6-
return next => {
7-
const handlersForNext = mapValues(handlersForStore, handler => handler(next))
8-
return action => {
9-
const handler = handlersForNext[action.type]
10-
return handler ? handler(action) : next(action)
11-
}
12-
}
2+
const result = store => next => action => {
3+
const handler = actionHandlers[action.type]
4+
if (!handler) return next(action)
5+
return handler(store)(next)(action)
136
}
147
result.actionHandlers = actionHandlers
158
return result
169
}
10+

0 commit comments

Comments
 (0)