Skip to content

Commit

Permalink
feat(action.type): remove Symbol from allowed types (#86)
Browse files Browse the repository at this point in the history
BREAKING: `type` now *must* be a string constant.

Resolves #39.
Resolves #9.
  • Loading branch information
unional authored and JaKXz committed Nov 2, 2017
1 parent cc178cf commit 6919306
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
2 changes: 1 addition & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface FluxStandardAction<Payload, Meta> {
* 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.
Expand Down
3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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)
);
}
Expand Down
5 changes: 1 addition & 4 deletions test/isFSA.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { isFSA } from '../src/';

const type = 'ACTION_TYPE';
const symbolType = Symbol.for(type);

describe('isFSA()', () => {
it('requires a type', () => {
Expand All @@ -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);
});
Expand Down

0 comments on commit 6919306

Please sign in to comment.