1.0.18 • Published 5 years ago
@kingjs/descriptor.nested.update v1.0.18
@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
1.0.18
5 years ago
1.0.17
5 years ago
1.0.16
5 years ago
1.0.15
5 years ago
1.0.14
5 years ago
1.0.13
5 years ago
1.0.12
5 years ago
1.0.11
5 years ago
1.0.10
5 years ago
1.0.9
6 years ago
1.0.8
6 years ago
1.0.7
6 years ago
1.0.6
6 years ago
1.0.5
6 years ago
1.0.4
6 years ago
1.0.3
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago