ES6 Symbols break handleActions
See original GitHub issuehandleActions
doesn’t correctly match actions with types that are Symbol
s, e.g.
const TEST_ACTION = Symbol('TEST_ACTION')
const OTHER_TEST_ACTION = 'OTHER_TEST_ACTION'
const reducer = handleActions({
[TEST_ACTION]: () => 'foo',
[OTHER_TEST_ACTION]: () => 'bar',
}, 'baz')
let state = 'test'
state = reducer(state, {type: TEST_ACTION})
console.log(state) // test (unexpected)
state = reducer(state, {type: OTHER_TEST_ACTION})
console.log(state) // bar (fine)
TEST_ACTION
is broken, OTHER_TEST_ACTION
is fine.
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
7. Symbols
In ES6, you can use symbols and be sure that they are always unique: ... When the new method Array.prototype.values() was created, it...
Read more >Metaprogramming in ES6: Symbols and why they're ...
But it actually makes a lot of sense when you see how each one is split: Symbols are all about Reflection within implementation...
Read more >A practical guide to ES6 Symbol
Here is a quick summary of how Symbols are used in code. A user-defined symbol is created with the global Symbol function. They...
Read more >Request: Remove the some type restrictions on Computed ...
Above are valid usages, but TS tips me: [ts] A computed property name must be of type 'string', 'number', 'symbol', or 'any'.
Read more >ES6 in Action: Symbols and Their Uses
Well-known Symbols. Because symbol-keyed properties are effectively invisible to pre-ES6 code, they're ideal for adding new functionality to ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
(Just FYI—while Redux supports symbols as action types, this is generally a bad idea. You won’t be able to serialize your actions and replay them.)
Closing since this issue is fixed. Please reopen if anything else comes up. Thanks!