-
Notifications
You must be signed in to change notification settings - Fork 1
/
concat.js
65 lines (62 loc) · 1.94 KB
/
concat.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
const concat = require('rxjs').concat;
const combineLatest = require('rxjs').combineLatest;
const merge = require('rxjs').merge;
const of = require('rxjs').of;
const startWith = require('rxjs/operators').startWith;
const timer = require('rxjs').timer;
const flatMap = require('rxjs/operators').flatMap;
const concatMap = require('rxjs/operators').concatMap;
const map = require('rxjs/operators').map;
const mapTo = require('rxjs/operators').mapTo;
const take = require('rxjs/operators').take;
const takeLast = require('rxjs/operators').takeLast;
const tap = require('rxjs/operators').tap;
const ignoreElements = require('rxjs/operators').ignoreElements;
const skip = require('rxjs/operators').skip;
const filter = require('rxjs/operators').filter;
const last = require('rxjs/operators').last;
const distinct = require('rxjs/operators').distinct;
const distinctUntilChanged = require('rxjs/operators').distinctUntilChanged;
// You can think of concat like a line at a ATM, the next transaction (subscription) cannot start
// until the previous completes!
const o$ = timer(30).pipe(mapTo('Outer'));
timer(0, 10).pipe(
map(i => `Inner ${i}`),
flatMap(r => concat(o$, of(r))),
distinct(),
take(10),
tap(console.log)
).subscribe();
/**
Outer
Inner 0
Inner 1
Inner 2
Inner 3
Inner 4
Inner 5
Inner 6
Inner 7
Inner 8
*/
// const o$ = timer(30).pipe(mapTo({a: 1, b:2}));
//
// timer(0, 10).pipe(
// map(i => ({a: i, b: 2})),
// flatMap(r => concat(o$, of(r))),
// distinct(),
// take(10),
// tap(console.log)
// ).subscribe();
/**
{ a: 1, b: 2 }
{ a: 0, b: 2 }
{ a: 1, b: 2 }
{ a: 2, b: 2 }
{ a: 3, b: 2 }
{ a: 4, b: 2 }
{ a: 5, b: 2 }
{ a: 6, b: 2 }
{ a: 7, b: 2 }
{ a: 8, b: 2 }
*/