Permalink
Browse files

Make bindActionCreators transparently pass `this`. (#2641)

  • Loading branch information...
Parakleta authored and timdorr committed Oct 6, 2017
1 parent b30e6ae commit 628928e3108df9725f07689e3785b5a2a226baa8
Showing with 16 additions and 1 deletion.
  1. +1 −1 src/bindActionCreators.js
  2. +15 −0 test/bindActionCreators.spec.js
@@ -1,5 +1,5 @@
function bindActionCreator(actionCreator, dispatch) {
return (...args) => dispatch(actionCreator(...args))
return function() { return dispatch(actionCreator.apply(this, arguments)) }
}
/**
@@ -33,6 +33,21 @@ describe('bindActionCreators', () => {
])
})
it('wraps action creators transparently', () => {
const uniqueThis = {}
const argArray = [1, 2, 3]
function actionCreator() {
return { type: 'UNKNOWN_ACTION', this: this, args: [...arguments] }
}
const boundActionCreator = bindActionCreators(actionCreator, store.dispatch)
const boundAction = boundActionCreator.apply(uniqueThis,argArray)
const action = actionCreator.apply(uniqueThis,argArray)
expect(boundAction).toEqual(action)
expect(boundAction.this).toBe(uniqueThis)
expect(action.this).toBe(uniqueThis)
})
it('skips non-function values in the passed object', () => {
const boundActionCreators = bindActionCreators({
...actionCreators,

0 comments on commit 628928e

Please sign in to comment.