-
Notifications
You must be signed in to change notification settings - Fork 186
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
support $unset #18
Comments
You can use |
will |
There are two things you can do to get this usage. The first is to var state = {
sub: {
keep: true,
remove: true
}
}
var next = update(state, {
sub: {
$apply: function(obj) {
var copy = Object.assign({}, obj)
delete copy.remove
return copy
}
}
})
console.log('remove' in next.sub) // false
console.log('keep' in next.sub) // true The other is to extend the update function to include update.extend('$unset', function(keysToRemove, original) {
var copy = Object.assign({}, original)
for (const key of keysToRemove) delete copy[key]
return copy
});
// usage is as follows
var state = {
sub: {
keep: true,
remove: true
}
}
var next = update(state, {
sub: {
$unset: ['remove']
}
})
console.log('remove' in next.sub) // false
console.log('keep' in next.sub) // true |
Why not include |
I agree with @kachkaev this should be included in the standard library, now I have to have a global initialization routine instead of only requiring the library wherever I use it. |
This has been discussion on this in the react repo, I'd rather not include it especially considering you can extend it in as done above. See the comment by @spicyj here |
@kolodny that comment by @spicyj is 1.5 years old though. I am personally relying on Patching |
Adding $unset would not make this a "crazy DSL" as per the cited comment. I would argue that without it, immutability-helper is actually incomplete. Modifications come in three basic forms: additions, updates, and removals. So why limit this library to the first two, when adding the third only costs 5 lines of code? |
My update-immutable package supports https://www.npmjs.com/package/update-immutable My module also implements autovivification which IMO is another feature for |
I seemed to have underestimated the desire for this feature. It will be included in the next release. Thanks to everyone for all the feedback. |
Hi @kolodny, When about do you think you might release that version? Just wanted to use |
This is done and released in |
Hi @kolodny, Are you sure that the $unset function is immutable? I have a redux case using unset that isn't triggering a re-render in components:
When I replaced it with the following, using Lodash's omit function, it did trigger a re-render.
Please let me know if I'm wrong, just wanted to bring this to your attention. I do have the correct version, from my package lock:
|
@gbennum Worked for me. 2.6.6 |
Great! Glad to see I was wrong. I wonder what the difference is between the omit and update that would change the behavior of rendering in components. |
Could you please implement the
$unset
function? ThanksThe text was updated successfully, but these errors were encountered: