-
Notifications
You must be signed in to change notification settings - Fork 47.4k
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
[RFC] Add enum utility function #2606
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
The goal of the |
What @spicyj said. When I first saw keyMirror I actually wrote something very similar before being told the same thing. It's weird but it has a purpose. I encourage you to release any tools you find useful for yourself on npm / wherever. I'm sure others might find this useful. |
Thanks for the feedback, much appreciated. 👍 |
Initially this PR is not intended for merge for but primarily as a Request for Comments.
A few days ago I was poking around the code base with a friend and I came across the
keyMirror
utility function. I could see from how it was being used what the intention behind the function was but I had the feeling that the implementation (and api) of the function wasn't carried through enough to be useable in a practical sense.When I'm thinking of creating an enum what I want to do is simply define the set of valid values for it, I don't want to be hassled into first constructing an object literal whose keys represent my values. If I'm going to do that I might as well make a macro in my editor which transforms some structured list into that object.
I'd rather do this:
than:
I've implemented
enum
in terms ofkeyMirror
but it really doesn't need to be. IfkeyMirror
is only being used to build enumerations then I think it makes more sense to replace it entirely withenum
however I'm not sure how important BC is. I've given some thought on how to bring the two functions together but I'm interested in knowing your opinion on it.I'm also using the spread operator from ES6, I'm not sure if that's allowed or not.
Note I'm waiting on feedback before adding tests for this, no need to waste time on something that's not going anywhere :)