Learn RxJS
Search…
windowToggle

signature: windowToggle(openings: Observable, closingSelector: function(value): Observable): Observable

Collect and emit observable of values from source between opening and closing emission.

Examples

Example 1: Toggle window at increasing interval
1
// RxJS v6+
2
import { timer, interval } from 'rxjs';
3
import { tap, windowToggle, mergeAll } from 'rxjs/operators';
4
5
//emit immediately then every 1s
6
const source = timer(0, 1000);
7
//toggle window on every 5
8
const toggle = interval(5000);
9
const example = source.pipe(
10
//turn window on every 5s
11
windowToggle(toggle, val => interval(val * 1000)),
12
tap(_ => console.log('NEW WINDOW!'))
13
);
14
15
const subscribeTwo = example
16
.pipe(
17
//window emits nested observable
18
mergeAll()
19
/*
20
output:
21
"NEW WINDOW!"
22
5
23
"NEW WINDOW!"
24
10
25
11
26
"NEW WINDOW!"
27
15
28
16
29
"NEW WINDOW!"
30
20
31
21
32
22
33
*/
34
)
35
.subscribe(val => console.log(val));
Copied!

Additional Resources