Skip to content

Commit 77597e1

Browse files
committed
Minimize lodash dependencies
1 parent 56a51e3 commit 77597e1

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
},
3232
"dependencies": {
3333
"invariant": "^2.1.0",
34-
"lodash": "^3.10.1",
34+
"lodash.assign": "^3.2.0",
35+
"lodash.isarray": "^3.0.4",
36+
"lodash.isfunction": "^3.0.6",
37+
"lodash.isobject": "^3.0.2",
38+
"lodash.isplainobject": "^3.2.0",
3539
"redux": "^3.0.0"
3640
}
3741
}

src/components/connector.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import shallowEqual from '../utils/shallowEqual';
22
import wrapActionCreators from '../utils/wrapActionCreators';
33
import invariant from 'invariant';
4-
import _ from 'lodash';
4+
5+
import isPlainObject from 'lodash.isplainobject';
6+
import isFunction from 'lodash.isfunction';
7+
import isObject from 'lodash.isobject';
8+
import assign from 'lodash.assign';
59

610
const defaultMapStateToTarget = () => ({});
711
const defaultMapDispatchToTarget = dispatch => ({dispatch});
@@ -11,17 +15,17 @@ export default function Connector(store) {
1115

1216
const finalMapStateToTarget = mapStateToTarget || defaultMapStateToTarget;
1317

14-
const finalMapDispatchToTarget = _.isPlainObject(mapDispatchToTarget) ?
18+
const finalMapDispatchToTarget = isPlainObject(mapDispatchToTarget) ?
1519
wrapActionCreators(mapDispatchToTarget) :
1620
mapDispatchToTarget || defaultMapDispatchToTarget;
1721

1822
invariant(
19-
_.isFunction(finalMapStateToTarget),
23+
isFunction(finalMapStateToTarget),
2024
'mapStateToTarget must be a Function. Instead received $s.', finalMapStateToTarget
2125
);
2226

2327
invariant(
24-
_.isPlainObject(finalMapDispatchToTarget) || _.isFunction(finalMapDispatchToTarget),
28+
isPlainObject(finalMapDispatchToTarget) || isFunction(finalMapDispatchToTarget),
2529
'mapDispatchToTarget must be a plain Object or a Function. Instead received $s.', finalMapDispatchToTarget
2630
);
2731

@@ -32,7 +36,7 @@ export default function Connector(store) {
3236
return (target) => {
3337

3438
invariant(
35-
_.isFunction(target) || _.isObject(target),
39+
isFunction(target) || isObject(target),
3640
'The target parameter passed to connect must be a Function or a object.'
3741
);
3842

@@ -53,18 +57,18 @@ export default function Connector(store) {
5357
}
5458

5559
function updateTarget(target, StateSlice, dispatch) {
56-
if(_.isFunction(target)) {
60+
if(isFunction(target)) {
5761
target(StateSlice, dispatch);
5862
} else {
59-
_.assign(target, StateSlice, dispatch);
63+
assign(target, StateSlice, dispatch);
6064
}
6165
}
6266

6367
function getStateSlice(state, mapStateToScope) {
6468
const slice = mapStateToScope(state);
6569

6670
invariant(
67-
_.isPlainObject(slice),
71+
isPlainObject(slice),
6872
'`mapStateToScope` must return an object. Instead received %s.',
6973
slice
7074
);

src/components/ngRedux.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import Connector from './connector';
22
import invariant from 'invariant';
33
import {createStore, applyMiddleware, compose} from 'redux';
44
import digestMiddleware from './digestMiddleware';
5-
import _ from 'lodash';
5+
6+
import isArray from 'lodash.isarray';
7+
import isFunction from 'lodash.isfunction';
68

79
export default function ngReduxProvider() {
810
let _reducer = undefined;
@@ -11,13 +13,13 @@ export default function ngReduxProvider() {
1113

1214
this.createStoreWith = (reducer, middlewares, storeEnhancers) => {
1315
invariant(
14-
_.isFunction(reducer),
16+
isFunction(reducer),
1517
'The reducer parameter passed to createStoreWith must be a Function. Instead received %s.',
1618
typeof reducer
1719
);
1820

1921
invariant(
20-
!storeEnhancers || _.isArray(storeEnhancers),
22+
!storeEnhancers || isArray(storeEnhancers),
2123
'The storeEnhancers parameter passed to createStoreWith must be an Array. Instead received %s.',
2224
typeof storeEnhancers
2325
);

test/components/connector.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import expect from 'expect';
22
let sinon = require('sinon');
33
import { createStore } from 'redux';
44
import Connector from '../../src/components/connector';
5-
import _ from 'lodash';
5+
import isFunction from 'lodash.isfunction';
66

77
describe('Connector', () => {
88
let store;
@@ -70,8 +70,8 @@ describe('Connector', () => {
7070

7171
it('Should extend target (object) with actionCreators', () => {
7272
connect(() => ({}), { ac1: () => { }, ac2: () => { } })(targetObj);
73-
expect(_.isFunction(targetObj.ac1)).toBe(true);
74-
expect(_.isFunction(targetObj.ac2)).toBe(true);
73+
expect(isFunction(targetObj.ac1)).toBe(true);
74+
expect(isFunction(targetObj.ac2)).toBe(true);
7575
});
7676

7777
it('Should return an unsubscribing function', () => {

0 commit comments

Comments
 (0)