Skip to content

Commit edef178

Browse files
author
Joel Mertanen
committed
fix(lib): allow es6 modules to mapDispatchToTarget
1 parent b7885cd commit edef178

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/components/connector.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default function Connector(store) {
1515

1616
let finalMapStateToTarget = mapStateToTarget || defaultMapStateToTarget;
1717

18-
const finalMapDispatchToTarget = isPlainObject(mapDispatchToTarget) ?
18+
const finalMapDispatchToTarget = isObject(mapDispatchToTarget) && !isFunction(mapDispatchToTarget) ?
1919
wrapActionCreators(mapDispatchToTarget) :
2020
mapDispatchToTarget || defaultMapDispatchToTarget;
2121

@@ -25,7 +25,7 @@ export default function Connector(store) {
2525
);
2626

2727
invariant(
28-
isPlainObject(finalMapDispatchToTarget) || isFunction(finalMapDispatchToTarget),
28+
isObject(finalMapDispatchToTarget) || isFunction(finalMapDispatchToTarget),
2929
'mapDispatchToTarget must be a plain Object or a Function. Instead received %s.', finalMapDispatchToTarget
3030
);
3131

test/components/connector.spec.js

+10
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ describe('Connector', () => {
114114
expect(receivedDispatch).toBe(store.dispatch);
115115
});
116116

117+
it('Should allow ES6 modules', () => {
118+
// The tests are run in Node, so we are unable to use actual ES6 modules. We get quite
119+
// close by emulating it
120+
class FakeModule {
121+
prop() {}
122+
};
123+
const fakeModule = new FakeModule();
124+
expect(() => connect(() => ({}), fakeModule)(targetObj)).toNotThrow();
125+
});
126+
117127
it('Should provide state slice, bound actions and previous state slice to target (function)', () => {
118128
const targetFunc = sinon.spy();
119129

0 commit comments

Comments
 (0)