Skip to content

Commit 87ff772

Browse files
authored
remove lodash dependencies (#307)
1 parent 0c8fa43 commit 87ff772

26 files changed

+62
-58
lines changed

.babelrc

-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
"transform-object-rest-spread"
77
],
88
"env": {
9-
"es": {
10-
"plugins": [
11-
"./build/use-lodash-es"
12-
]
13-
},
149
"commonjs": {
1510
"presets": [
1611
"env"

build/use-lodash-es.js

-12
This file was deleted.

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,12 @@
6464
"xo": "^0.20.3"
6565
},
6666
"dependencies": {
67+
"camelcase": "^5.0.0",
6768
"invariant": "^2.2.1",
68-
"lodash": "^4.13.1",
69-
"lodash-es": "^4.17.4",
69+
"is-function": "^1.0.1",
70+
"is-plain-object": "^2.0.4",
71+
"is-symbol": "^1.0.1",
72+
"lodash.curry": "^4.1.1",
7073
"reduce-reducers": "^0.1.0"
7174
},
7275
"xo": {

src/combineActions.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import isString from 'lodash/isString';
2-
import isFunction from 'lodash/isFunction';
3-
import isEmpty from 'lodash/isEmpty';
4-
import toString from 'lodash/toString';
5-
import isSymbol from 'lodash/isSymbol';
61
import invariant from 'invariant';
2+
import isFunction from 'is-function';
3+
import isSymbol from 'is-symbol';
4+
import isEmpty from './utils/isEmpty';
5+
import toString from './utils/toString';
6+
import isString from './utils/isString';
77
import { ACTION_TYPE_DELIMITER } from './constants';
88

99
function isValidActionType(type) {

src/createAction.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import identity from 'lodash/identity';
2-
import isFunction from 'lodash/isFunction';
3-
import isNull from 'lodash/isNull';
1+
import isFunction from 'is-function';
42
import invariant from 'invariant';
3+
import identity from './utils/identity';
4+
import isNull from './utils/isNull';
55

66
export default function createAction(
77
type,

src/createActions.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import identity from 'lodash/identity';
2-
import isPlainObject from 'lodash/isPlainObject';
3-
import isArray from 'lodash/isArray';
4-
import last from 'lodash/last';
5-
import isString from 'lodash/isString';
6-
import isFunction from 'lodash/isFunction';
7-
import isNil from 'lodash/isNil';
1+
import isPlainObject from 'is-plain-object';
2+
import isFunction from 'is-function';
83
import invariant from 'invariant';
4+
import identity from './utils/identity';
5+
import isArray from './utils/isArray';
6+
import isString from './utils/isString';
7+
import isNil from './utils/isNil';
8+
import getLastElement from './utils/getLastElement';
99
import camelCase from './utils/camelCase';
1010
import arrayToObject from './utils/arrayToObject';
1111
import flattenActionMap from './utils/flattenActionMap';
@@ -14,7 +14,7 @@ import createAction from './createAction';
1414
import { DEFAULT_NAMESPACE } from './constants';
1515

1616
export default function createActions(actionMap, ...identityActions) {
17-
const options = isPlainObject(last(identityActions))
17+
const options = isPlainObject(getLastElement(identityActions))
1818
? identityActions.pop()
1919
: {};
2020
invariant(

src/createCurriedAction.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import curry from 'lodash/curry';
1+
import curry from 'lodash.curry';
22
import createAction from './createAction';
33

44
export default (type, payloadCreator) =>

src/handleAction.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import isFunction from 'lodash/isFunction';
2-
import isPlainObject from 'lodash/isPlainObject';
3-
import identity from 'lodash/identity';
4-
import isNil from 'lodash/isNil';
5-
import isUndefined from 'lodash/isUndefined';
6-
import includes from 'lodash/includes';
71
import invariant from 'invariant';
2+
import isFunction from 'is-function';
3+
import isPlainObject from 'is-plain-object';
4+
import identity from './utils/identity';
5+
import isNil from './utils/isNil';
6+
import isUndefined from './utils/isUndefined';
7+
import toString from './utils/toString';
88
import { ACTION_TYPE_DELIMITER } from './constants';
99

1010
export default function handleAction(type, reducer = identity, defaultState) {
11-
const types = type.toString().split(ACTION_TYPE_DELIMITER);
11+
const types = toString(type).split(ACTION_TYPE_DELIMITER);
1212
invariant(
1313
!isUndefined(defaultState),
1414
`defaultState for reducer handling ${types.join(', ')} should be defined`
@@ -26,7 +26,7 @@ export default function handleAction(type, reducer = identity, defaultState) {
2626

2727
return (state = defaultState, action) => {
2828
const { type: actionType } = action;
29-
if (!actionType || !includes(types, actionType.toString())) {
29+
if (!actionType || !types.includes(toString(actionType))) {
3030
return state;
3131
}
3232

src/handleActions.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import isPlainObject from 'lodash/isPlainObject';
2-
import isMap from 'lodash/isMap';
31
import reduceReducers from 'reduce-reducers';
2+
import isPlainObject from 'is-plain-object';
43
import invariant from 'invariant';
5-
import handleAction from './handleAction';
4+
import isMap from './utils/isMap';
65
import ownKeys from './utils/ownKeys';
76
import flattenReducerMap from './utils/flattenReducerMap';
7+
import handleAction from './handleAction';
88

99
function get(key, x) {
1010
return isMap(x) ? x.get(key) : x[key];

src/utils/camelCase.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import camelCase from 'lodash/camelCase';
1+
import camelCase from 'camelcase';
22

33
const namespacer = '/';
44

src/utils/flattenActionMap.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import isPlainObject from 'lodash/isPlainObject';
1+
import isPlainObject from 'is-plain-object';
22
import flattenWhenNode from './flattenWhenNode';
33

44
export default flattenWhenNode(isPlainObject);

src/utils/flattenReducerMap.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import isPlainObject from 'lodash/isPlainObject';
2-
import isMap from 'lodash/isMap';
1+
import isPlainObject from 'is-plain-object';
2+
import isMap from './isMap';
33
import hasGeneratorInterface from './hasGeneratorInterface';
44
import flattenWhenNode from './flattenWhenNode';
55

src/utils/flattenWhenNode.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import isMap from 'lodash/isMap';
21
import { DEFAULT_NAMESPACE, ACTION_TYPE_DELIMITER } from '../constants';
2+
import isMap from './isMap';
33
import ownKeys from './ownKeys';
44

55
function get(key, x) {

src/utils/getLastElement.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default array => array[array.length - 1];

src/utils/identity.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default value => value;

src/utils/isArray.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default value => Array.isArray(value);

src/utils/isEmpty.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default value => value.length === 0;

src/utils/isMap.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default value => value instanceof Map;

src/utils/isNil.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default value => value === null || value === undefined;

src/utils/isNull.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default value => value === null;

src/utils/isString.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default value => typeof value === 'string';

src/utils/isUndefined.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default value => value === undefined;

src/utils/ownKeys.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import isMap from 'lodash/isMap';
1+
import isMap from './isMap';
22

33
export default function ownKeys(object) {
44
if (isMap(object)) {

src/utils/toString.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default value => value.toString();

src/utils/unflattenActionCreators.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import isEmpty from 'lodash/isEmpty';
21
import { DEFAULT_NAMESPACE } from '../constants';
2+
import isEmpty from './isEmpty';
33
import camelCase from './camelCase';
44

55
export default function unflattenActionCreators(

yarn.lock

+12-4
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,10 @@ camelcase@^4.0.0, camelcase@^4.1.0:
12921292
version "4.1.0"
12931293
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-4.1.0.tgz#d545635be1e33c542649c69173e5de6acfae34dd"
12941294

1295+
camelcase@^5.0.0:
1296+
version "5.0.0"
1297+
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.0.0.tgz#03295527d58bd3cd4aa75363f35b2e8d97be2f42"
1298+
12951299
caniuse-lite@^1.0.30000792:
12961300
version "1.0.30000833"
12971301
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000833.tgz#98e84fcdb4399c6fa0b0fd41490d3217ac7802b4"
@@ -3362,6 +3366,10 @@ is-fullwidth-code-point@^2.0.0:
33623366
version "2.0.0"
33633367
resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f"
33643368

3369+
is-function@^1.0.1:
3370+
version "1.0.1"
3371+
resolved "https://registry.yarnpkg.com/is-function/-/is-function-1.0.1.tgz#12cfb98b65b57dd3d193a3121f5f6e2f437602b5"
3372+
33653373
is-generator-fn@^1.0.0:
33663374
version "1.0.0"
33673375
resolved "https://registry.yarnpkg.com/is-generator-fn/-/is-generator-fn-1.0.0.tgz#969d49e1bb3329f6bb7f09089be26578b2ddd46a"
@@ -4254,10 +4262,6 @@ locate-path@^2.0.0:
42544262
p-locate "^2.0.0"
42554263
path-exists "^3.0.0"
42564264

4257-
lodash-es@^4.17.4:
4258-
version "4.17.10"
4259-
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.10.tgz#62cd7104cdf5dd87f235a837f0ede0e8e5117e05"
4260-
42614265
lodash._baseassign@^3.0.0:
42624266
version "3.2.0"
42634267
resolved "https://registry.yarnpkg.com/lodash._baseassign/-/lodash._baseassign-3.2.0.tgz#8c38a099500f215ad09e59f1722fd0c52bfe0a4e"
@@ -4301,6 +4305,10 @@ lodash.camelcase@^4.1.1:
43014305
version "4.3.0"
43024306
resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6"
43034307

4308+
lodash.curry@^4.1.1:
4309+
version "4.1.1"
4310+
resolved "https://registry.yarnpkg.com/lodash.curry/-/lodash.curry-4.1.1.tgz#248e36072ede906501d75966200a86dab8b23170"
4311+
43044312
lodash.get@^4.4.2:
43054313
version "4.4.2"
43064314
resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"

0 commit comments

Comments
 (0)