##// END OF EJS Templates
`Subscribable` is made compatible with rxjs, added map, filter and scan...
`Subscribable` is made compatible with rxjs, added map, filter and scan methods to observables. `watch` can accept either stateful object and a property name to observe or the subscribable value. added ref attribute to the markup elements and widgets. `bind`, `tooggleClass` and `attach` methods can be passed to `ref` attribute in the markup to interact with elemnts and widgets.

File last commit:

r102:c65ea2350b1a v1.3
r102:c65ea2350b1a v1.3
Show More
observable-tests.ts
51 lines | 1.1 KiB | video/mp2t | TypeScriptLexer
/ djx / src / test / ts / observable-tests.ts
import { observe } from "./observable";
import * as t from "tap";
const subj1 = observe<number>(({ next, complete }) => {
next(1);
complete();
next(2);
});
const consumer1 = {
sum: 0,
next(v: number) {
this.sum += v;
}
}
subj1.subscribe(consumer1);
t.equal(consumer1.sum, 1, "Should get only one value");
subj1.subscribe(consumer1);
t.equal(consumer1.sum, 2, "Should get the value again");
const consumer2 = {
value: 0,
completed: false,
next(v: number) { this.value = v; },
complete() { this.completed = true; }
};
let maps = 0;
subj1
.map(v => {
t.comment("map1: " + v * 2);
maps++;
return v * 2;
})
.map (v => {
t.comment("map2: " + v * 2);
maps++;
return v * 2;
})
.map(v => {
t.comment("map3: " + v * 2);
maps++;
return v * 2
})
.subscribe(consumer2);
t.equal(consumer2.value, 8, "Should map");
t.equal(maps, 3, "The map chain should not be executed after completion");
t.ok(consumer2.completed, "The completion signal should pass through");