Saved searches

Use saved searches to filter your results more quickly

Cancel Create saved search Sign up Reseting focus

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

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

zhaoyao91 opened this issue Feb 7, 2017 · 15 comments

support $unset #18

zhaoyao91 opened this issue Feb 7, 2017 · 15 comments

Comments

zhaoyao91 commented Feb 7, 2017

Could you please implement the $unset function? Thanks

The text was updated successfully, but these errors were encountered:

zhaoyao91 commented Feb 12, 2017

will keep the key in the state object? If so, I am afraid it's not proper for some cases such as key is random ids which are added and removed frequently. If we do not clear the key, the keys will explode.

kolodny commented Feb 12, 2017

There are two things you can do to get this usage. The first is to $apply the object you want to remove the property from:

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 $unset :

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