Skip to content

Commit

Permalink
Merge pull request #217 from joelmertanen/allow-es6-objects
Browse files Browse the repository at this point in the history
Allow mapDispatchToTarget to be an ES6 module
  • Loading branch information
AntJanus authored May 13, 2019
2 parents 0d5d2a5 + edef178 commit d11849e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/components/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function Connector(store) {

let finalMapStateToTarget = mapStateToTarget || defaultMapStateToTarget;

const finalMapDispatchToTarget = isPlainObject(mapDispatchToTarget) ?
const finalMapDispatchToTarget = isObject(mapDispatchToTarget) && !isFunction(mapDispatchToTarget) ?
wrapActionCreators(mapDispatchToTarget) :
mapDispatchToTarget || defaultMapDispatchToTarget;

Expand All @@ -25,7 +25,7 @@ export default function Connector(store) {
);

invariant(
isPlainObject(finalMapDispatchToTarget) || isFunction(finalMapDispatchToTarget),
isObject(finalMapDispatchToTarget) || isFunction(finalMapDispatchToTarget),
'mapDispatchToTarget must be a plain Object or a Function. Instead received %s.', finalMapDispatchToTarget
);

Expand Down
10 changes: 10 additions & 0 deletions test/components/connector.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ describe('Connector', () => {
expect(receivedDispatch).toBe(store.dispatch);
});

it('Should allow ES6 modules', () => {
// The tests are run in Node, so we are unable to use actual ES6 modules. We get quite
// close by emulating it
class FakeModule {
prop() {}
};
const fakeModule = new FakeModule();
expect(() => connect(() => ({}), fakeModule)(targetObj)).toNotThrow();
});

it('Should provide state slice, bound actions and previous state slice to target (function)', () => {
const targetFunc = sinon.spy();

Expand Down

0 comments on commit d11849e

Please sign in to comment.