Skip to content

Commit

Permalink
Make bindActionCreators transparently pass this. (reduxjs#2641)
Browse files Browse the repository at this point in the history
  • Loading branch information
Parakleta authored and seantcoyote committed Jan 14, 2018
1 parent ecda836 commit ea07b6d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/bindActionCreators.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function bindActionCreator(actionCreator, dispatch) {
return (...args) => dispatch(actionCreator(...args))
return function() { return dispatch(actionCreator.apply(this, arguments)) }
}

/**
Expand Down
15 changes: 15 additions & 0 deletions test/bindActionCreators.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ea07b6d

Please sign in to comment.