From 691930621ac9f44544fab459f0d5d7bf09d618dc Mon Sep 17 00:00:00 2001 From: Homa Wong Date: Thu, 2 Nov 2017 08:34:51 -0700 Subject: [PATCH] feat(action.type): remove Symbol from allowed types (#86) BREAKING: `type` now *must* be a string constant. Resolves #39. Resolves #9. --- README.md | 2 +- src/index.d.ts | 2 +- src/index.js | 3 +-- test/isFSA.test.js | 5 +---- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 854a290..e6f2859 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ An action MUST NOT include properties other than `type`, `payload`, `error`, and ### `type` -The `type` of an action identifies to the consumer the nature of the action that has occurred. By convention, `type` is usually a string constant or a Symbol. If two types are the same, they MUST be strictly equivalent (using `===`). +The `type` of an action identifies to the consumer the nature of the action that has occurred. `type` is a string constant. If two types are the same, they MUST be strictly equivalent (using `===`). ### `payload` diff --git a/src/index.d.ts b/src/index.d.ts index 6c8b3dc..7e02074 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -3,7 +3,7 @@ export interface FluxStandardAction { * The `type` of an action identifies to the consumer the nature of the action that has occurred. * Two actions with the same `type` MUST be strictly equivalent (using `===`) */ - type: string | symbol; + type: string; /** * The optional `payload` property MAY be any type of value. * It represents the payload of the action. diff --git a/src/index.js b/src/index.js index babc290..7017b7a 100644 --- a/src/index.js +++ b/src/index.js @@ -1,13 +1,12 @@ import { isPlainObject, isString, - isSymbol, } from 'lodash'; export function isFSA(action) { return ( isPlainObject(action) && - (isString(action.type) || isSymbol(action.type)) && + isString(action.type) && Object.keys(action).every(isValidKey) ); } diff --git a/test/isFSA.test.js b/test/isFSA.test.js index 1970b4d..dfe1981 100644 --- a/test/isFSA.test.js +++ b/test/isFSA.test.js @@ -1,7 +1,6 @@ import { isFSA } from '../src/'; const type = 'ACTION_TYPE'; -const symbolType = Symbol.for(type); describe('isFSA()', () => { it('requires a type', () => { @@ -17,9 +16,7 @@ describe('isFSA()', () => { expect(isFSA(action)).toBe(false); }); - it('only returns true if type is a string or symbol', () => { - // remove this assertion if/when symbol support is dropped - expect(isFSA({ type: symbolType })).toBe(true); + it('only returns true if type is a string', () => { expect(isFSA({ type: true })).toBe(false); expect(isFSA({ type: 123 })).toBe(false); });