diff --git a/.babelrc b/.babelrc index df32b024..bd59a37d 100644 --- a/.babelrc +++ b/.babelrc @@ -6,11 +6,6 @@ "transform-object-rest-spread" ], "env": { - "es": { - "plugins": [ - "./build/use-lodash-es" - ] - }, "commonjs": { "presets": [ "env" diff --git a/build/use-lodash-es.js b/build/use-lodash-es.js deleted file mode 100644 index 1b9b275c..00000000 --- a/build/use-lodash-es.js +++ /dev/null @@ -1,12 +0,0 @@ -/* eslint-disable unicorn/filename-case */ - -module.exports = () => { - return { - visitor: { - ImportDeclaration(path) { - const source = path.node.source; - source.value = source.value.replace(/^lodash($|\/)/, 'lodash-es$1'); - } - } - }; -}; diff --git a/package.json b/package.json index c2291270..59e078e5 100644 --- a/package.json +++ b/package.json @@ -64,9 +64,12 @@ "xo": "^0.20.3" }, "dependencies": { + "camelcase": "^5.0.0", "invariant": "^2.2.1", - "lodash": "^4.13.1", - "lodash-es": "^4.17.4", + "is-function": "^1.0.1", + "is-plain-object": "^2.0.4", + "is-symbol": "^1.0.1", + "lodash.curry": "^4.1.1", "reduce-reducers": "^0.1.0" }, "xo": { diff --git a/src/combineActions.js b/src/combineActions.js index 6c437498..10eeb9e6 100644 --- a/src/combineActions.js +++ b/src/combineActions.js @@ -1,9 +1,9 @@ -import isString from 'lodash/isString'; -import isFunction from 'lodash/isFunction'; -import isEmpty from 'lodash/isEmpty'; -import toString from 'lodash/toString'; -import isSymbol from 'lodash/isSymbol'; import invariant from 'invariant'; +import isFunction from 'is-function'; +import isSymbol from 'is-symbol'; +import isEmpty from './utils/isEmpty'; +import toString from './utils/toString'; +import isString from './utils/isString'; import { ACTION_TYPE_DELIMITER } from './constants'; function isValidActionType(type) { diff --git a/src/createAction.js b/src/createAction.js index f07ae9fe..5e1e9021 100644 --- a/src/createAction.js +++ b/src/createAction.js @@ -1,7 +1,7 @@ -import identity from 'lodash/identity'; -import isFunction from 'lodash/isFunction'; -import isNull from 'lodash/isNull'; +import isFunction from 'is-function'; import invariant from 'invariant'; +import identity from './utils/identity'; +import isNull from './utils/isNull'; export default function createAction( type, diff --git a/src/createActions.js b/src/createActions.js index 16198002..582ea296 100644 --- a/src/createActions.js +++ b/src/createActions.js @@ -1,11 +1,11 @@ -import identity from 'lodash/identity'; -import isPlainObject from 'lodash/isPlainObject'; -import isArray from 'lodash/isArray'; -import last from 'lodash/last'; -import isString from 'lodash/isString'; -import isFunction from 'lodash/isFunction'; -import isNil from 'lodash/isNil'; +import isPlainObject from 'is-plain-object'; +import isFunction from 'is-function'; import invariant from 'invariant'; +import identity from './utils/identity'; +import isArray from './utils/isArray'; +import isString from './utils/isString'; +import isNil from './utils/isNil'; +import getLastElement from './utils/getLastElement'; import camelCase from './utils/camelCase'; import arrayToObject from './utils/arrayToObject'; import flattenActionMap from './utils/flattenActionMap'; @@ -14,7 +14,7 @@ import createAction from './createAction'; import { DEFAULT_NAMESPACE } from './constants'; export default function createActions(actionMap, ...identityActions) { - const options = isPlainObject(last(identityActions)) + const options = isPlainObject(getLastElement(identityActions)) ? identityActions.pop() : {}; invariant( diff --git a/src/createCurriedAction.js b/src/createCurriedAction.js index 42f76509..7b7aabc1 100644 --- a/src/createCurriedAction.js +++ b/src/createCurriedAction.js @@ -1,4 +1,4 @@ -import curry from 'lodash/curry'; +import curry from 'lodash.curry'; import createAction from './createAction'; export default (type, payloadCreator) => diff --git a/src/handleAction.js b/src/handleAction.js index 7eacc0c9..cfefa024 100644 --- a/src/handleAction.js +++ b/src/handleAction.js @@ -1,14 +1,14 @@ -import isFunction from 'lodash/isFunction'; -import isPlainObject from 'lodash/isPlainObject'; -import identity from 'lodash/identity'; -import isNil from 'lodash/isNil'; -import isUndefined from 'lodash/isUndefined'; -import includes from 'lodash/includes'; import invariant from 'invariant'; +import isFunction from 'is-function'; +import isPlainObject from 'is-plain-object'; +import identity from './utils/identity'; +import isNil from './utils/isNil'; +import isUndefined from './utils/isUndefined'; +import toString from './utils/toString'; import { ACTION_TYPE_DELIMITER } from './constants'; export default function handleAction(type, reducer = identity, defaultState) { - const types = type.toString().split(ACTION_TYPE_DELIMITER); + const types = toString(type).split(ACTION_TYPE_DELIMITER); invariant( !isUndefined(defaultState), `defaultState for reducer handling ${types.join(', ')} should be defined` @@ -26,7 +26,7 @@ export default function handleAction(type, reducer = identity, defaultState) { return (state = defaultState, action) => { const { type: actionType } = action; - if (!actionType || !includes(types, actionType.toString())) { + if (!actionType || !types.includes(toString(actionType))) { return state; } diff --git a/src/handleActions.js b/src/handleActions.js index d8b8f7e8..5e67e5ab 100644 --- a/src/handleActions.js +++ b/src/handleActions.js @@ -1,10 +1,10 @@ -import isPlainObject from 'lodash/isPlainObject'; -import isMap from 'lodash/isMap'; import reduceReducers from 'reduce-reducers'; +import isPlainObject from 'is-plain-object'; import invariant from 'invariant'; -import handleAction from './handleAction'; +import isMap from './utils/isMap'; import ownKeys from './utils/ownKeys'; import flattenReducerMap from './utils/flattenReducerMap'; +import handleAction from './handleAction'; function get(key, x) { return isMap(x) ? x.get(key) : x[key]; diff --git a/src/utils/camelCase.js b/src/utils/camelCase.js index 687012dd..5a933e3c 100644 --- a/src/utils/camelCase.js +++ b/src/utils/camelCase.js @@ -1,4 +1,4 @@ -import camelCase from 'lodash/camelCase'; +import camelCase from 'camelcase'; const namespacer = '/'; diff --git a/src/utils/flattenActionMap.js b/src/utils/flattenActionMap.js index bc30496f..f5df4795 100644 --- a/src/utils/flattenActionMap.js +++ b/src/utils/flattenActionMap.js @@ -1,4 +1,4 @@ -import isPlainObject from 'lodash/isPlainObject'; +import isPlainObject from 'is-plain-object'; import flattenWhenNode from './flattenWhenNode'; export default flattenWhenNode(isPlainObject); diff --git a/src/utils/flattenReducerMap.js b/src/utils/flattenReducerMap.js index 3495ecbc..ebaca8b9 100644 --- a/src/utils/flattenReducerMap.js +++ b/src/utils/flattenReducerMap.js @@ -1,5 +1,5 @@ -import isPlainObject from 'lodash/isPlainObject'; -import isMap from 'lodash/isMap'; +import isPlainObject from 'is-plain-object'; +import isMap from './isMap'; import hasGeneratorInterface from './hasGeneratorInterface'; import flattenWhenNode from './flattenWhenNode'; diff --git a/src/utils/flattenWhenNode.js b/src/utils/flattenWhenNode.js index 95147cae..58dcbe89 100644 --- a/src/utils/flattenWhenNode.js +++ b/src/utils/flattenWhenNode.js @@ -1,5 +1,5 @@ -import isMap from 'lodash/isMap'; import { DEFAULT_NAMESPACE, ACTION_TYPE_DELIMITER } from '../constants'; +import isMap from './isMap'; import ownKeys from './ownKeys'; function get(key, x) { diff --git a/src/utils/getLastElement.js b/src/utils/getLastElement.js new file mode 100644 index 00000000..0f8f081c --- /dev/null +++ b/src/utils/getLastElement.js @@ -0,0 +1 @@ +export default array => array[array.length - 1]; diff --git a/src/utils/identity.js b/src/utils/identity.js new file mode 100644 index 00000000..0b177b07 --- /dev/null +++ b/src/utils/identity.js @@ -0,0 +1 @@ +export default value => value; diff --git a/src/utils/isArray.js b/src/utils/isArray.js new file mode 100644 index 00000000..b0f97bbe --- /dev/null +++ b/src/utils/isArray.js @@ -0,0 +1 @@ +export default value => Array.isArray(value); diff --git a/src/utils/isEmpty.js b/src/utils/isEmpty.js new file mode 100644 index 00000000..43d166be --- /dev/null +++ b/src/utils/isEmpty.js @@ -0,0 +1 @@ +export default value => value.length === 0; diff --git a/src/utils/isMap.js b/src/utils/isMap.js new file mode 100644 index 00000000..53cbe1cb --- /dev/null +++ b/src/utils/isMap.js @@ -0,0 +1 @@ +export default value => value instanceof Map; diff --git a/src/utils/isNil.js b/src/utils/isNil.js new file mode 100644 index 00000000..f3ce0430 --- /dev/null +++ b/src/utils/isNil.js @@ -0,0 +1 @@ +export default value => value === null || value === undefined; diff --git a/src/utils/isNull.js b/src/utils/isNull.js new file mode 100644 index 00000000..b7664b39 --- /dev/null +++ b/src/utils/isNull.js @@ -0,0 +1 @@ +export default value => value === null; diff --git a/src/utils/isString.js b/src/utils/isString.js new file mode 100644 index 00000000..29d056fe --- /dev/null +++ b/src/utils/isString.js @@ -0,0 +1 @@ +export default value => typeof value === 'string'; diff --git a/src/utils/isUndefined.js b/src/utils/isUndefined.js new file mode 100644 index 00000000..43c1eb5e --- /dev/null +++ b/src/utils/isUndefined.js @@ -0,0 +1 @@ +export default value => value === undefined; diff --git a/src/utils/ownKeys.js b/src/utils/ownKeys.js index 9e3a9da5..38be0662 100644 --- a/src/utils/ownKeys.js +++ b/src/utils/ownKeys.js @@ -1,4 +1,4 @@ -import isMap from 'lodash/isMap'; +import isMap from './isMap'; export default function ownKeys(object) { if (isMap(object)) { diff --git a/src/utils/toString.js b/src/utils/toString.js new file mode 100644 index 00000000..e33f21a6 --- /dev/null +++ b/src/utils/toString.js @@ -0,0 +1 @@ +export default value => value.toString(); diff --git a/src/utils/unflattenActionCreators.js b/src/utils/unflattenActionCreators.js index 5ad29ec0..bcd43ea1 100644 --- a/src/utils/unflattenActionCreators.js +++ b/src/utils/unflattenActionCreators.js @@ -1,5 +1,5 @@ -import isEmpty from 'lodash/isEmpty'; import { DEFAULT_NAMESPACE } from '../constants'; +import isEmpty from './isEmpty'; import camelCase from './camelCase'; export default function unflattenActionCreators( diff --git a/yarn.lock b/yarn.lock index 4b3638f3..4847d052 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1292,6 +1292,10 @@ camelcase@^4.0.0, camelcase@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-4.1.0.tgz#d545635be1e33c542649c69173e5de6acfae34dd" +camelcase@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.0.0.tgz#03295527d58bd3cd4aa75363f35b2e8d97be2f42" + caniuse-lite@^1.0.30000792: version "1.0.30000833" 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: version "2.0.0" resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f" +is-function@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/is-function/-/is-function-1.0.1.tgz#12cfb98b65b57dd3d193a3121f5f6e2f437602b5" + is-generator-fn@^1.0.0: version "1.0.0" 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: p-locate "^2.0.0" path-exists "^3.0.0" -lodash-es@^4.17.4: - version "4.17.10" - resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.10.tgz#62cd7104cdf5dd87f235a837f0ede0e8e5117e05" - lodash._baseassign@^3.0.0: version "3.2.0" resolved "https://registry.yarnpkg.com/lodash._baseassign/-/lodash._baseassign-3.2.0.tgz#8c38a099500f215ad09e59f1722fd0c52bfe0a4e" @@ -4301,6 +4305,10 @@ lodash.camelcase@^4.1.1: version "4.3.0" resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6" +lodash.curry@^4.1.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/lodash.curry/-/lodash.curry-4.1.1.tgz#248e36072ede906501d75966200a86dab8b23170" + lodash.get@^4.4.2: version "4.4.2" resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"