question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ES6 Symbols break handleActions

See original GitHub issue

handleActions doesn’t correctly match actions with types that are Symbols, 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:closed
  • Created 8 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
gaearoncommented, Aug 24, 2015

(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.)

0reactions
lukewestbycommented, Oct 31, 2015

Closing since this issue is fixed. Please reopen if anything else comes up. Thanks!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found