xain
Using ES2015 proxies to simplify observation and reaction
Usage
Simple observation
'use strict'; const observable observe = ; const o = ;let count = 0;const unobserve = ; // returns a funtion that, when called, stops the observation// count == 0ofoo = 1;// count == 0ofoo = 2;ofoo = 2;// count == 1ofoo = 1;// count == 2; // stop the observerofoo = 5;ofoo = 6;ofoo = 7;// count == 2
Batched observation
(Use when you make several changes and you want to get the diff, if it exists, between the first and last changes on this tick)
const o = ; // notice the `true` parameter indicating it is batchedlet count = 0;;// count == 0ofoo = 0;// count == 0ofoo = 2;ofoo = 2;// count == 0process;
Reactive links
const x = ; const o = x;let counter = 0;const r = x;t;t;t;t;ox = 3;t;t;t;t;ox = 5;t;t;t;t;
Note: a link
function must always get
every single dependency every time it runs.
The easiest way is to destructure the observable (the actual argument passed to the link function)
into the properties the link depends upon.
Observable streams
const x = ; const o = x;const str = x ;const expected = 3 4 2;let actual = ;x;ox = 1;ox = -2;ox = 5;t;t;t;