Skip to content

Action types as symbols #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ooflorent opened this issue Jun 2, 2015 · 7 comments
Closed

Action types as symbols #4

ooflorent opened this issue Jun 2, 2015 · 7 comments

Comments

@ooflorent
Copy link
Contributor

Allowing this would be awesome.
Why did you enforce type as string? (createDispatcher.js#L67)

export const INCREMENT_COUNTER = Symbol()
export const DECREMENT_COUNTER = Symbol()
@gaearon
Copy link
Contributor

gaearon commented Jun 2, 2015

I thought of that, but this kind of screws the replay thing. (AFAIK you can't serialize and then deserialize symbols.) I want to pass them around for devtools, localStorage persistence, etc.

@ooflorent
Copy link
Contributor Author

You're right you cannot deserialize a Symbol. I've missed that point.

@gaearon
Copy link
Contributor

gaearon commented Jun 2, 2015

I say let's keep them strings for now and revisit if there are ways to get around (de)serialization problem.

@tbranyen
Copy link

I might be confused here, but what do you mean by "cannot deserialize a Symbol"?

const INCREMENT_COUNTER = Symbol('INCREMENT_COUNTER');

console.log(String(INCREMENT_COUNTER)); // Symbol(INCREMENT_COUNTER)

Wouldn't this be perfectly ideal for Redux? The ability to have identically named action types that are namespaced. I'm absolutely hating the fear that action types are overlapping since everything is global.

@tbranyen
Copy link

I just tried using a Symbol and thankfully it works excellent with Redux! The only error that came up was with redux-logger, so I'll narrow down the error and submit a patch (if one isn't already there).

@gaearon
Copy link
Contributor

gaearon commented Dec 16, 2015

You can't take an array of actions that use symbols, serialise them to JSON, save to localStorage, and later deserialise and replay them in a different browser session.

@tbranyen
Copy link

@gaearon I see what you mean, that is very true. For my use case it won't be a problem, and I've submitted a patch request for redux-logger here: LogRocket/redux-logger#106

(Sorry for spamming this particular issue, but I think it's useful for others looking to use Symbols).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants