Skip to content

Conversation

@shinout
Copy link

@shinout shinout commented Mar 14, 2018

Add power-assign to docs of ImmutableUpdatePatterns.

It' an immutable updater of POJO using MongoDB's operator, easier access to nested values.

const obj = {
  count: 11,
  arr: ['value1'],
  bar: { baz: 'abc' },
}
const newObj = assign(obj, {
  $inc: { count: 1 }, // $inc: operator to increment number
  $push: { arr: 'value2' }, // $push: operator to push elements to array
  $unset: { 'bar.baz': '' }, // $unset: operator to unset a value
})

assert(newObj.count === 12)
assert(newObj.bar.hasOwnProperty('baz') === false)
assert.deepEqual(obj.arr, ['value1', 'value2'])

@markerikson
Copy link
Contributor

Hi. Appreciate the PR, but this isn't something I'm looking to specifically highlight on this docs page right now. I see that you submitted a PR to list it in my addons catalog, though, and I'll take that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants