Functional state getter & setter.
var state = {
a: {
b: {
c: 1
}
}
};
const setState = (newState) => {
state = newState;
};
console.log(yank(state, 'a.b.c', 1)); // 1
shove(setState, 'a.b.c')(2);
console.log(yank(state, 'a.b.c', 1)); // 2
console.log(yank(state, 'a.b.d')); // undefined
- Parameters:
setterFunction
Function, ie.const setState = this.setState.bind(this);
path
String, ie. 'user.details.name'
- Returns Function, parameters:
value
Any
- Parameters:
state
Objectpath
String, ie. 'user.details.name'default
Any
- Returns Any
dlv
(modified) - https://github.com/developit/dlvdset
(modified) - https://github.com/lukeed/dset
Attribution 4.0 International (CC BY 4.0)