每日前提
- 内容为学习后的自我总结。再次感谢博主的分享,附上原po链接: 原po链接
宝珠图(Marble diagrams)
用-来表达一小段时间,这些-串起就代表一个observable(表示时间序列)
----------------
---------------X // Error happened
---------------| // observerable completed
Example one:
var source = Rx.Observable.interval(1000);
-----0-----1-----2-----3--...
Example two:
var source = Rx.Observable.of(1,2,3,4);
(1234)| // () means sync
Example three:
var source = Rx.Observable.interval(1000);
var newest = source.map(x => x + 1);
source: -----0-----1-----2-----3--...
map(x => x + 1)
newest: -----1-----2-----3-----4--...
Example Four:
var source = Rx.Observable.interval(1000);
var newest = source.map(x => x + 2);
newest.subscribe(console.log);
// 2
// 3
// 4
// 5..
source: -----0-----1-----2-----3--...
map(x => x + 1)
newest: -----1-----2-----3-----4--...
Example Five:
var source = Rx.Observable.interval(1000);
var newest = source.mapTo(2);
newest.subscribe(console.log);
// 2
// 2
// 2
// 2..
source: -----0-----1-----2-----3--...
mapTo(2)
newest: -----2-----2-----2-----2--...
Example Six:
var source = Rx.Observable.interval(1000);
var newest = source.filter(x => x % 2 === 0);
newest.subscribe(console.log);
// 0
// 2
// 4
// 6..
source: -----0-----1-----2-----3-----4-...
filter(x => x % 2 === 0)
newest: -----0-----------2-----------4-...