-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
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
Give the initial action a Symbol type #114
Conversation
Not opposed but why is this better than type being undefined? Just so devtools know it's the first action? |
Yeah it's kind of looking weird there with |
Only "downside" is now Redux depends on a Symbol polyfill. But I guess we're assuming most people are using Babel, anyway. |
Yeah I wonder how bad of an impact that is.. |
👎 |
We don't plan to use Promises in core. The only runtimey feature I think of using is Symbols. Let's measure the impact on the compiled size, then consider. |
👍 for measuring things :D But let's also weigh the increased size against what it's buying us. If it's just so it looks less "weird" when hot reloading then I'm inclined to agree with @chicoxyzzy. |
It's still part of a bigger picture (#113). It's not the only place where I'd like to use Symbols. I think they solve the idea of “scoped” state keys or action types in the most natural way possible so it's not just a matter of “looking weird” but also a matter of using the right tool for the job vs making excuses “because polyfill”. But yeah, need to measure first. :-) |
Here's redux with core-js/es6/symbol (I imagine that's what we need, right?)
Without it:
It has an impact of 25% in the regular build and almost 35% in the minified one. |
@gaearon some people have native symbols. I bet you have them too in your Chrome. |
I understand that. Woah, that's a lot! I'm not super sure how core-js works. Can you try compiling code “as is” vs with changes in this PR? |
Just so we're on the same page: If we do decide to depend on Symbols, we shouldn't actually bundle it with Redux; we should list it in the docs as a prerequisite a la React, right? |
can we just add caveat that Redux uses Symbol? so developers will have a choice if they want to use polyfill or not |
@acdlite true |
@gaearon as is:
with this PR:
This code is just running scripts/browser on top of master (that's why the results differ from my previous reports). Anyway, the difference is almost negligible. |
OK, here's what I suggest: let's disable Babel's Symbol polyfilling and have something custom that turns Is this too crazy? |
I believe that it's much better to get rid of any kind of polyfill from such lightweight library. So we can just add a note in docs that Redux uses symbol. But... Are you sure Symbol is so necessary here? We lived without symbols in JS for many years. Yes symbols are cool for large-scale applications as they can help implement some cool patterns. But this is a library not a large-scale application. |
Also do you really want to write tests for all cases when you use Symbol or string constant? Because you can't be 100% sure it will work same way everywhere. What about @acdlite's experiments with Flow? Are you sure Flow works well with Symbol type? |
23kb minified is nothing. Moreover assets are typically served GZIP-ed. |
Symbols can't really be polyfilled well and they're iffy on IE8. FWIW I wrote a very minimal spec compliant Symbol polyfill, it's the one I was using in alt until I removed Symbols: https://github.com/goatslacker/es-symbol My 2 cents is that it's probably not worth it until there's more ES6 adoption, just try and pick a really mangled constant that no one will ever use. |
Uh, nevermind, I'll just prefix internal types with an underscore for now. |
Double const somePropSymbol = '@@someProp'
const someProp = this[somePropSymbol] |
Good point! |
I intend to use Symbol types for “internal” (or devtools-related) actions that the app should not handle.
As the first change, I propose to give a Symbol type to the initial action used to bootstrap the Store. (Currently it has no type at all.)
I can't imagine a situation in which a Store would want to know whether it's the initial action or not. So I don't think it's needed to expose this Symbol.