Runkit
Runkit
home page
user forum
new notebook
clone notebook
download notebook
support & documentation
log in
sign up
new notebook
help & feedback
clone this notebook
download this notebook
Sign In
Sign Up
RunKit + npm: xyjax-update-immutable
node v10.24.1
endpoint
share
tweet
const { updateImmutable } = require('xyjax-update-immutable') var target_1 = {} //changes can be primitives... var target_2 = updateImmutable('a.b', 4)(target_1) //...objects... var target_3 = updateImmutable('c', {d: 5})(target_2) //...or calculating fields (with default parameters in case of field is not found) var target_4 = updateImmutable('c.d', (x = 0) => { return x * 2 })(target_3) //any of this approaches work at any nested level (calculating field as example) var target_5 = updateImmutable('a.b.c.d.e.f.g', (x = 5) => { return x * Math.random() })(target_1) console.log(target_1) // {} console.log(target_2) // {a: {b: 4}} console.log(target_3) // {a: {b: 4}, c: {d: 5}} console.log(target_4) // {a: {b: 4}, c: {d: 10}} console.log(target_5) // {a: {b: {c: {d: {e: {f: {g: Math.random() evaluation result}}}}}}}
Created from: https://npm.runkit.com/xyjax-update-immutable
Loading…
Clone and edit this document