-
Notifications
You must be signed in to change notification settings - Fork 9
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
Setting multiple values #20
Comments
Couldn't this be accomplished with a simple utility function in your project? Using your example code: const setAll = (changes, object) => changes.reduce((newObject, change) => set(...change, newObject), object);
console.log(setAll([['foo', 2], ['bar', 3]], object)); // {foo: 2, bar: 3} EDIT: or if your changes are at the same nesting level in your object, you could use console.log(merge({foo: 2, bar: 3}, object)); // {foo: 2, bar: 3} |
Using |
So...a couple things here. One, I'll fall back on the use of Two... It's all relative. How many properties are you updating? How nested are these keys? I understand what you're saying, but it's conceptual ... Unless you are updating hundreds of deeply nested keys at once, the execution time difference is likely negligible for real world processing. And even in that edge case scenario, you're probably better off deep cloning and mutating the clone than setting a ton of specific properties immutably. |
Thanks for the advice. I suppose you're right that it doesn't make that big of a difference in normal use cases. I'll look into using |
So I'm trying to set multiple values on the object, and here's what I'm using:
This gets pretty unwieldy the more values I need to set, and my guess that its not very optimal. It'd be great to add better support for this use case, however I'm not sure what's the best way to add it to the existing api.
set
and other methods already have a fuzzy arg with an array type that does something else:Here's one option for overloading
set
:Thoughts?
The text was updated successfully, but these errors were encountered: