From d6aeba6030d615a03f337e74800823d31fb706e0 Mon Sep 17 00:00:00 2001 From: Tim Cheung Date: Thu, 26 Jul 2018 01:24:50 +0100 Subject: [PATCH] =?UTF-8?q?use=20own=20`isFunction`,=20`isPlainObject?= =?UTF-8?q?=C2=B4=20and=20`isSymbol`=20checks`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 --- src/combineActions.js | 4 ++-- src/createAction.js | 2 +- src/createActions.js | 4 ++-- src/handleAction.js | 4 ++-- src/handleActions.js | 2 +- src/utils/flattenActionMap.js | 2 +- src/utils/flattenReducerMap.js | 2 +- src/utils/isFunction.js | 1 + src/utils/isPlainObject.js | 10 ++++++++++ src/utils/isSymbol.js | 4 ++++ yarn.lock | 4 ---- 12 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 src/utils/isFunction.js create mode 100644 src/utils/isPlainObject.js create mode 100644 src/utils/isSymbol.js diff --git a/package.json b/package.json index 0ccd145c..faf25113 100644 --- a/package.json +++ b/package.json @@ -66,9 +66,6 @@ }, "dependencies": { "invariant": "^2.2.1", - "is-function": "^1.0.1", - "is-plain-object": "^2.0.4", - "is-symbol": "^1.0.1", "lodash.camelcase": "^4.3.0", "lodash.curry": "^4.1.1", "reduce-reducers": "^0.1.0" diff --git a/src/combineActions.js b/src/combineActions.js index 10eeb9e6..5dbfa98e 100644 --- a/src/combineActions.js +++ b/src/combineActions.js @@ -1,6 +1,6 @@ import invariant from 'invariant'; -import isFunction from 'is-function'; -import isSymbol from 'is-symbol'; +import isFunction from './utils/isFunction'; +import isSymbol from './utils/isSymbol'; import isEmpty from './utils/isEmpty'; import toString from './utils/toString'; import isString from './utils/isString'; diff --git a/src/createAction.js b/src/createAction.js index 5e1e9021..6a3f3042 100644 --- a/src/createAction.js +++ b/src/createAction.js @@ -1,5 +1,5 @@ -import isFunction from 'is-function'; import invariant from 'invariant'; +import isFunction from './utils/isFunction'; import identity from './utils/identity'; import isNull from './utils/isNull'; diff --git a/src/createActions.js b/src/createActions.js index 582ea296..11a4e3be 100644 --- a/src/createActions.js +++ b/src/createActions.js @@ -1,6 +1,6 @@ -import isPlainObject from 'is-plain-object'; -import isFunction from 'is-function'; import invariant from 'invariant'; +import isPlainObject from './utils/isPlainObject'; +import isFunction from './utils/isFunction'; import identity from './utils/identity'; import isArray from './utils/isArray'; import isString from './utils/isString'; diff --git a/src/handleAction.js b/src/handleAction.js index cfefa024..285a4125 100644 --- a/src/handleAction.js +++ b/src/handleAction.js @@ -1,6 +1,6 @@ import invariant from 'invariant'; -import isFunction from 'is-function'; -import isPlainObject from 'is-plain-object'; +import isFunction from './utils/isFunction'; +import isPlainObject from './utils/isPlainObject'; import identity from './utils/identity'; import isNil from './utils/isNil'; import isUndefined from './utils/isUndefined'; diff --git a/src/handleActions.js b/src/handleActions.js index 5e67e5ab..5acaad08 100644 --- a/src/handleActions.js +++ b/src/handleActions.js @@ -1,6 +1,6 @@ import reduceReducers from 'reduce-reducers'; -import isPlainObject from 'is-plain-object'; import invariant from 'invariant'; +import isPlainObject from './utils/isPlainObject'; import isMap from './utils/isMap'; import ownKeys from './utils/ownKeys'; import flattenReducerMap from './utils/flattenReducerMap'; diff --git a/src/utils/flattenActionMap.js b/src/utils/flattenActionMap.js index f5df4795..5a9cd843 100644 --- a/src/utils/flattenActionMap.js +++ b/src/utils/flattenActionMap.js @@ -1,4 +1,4 @@ -import isPlainObject from 'is-plain-object'; +import isPlainObject from './isPlainObject'; import flattenWhenNode from './flattenWhenNode'; export default flattenWhenNode(isPlainObject); diff --git a/src/utils/flattenReducerMap.js b/src/utils/flattenReducerMap.js index ebaca8b9..3600a57e 100644 --- a/src/utils/flattenReducerMap.js +++ b/src/utils/flattenReducerMap.js @@ -1,4 +1,4 @@ -import isPlainObject from 'is-plain-object'; +import isPlainObject from './isPlainObject'; import isMap from './isMap'; import hasGeneratorInterface from './hasGeneratorInterface'; import flattenWhenNode from './flattenWhenNode'; diff --git a/src/utils/isFunction.js b/src/utils/isFunction.js new file mode 100644 index 00000000..c6a22c4c --- /dev/null +++ b/src/utils/isFunction.js @@ -0,0 +1 @@ +export default value => typeof value === 'function'; diff --git a/src/utils/isPlainObject.js b/src/utils/isPlainObject.js new file mode 100644 index 00000000..f1c7584f --- /dev/null +++ b/src/utils/isPlainObject.js @@ -0,0 +1,10 @@ +export default value => { + if (typeof value !== 'object' || value === null) return false; + + let proto = value; + while (Object.getPrototypeOf(proto) !== null) { + proto = Object.getPrototypeOf(proto); + } + + return Object.getPrototypeOf(value) === proto; +}; diff --git a/src/utils/isSymbol.js b/src/utils/isSymbol.js new file mode 100644 index 00000000..bd48cf74 --- /dev/null +++ b/src/utils/isSymbol.js @@ -0,0 +1,4 @@ +export default value => + typeof value === 'symbol' || + (typeof value === 'object' && + Object.prototype.toString.call(value) === '[object Symbol]'); diff --git a/yarn.lock b/yarn.lock index 494b4b93..65544086 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3456,10 +3456,6 @@ 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"