Skip to content

Commit 628928e

Browse files
Parakletatimdorr
authored andcommitted
Make bindActionCreators transparently pass this. (reduxjs#2641)
1 parent b30e6ae commit 628928e

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/bindActionCreators.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function bindActionCreator(actionCreator, dispatch) {
2-
return (...args) => dispatch(actionCreator(...args))
2+
return function() { return dispatch(actionCreator.apply(this, arguments)) }
33
}
44

55
/**

test/bindActionCreators.spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ describe('bindActionCreators', () => {
3333
])
3434
})
3535

36+
it('wraps action creators transparently', () => {
37+
const uniqueThis = {}
38+
const argArray = [1, 2, 3]
39+
function actionCreator() {
40+
return { type: 'UNKNOWN_ACTION', this: this, args: [...arguments] }
41+
}
42+
const boundActionCreator = bindActionCreators(actionCreator, store.dispatch)
43+
44+
const boundAction = boundActionCreator.apply(uniqueThis,argArray)
45+
const action = actionCreator.apply(uniqueThis,argArray)
46+
expect(boundAction).toEqual(action)
47+
expect(boundAction.this).toBe(uniqueThis)
48+
expect(action.this).toBe(uniqueThis)
49+
})
50+
3651
it('skips non-function values in the passed object', () => {
3752
const boundActionCreators = bindActionCreators({
3853
...actionCreators,

0 commit comments

Comments
 (0)