From 34da13e39198e7bbbc623f6ae4f1e5c286e44ac1 Mon Sep 17 00:00:00 2001 From: BlackHole1 <158blackhole@gmail.com> Date: Thu, 21 Mar 2019 10:13:26 +0800 Subject: [PATCH 1/2] refactor(type): Prevent the toString method from being overridden --- src/createAction.js | 2 +- src/utils/flattenWhenNode.js | 2 +- src/utils/toString.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/createAction.js b/src/createAction.js index 6a3f3042..da28b98c 100644 --- a/src/createAction.js +++ b/src/createAction.js @@ -20,7 +20,7 @@ export default function createAction( head instanceof Error ? head : payloadCreator(head, ...args); const hasMeta = isFunction(metaCreator); - const typeString = type.toString(); + const typeString = String(type); const actionCreator = (...args) => { const payload = finalPayloadCreator(...args); diff --git a/src/utils/flattenWhenNode.js b/src/utils/flattenWhenNode.js index 3ee137f1..9c23f61b 100644 --- a/src/utils/flattenWhenNode.js +++ b/src/utils/flattenWhenNode.js @@ -11,7 +11,7 @@ export default predicate => ) { function connectNamespace(type) { if (!partialFlatActionType) return type; - const types = type.toString().split(ACTION_TYPE_DELIMITER); + const types = String(type).split(ACTION_TYPE_DELIMITER); const partials = partialFlatActionType.split(ACTION_TYPE_DELIMITER); return [] .concat(...partials.map(p => types.map(t => `${p}${namespace}${t}`))) diff --git a/src/utils/toString.js b/src/utils/toString.js index e33f21a6..428d1cad 100644 --- a/src/utils/toString.js +++ b/src/utils/toString.js @@ -1 +1 @@ -export default value => value.toString(); +export default value => String(value); From b580a620bcea86b9616fc63328687bb82d775712 Mon Sep 17 00:00:00 2001 From: BlackHole1 <158blackhole@gmail.com> Date: Thu, 21 Mar 2019 10:21:09 +0800 Subject: [PATCH 2/2] refactor(type): "Increase the handling of undefined cases" --- src/createAction.js | 6 +++--- src/utils/isNull.js | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) delete mode 100644 src/utils/isNull.js diff --git a/src/createAction.js b/src/createAction.js index da28b98c..5c39b419 100644 --- a/src/createAction.js +++ b/src/createAction.js @@ -1,7 +1,7 @@ import invariant from 'invariant'; import isFunction from './utils/isFunction'; import identity from './utils/identity'; -import isNull from './utils/isNull'; +import isNil from './utils/isNil'; export default function createAction( type, @@ -9,12 +9,12 @@ export default function createAction( metaCreator ) { invariant( - isFunction(payloadCreator) || isNull(payloadCreator), + isFunction(payloadCreator) || isNil(payloadCreator), 'Expected payloadCreator to be a function, undefined or null' ); const finalPayloadCreator = - isNull(payloadCreator) || payloadCreator === identity + isNil(payloadCreator) || payloadCreator === identity ? identity : (head, ...args) => head instanceof Error ? head : payloadCreator(head, ...args); diff --git a/src/utils/isNull.js b/src/utils/isNull.js deleted file mode 100644 index b7664b39..00000000 --- a/src/utils/isNull.js +++ /dev/null @@ -1 +0,0 @@ -export default value => value === null;