-
Notifications
You must be signed in to change notification settings - Fork 47.1k
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
Thoughts on making react/lib/keyMirror an NPM module #1639
Comments
I thought the same thing, so I published keyMirror as a standalone module. |
Awesome! I heard some discussion about splitting out some utils in React into separate modules like this. I'm curious to know if Facebook would consider using @STRML's module, or if they'd rather keep things under their control. If not, I'd be happy to send out a PR. |
It's a super simple module - I think, in the end, it would be better to separate |
👍 |
1 similar comment
👍 |
We want to do this, but versioning will be an interesting problem which is why we haven't done it yet (these are common core modules which may need to be versioned separately from React for e.g. jest). Stay tuned... |
👍 @petehunt What's the challenge here? Most of these won't change a bunch. |
Out of pure curiosity, why does |
@ToucheSir The main purpose of keyMirror is to deal with the fact that Closure Compiler advanced mode crushes keys, which allows you to write code like
and have it become something like
which evaluates to
at runtime. If it was specified as a list of strings, they wouldn't get crushed matching the property names. |
@jordwalke and what happens when they do? what if we release a component that depends on a version of BTW, we were talking about changing |
@spicyj Thanks for the insight! Didn't even bother to think down that route, but now keyMirror is gaining appeal by the second. :) |
@spicyj i didn't got it, can you explain it more ? what's the whole point of the keymirror ? |
Google Closure Compiler has an advanced mode. It's more powerful than UglifyJS and will compress your code like crazy. In advanced mode, any property names you define will be “crushed” (unless you're defining them as strings). When you have code like var Stuff = {
GOOD_STUFF: 'GOOD_STUFF'
}; Closure Compiler in advanced mode will compress it to var a = {
b: 'GOOD_STUFF'
}; which will break your code. There are two options: a) Use string property name to opt out of crushing var a = {
'GOOD_STUFF': 'GOOD_STUFF'
}; This works, but you miss out on a nice optimization opportunity. b) Use a helper that makes sure keys and values match That's what |
Random usage of |
Hello, probably this sound redundant, I am using react by the bower package and I am trying to use keyMirror which is inside React.js, but this is not exposed as a global object, how can I use it without import another keyMirror package? |
You can't. |
Wouldn't it be easier to use key mirror the following way keyMirror(['monkey', 'gorilla']); Instead of keyMirror({monkey: null, gorilla: null}); |
See my comment on June 5 for the answer to your question. keyMirror isn't and has never been a supported API of React. I'm going to lock this conversation to reduce noise. |
I'm finding I really love something like
keyMirror
on non-react related fluxy projects. Is there a good NPM module for this, or considerations of making it a separate module?The text was updated successfully, but these errors were encountered: