Learn RxJS
Search…
windowCount

signature: windowCount(windowSize: number, startWindowEvery: number): Observable

Observable of values from source, emitted each time provided count is fulfilled.

Examples

Example 1: Start new window every x items emitted
1
// RxJS v6+
2
import { interval } from 'rxjs';
3
import { windowCount, mergeAll, tap } from 'rxjs/operators';
4
5
//emit every 1s
6
const source = interval(1000);
7
const example = source.pipe(
8
//start new window every 4 emitted values
9
windowCount(4),
10
tap(_ => console.log('NEW WINDOW!'))
11
);
12
13
const subscribeTwo = example
14
.pipe(
15
//window emits nested observable
16
mergeAll()
17
/*
18
output:
19
"NEW WINDOW!"
20
0
21
1
22
2
23
3
24
"NEW WINDOW!"
25
4
26
5
27
6
28
7
29
*/
30
)
31
.subscribe(val => console.log(val));
Copied!

Additional Resources

Last modified 2yr ago