-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample8.js
73 lines (59 loc) · 1.95 KB
/
example8.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import Rx from 'rxjs/Rx';
import {
createSubscriber
} from './lib/util';
// // Rx.Observable.interval(1000)
// // .take(3)
// // .map(a => a+a)
// // .subscribe(createSubscriber("map"))
// function arrayMap(array, projection){
// const retArray = [];
// array.forEach(currentItem => {
// retArray.push(projection(currentItem));
// });
// return retArray;
// }
// // console.log(arrayMap([1,2,3], a=>a+a));
// function arrayMargeMap (array, projection ){
// const returnArray = [];
// for(let item of array){
// const projectedArray = projection(item);
// for(let projected of projectedArray){
// returnArray.push(projected);
// }
// }
// return returnArray;
// }
// const albumb = [
// {title:"album 1", tracks:[{id: 1, title:"track 1"}]},
// {title:"album 2", tracks:[{id: 2, title:"track 2"}]}
// ]
// const tracksWrong = arrayMap(albumb, albumb => albumb.tracks);
// const tracksRight = arrayMargeMap(albumb, albumb => albumb.tracks);
// console.log(JSON.stringify(tracksWrong));
// console.log(JSON.stringify(tracksRight));
// Rx.Observable.range(1, 3)
// .mergeMap(i => Rx.Observable.timer(i * 1000).map(() => `after ${i*2} seconds`))
// .subscribe(createSubscriber("mergeMap"));
// function getTracks(){
// return new Promise((resolve, reject) => {
// setTimeout(() => {
// resolve(["track 1","track 2","track 3"]);
// }, 1000)
// });
// }
// Rx.Observable.fromPromise(getTracks())
// .mergeMap(tracks => Rx.Observable.from(tracks))
// .subscribe(createSubscriber("tracks"))
function query(value){
return new Promise((resolve, reject) => {
setTimeout(function() {
resolve("this is a value")
}, 1000);
});
}
Rx.Observable.of("my quer")
.do(() => console.log("quering"))
.mergeMap(a => query(a))
.do(() => console.log("after quering"))
.subscribe(createSubscriber("query"))