kingjs/descriptor.nested.update
@Updates the leafs of a tree to values returned by a callback which takes the current value.
Usage
Replace the name of the person followed with the object representing the person being followed like this:
var update = require('@kingjs/descriptor.nested.update');
var people = {
alice: {
name: 'Alice',
follows: 'bob'
},
bob: {
name: 'Bob',
follows: 'chris'
},
chris: {
name: 'Chris',
follows: 'alice'
}
};
var result = update.call(
people,
people,
{ '*': { follows: null } },
function(name) { return this[name]; }
)
result:
{
alice: {
name: 'Alice',
follows: { /* bob */ }
},
bob: {
name: 'Bob',
follows: { /* chris */ }
},
chris: {
name: 'Chris',
follows: { /* alice */ }
}
}
API
declare function update(
tree: NestedDescriptor,
path: NestedDescriptor,
callback: (leaf, path) => any,
thisArg?
): NestedDescriptor
Interfaces
-
NestedDescriptor
: see @kingjs/descriptor
Parameters
-
tree
: The tree whose leafs are going to be updated. -
path
: The paths of the values to be updated. -
callback
: Used to updatepaths
oftree
:-
leaf
: The leaf value. -
path
: The path value.
-
-
thisArg
: Thethis
argument to pass tocallback
.
Returns
Returns tree
with updated values for the leafs found at paths
.
Install
With npm installed, run
$ npm install @kingjs/descriptor.nested.update
License
MIT