From 7ad209a22d1ee0521c74dcc75d6609af349b5e5a Mon Sep 17 00:00:00 2001 From: Justin Hewlett Date: Tue, 21 Jul 2015 23:13:51 -0600 Subject: [PATCH 1/2] Allow es6 symbols to be used as action types - Symbols are a good way to ensure uniqueness of your action types - In Chrome and Firefox, a symbol inside of a template literal throws an error. Making the string conversion explicit gets rid of the error --- src/utils/combineReducers.js | 4 ++-- test/utils/combineReducers.spec.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/utils/combineReducers.js b/src/utils/combineReducers.js index 54a74a4c82..3ac91cb1f3 100644 --- a/src/utils/combineReducers.js +++ b/src/utils/combineReducers.js @@ -10,8 +10,8 @@ import { ActionTypes } from '../createStore'; function getErrorMessage(key: String, action: Action): string { var actionType = action && action.type; - var actionName = actionType && `"${actionType}"` || 'an action'; - + var actionName = actionType && `"${actionType.toString()}"` || 'an action'; + return ( `Reducer "${key}" returned undefined handling ${actionName}. ` + `To ignore an action, you must explicitly return the previous state.` diff --git a/test/utils/combineReducers.spec.js b/test/utils/combineReducers.spec.js index 66d1e4e7f0..8b62e476f8 100644 --- a/test/utils/combineReducers.spec.js +++ b/test/utils/combineReducers.spec.js @@ -83,6 +83,23 @@ describe('Utils', () => { ); }); + it('should allow a symbol to be used as an action type', () => { + const increment = Symbol('INCREMENT') + + const reducer = combineReducers({ + counter(state = 0, action) { + switch (action.type) { + case increment: + return state + 1; + default: + return state; + } + } + }); + + expect(reducer(0, {type: increment}).counter).toEqual(1) + }); + it('should throw an error if a reducer attempts to handle a private action', () => { expect(() => combineReducers({ counter(state, action) { From adbfbdde0a561f25bd810b20bac03dd2be9a693c Mon Sep 17 00:00:00 2001 From: Justin Hewlett Date: Tue, 21 Jul 2015 23:40:23 -0600 Subject: [PATCH 2/2] Fix lint errors --- src/utils/combineReducers.js | 2 +- test/utils/combineReducers.spec.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/combineReducers.js b/src/utils/combineReducers.js index 3ac91cb1f3..45e5943f35 100644 --- a/src/utils/combineReducers.js +++ b/src/utils/combineReducers.js @@ -11,7 +11,7 @@ import { ActionTypes } from '../createStore'; function getErrorMessage(key: String, action: Action): string { var actionType = action && action.type; var actionName = actionType && `"${actionType.toString()}"` || 'an action'; - + return ( `Reducer "${key}" returned undefined handling ${actionName}. ` + `To ignore an action, you must explicitly return the previous state.` diff --git a/test/utils/combineReducers.spec.js b/test/utils/combineReducers.spec.js index 8b62e476f8..21be0a3529 100644 --- a/test/utils/combineReducers.spec.js +++ b/test/utils/combineReducers.spec.js @@ -84,7 +84,7 @@ describe('Utils', () => { }); it('should allow a symbol to be used as an action type', () => { - const increment = Symbol('INCREMENT') + const increment = Symbol('INCREMENT'); const reducer = combineReducers({ counter(state = 0, action) { @@ -97,7 +97,7 @@ describe('Utils', () => { } }); - expect(reducer(0, {type: increment}).counter).toEqual(1) + expect(reducer(0, {type: increment}).counter).toEqual(1); }); it('should throw an error if a reducer attempts to handle a private action', () => {