Sherlock provides the pluck method on derivations:
const a$ = atom({ property: 'value' });
const plucked$ = a$.pluck('property');
// now you can do:
plucked$.get(); // returns 'value';
plucked$.set('new value'); // a$ becomes: { property: 'new value' }
// In this case the pluck command is shorthand for the following:
const plucked$ = a$.lens({
get: obj => obj.property,
set: (newValue, obj) => { ...obj, property: newValue },
});
This can be used to create a cursor to a specific subtree of a more complex state. It works with ordinary JavaScript objects, but also with objects from Immutable.js and JavaScript Maps.
Just like with pluggable equals functions (#14), this pluck mechanism should also be pluggable to support other object types.
Sherlock provides the
pluck
method on derivations:This can be used to create a cursor to a specific subtree of a more complex state. It works with ordinary JavaScript objects, but also with objects from Immutable.js and JavaScript Maps.
Just like with pluggable equals functions (#14), this pluck mechanism should also be pluggable to support other object types.