Members
(constant) immSlot
create an immutable slot, which use '===' to test if value is mutated
(constant) mixin
add methods to Slot's prototype
Example
rimple.mixin({
negate() {
return this.val(-this.val());
}
});
const $$s = Slot(1).negate();
console.log($$s.val()); // output -1
(constant) mutate
mutate a group of slots, and starts ONE mutation proccess whose roots are these slots to be changed.
NOTE!!! this is not the same as set value for each slot one by one, but consider them as a whole to find the best mutaion path
Example
let $$p1 = Slot(1).tag('p1');
let $$p2 = Slot(2).tag('p2');
let $$p3 = $$p2.fork(it => it + 1).tag('p3');
let $$p4 = Slot(function ([p1, p2, p3], { roots, involved }) {
console.log(roots.map(it => it.tag())); // p1, p2
console.log(involved.map(it => it.tag())); // p1, p2, p3
return p1 + p2 + p3;
}, [$$p1, $$p2, $$p3]);
rimple.mutate([
[$$p1, 2],
[$$p2, 4],
]);
console.log($$p1.val(), $$p2.val(), $$p3.val(), $$p4.val()); // 2, 4, 5, 11
(constant) mutateWith
mutate a group of slots by applying functions upon them, and starts a mutation proccess whose roots are these slots to be changed
NOTE!!! this is not the same as set value for each slot one by one, but consider them as a whole to find the best mutaion path
Example
let $$p1 = Slot(1).tag('p1');
let $$p2 = Slot(2).tag('p2');
let $$p3 = $$p2.fork(it => it + 1).tag('p3');
let $$p4 = Slot(function ([p1, p2, p3], { roots, involved }) {
console.log(roots.map(it => it.tag())); // p1, p2
console.log(involved.map(it => it.tag())); // p1, p2, p3
return p1 + p2 + p3;
}, [$$p1, $$p2, $$p3]);
rimple.mutateWith([
[$$p1, n => n + 1],
[$$p2, n => n + 2],
]);
console.log($$p1.val(), $$p2.val(), $$p3.val(), $$p4.val()); // 2, 4, 5, 11