##// END OF EJS Templates
added pipe method to observable
added pipe method to observable

File last commit:

r114:e9a9ed6d7647 v1.5.0 default
r114:e9a9ed6d7647 v1.5.0 default
Show More
observable-tests.ts
81 lines | 1.8 KiB | video/mp2t | TypeScriptLexer
/ djx / src / test / ts / observable-tests.ts
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 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;
}
cin
linting
r108 };
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102
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 => {
cin
linting
r108 t.comment(`map1: ${v * 2}`);
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 maps++;
return v * 2;
})
cin
added pipe method to observable
r114 .map(v => {
cin
linting
r108 t.comment(`map2: ${v * 2}`);
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 maps++;
return v * 2;
})
.map(v => {
cin
linting
r108 t.comment(`map3: ${v * 2}`);
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 maps++;
cin
linting
r108 return v * 2;
cin
`Subscribable` is made compatible with rxjs, added map, filter and scan...
r102 })
.subscribe(consumer2);
t.equal(consumer2.value, 8, "Should map");
t.equal(maps, 3, "The map chain should not be executed after completion");
cin
corrected tear down logic handling in observables. Added support for observable query results
r110 t.ok(consumer2.completed, "The completion signal should pass through");
cin
added pipe method to observable
r114
const subj2 = observe<number>(({ next, complete }) => {
[1, 2, 3, 4, 5].forEach(next);
complete();
}).pipe<string>(self => ({ next, complete, error }) => {
t.comment("subj2: subscribe");
const h = self.subscribe({
next: val => {
if (val % 2 === 0)
next("odd");
else
next("even");
},
complete,
error
});
return () =>{
t.comment("subj2: unsubscribe");
h.unsubscribe();
};
});
subj2.subscribe({
next: val => t.comment("subj2: ", val),
complete: () => t.comment("subj2: complete")
});
subj2.subscribe({
next: val => t.comment("subj2: ", val),
complete: () => t.comment("subj2: complete")
});