Skip to content

Commit 314ccb8

Browse files
committed
Import bindActionCreators into the project
1 parent 50b60e4 commit 314ccb8

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/connect/mapDispatchToProps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { bindActionCreators } from 'redux'
1+
import bindActionCreators from '../utils/bindActionCreators'
22
import { wrapMapToPropsConstant, wrapMapToPropsFunc } from './wrapMapToProps'
33

44
export function whenMapDispatchToPropsIsFunction(mapDispatchToProps) {

src/utils/bindActionCreators.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default function bindActionCreators(actionCreators, dispatch) {
2+
const boundActionCreators = {}
3+
for (const key in actionCreators) {
4+
const actionCreator = actionCreators[key]
5+
if (typeof actionCreator === 'function') {
6+
boundActionCreators[key] = (...args) => dispatch(actionCreator(...args))
7+
}
8+
}
9+
return boundActionCreators
10+
}

src/utils/wrapActionCreators.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { bindActionCreators } from 'redux'
1+
import bindActionCreators from './bindActionCreators'
22

33
export default function wrapActionCreators(actionCreators) {
44
return (dispatch) => bindActionCreators(actionCreators, dispatch)

0 commit comments

Comments
 (0)