-
Notifications
You must be signed in to change notification settings - Fork 16
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
Using local assign in Object Semigroup #42
Conversation
src/semigroup/object.js
Outdated
* Analogue of Object.assign(). Copies properties from one or more source objects to | ||
* a target object. Existing keys on the target object will be overwritten. | ||
* Modified to support copying Symbols. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a comment in here this exists because React Native does weird things?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. You know a library is arriving when there are disgusting code blocks there to work around platform-specific constraints. This is actually a good thing.
Since we are only using assign here, and not elsewhere, can we just make it operate on two arguments? That should tighten the loop a little bit and then it isn't more abstract than it needs to be.
@cowboyd done! |
I think we can even make the target of |
lol. If this were ramda, they'd probably call it |
It turns out that
extend-shallow
does not work as expected because it actually defaults toObject.assign
when available. We need to always use our own implementation ofObject.assign
inside of Object Semigroup to prevent React Native from overwriting our assign with theirs.The implementation that I added is just a little slower than
Object.assign
.I can get it to be little faster than
Object.assign
, but I need to replaceObject.keys(source).concat(Object.getOwnPropertySymbols(source))
with the following,I decided to not use it because it's pretty ugly, but we can always add it back.