From e875b471aa2b1ed9262dc823ccdb7f9e876d5e22 Mon Sep 17 00:00:00 2001 From: Tim Cheung Date: Tue, 6 Sep 2016 11:06:12 +0200 Subject: [PATCH 1/2] Omit payload on undefined only --- src/__tests__/createAction-test.js | 3 ++- src/createAction.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/__tests__/createAction-test.js b/src/__tests__/createAction-test.js index 1265dd9a..22332534 100644 --- a/src/__tests__/createAction-test.js +++ b/src/__tests__/createAction-test.js @@ -95,7 +95,8 @@ describe('createAction()', () => { const explictNullAction = createAction(type)(null); expect(explictNullAction).to.deep.equal({ - type + type, + payload: null }); const baz = '1'; diff --git a/src/createAction.js b/src/createAction.js index 5a4eab5b..e6e706de 100644 --- a/src/createAction.js +++ b/src/createAction.js @@ -1,4 +1,5 @@ import identity from 'lodash/identity'; +import isUndefined from 'lodash/isUndefined'; export default function createAction(type, payloadCreator, metaCreator) { const finalPayloadCreator = typeof payloadCreator === 'function' @@ -13,7 +14,7 @@ export default function createAction(type, payloadCreator, metaCreator) { }; const payload = hasError ? args[0] : finalPayloadCreator(...args); - if (!(payload === null || payload === undefined)) { + if (!isUndefined(payload)) { action.payload = payload; } From fbfcab1b78e538742830cd8408e210ecbc44a782 Mon Sep 17 00:00:00 2001 From: Tim Cheung Date: Tue, 27 Sep 2016 11:57:24 +0200 Subject: [PATCH 2/2] remove obsolete test --- src/__tests__/createAction-test.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/__tests__/createAction-test.js b/src/__tests__/createAction-test.js index 22332534..bce3cc54 100644 --- a/src/__tests__/createAction-test.js +++ b/src/__tests__/createAction-test.js @@ -93,12 +93,6 @@ describe('createAction()', () => { type }); - const explictNullAction = createAction(type)(null); - expect(explictNullAction).to.deep.equal({ - type, - payload: null - }); - const baz = '1'; const actionCreator = createAction(type, null, () => ({ bar: baz })); expect(actionCreator()).to.deep.equal({