UNPKG

2.53 kBTypeScriptView Raw
1import { Observable } from '../Observable';
2import { OperatorFunction } from '../types';
3/**
4 * Branch out the source Observable values as a nested Observable with each
5 * nested Observable emitting at most `windowSize` values.
6 *
7 * <span class="informal">It's like {@link bufferCount}, but emits a nested
8 * Observable instead of an array.</span>
9 *
10 * ![](windowCount.png)
11 *
12 * Returns an Observable that emits windows of items it collects from the source
13 * Observable. The output Observable emits windows every `startWindowEvery`
14 * items, each containing no more than `windowSize` items. When the source
15 * Observable completes or encounters an error, the output Observable emits
16 * the current window and propagates the notification from the source
17 * Observable. If `startWindowEvery` is not provided, then new windows are
18 * started immediately at the start of the source and when each window completes
19 * with size `windowSize`.
20 *
21 * ## Examples
22 *
23 * Ignore every 3rd click event, starting from the first one
24 *
25 * ```ts
26 * import { fromEvent, windowCount, map, skip, mergeAll } from 'rxjs';
27 *
28 * const clicks = fromEvent(document, 'click');
29 * const result = clicks.pipe(
30 * windowCount(3),
31 * map(win => win.pipe(skip(1))), // skip first of every 3 clicks
32 * mergeAll() // flatten the Observable-of-Observables
33 * );
34 * result.subscribe(x => console.log(x));
35 * ```
36 *
37 * Ignore every 3rd click event, starting from the third one
38 *
39 * ```ts
40 * import { fromEvent, windowCount, mergeAll } from 'rxjs';
41 *
42 * const clicks = fromEvent(document, 'click');
43 * const result = clicks.pipe(
44 * windowCount(2, 3),
45 * mergeAll() // flatten the Observable-of-Observables
46 * );
47 * result.subscribe(x => console.log(x));
48 * ```
49 *
50 * @see {@link window}
51 * @see {@link windowTime}
52 * @see {@link windowToggle}
53 * @see {@link windowWhen}
54 * @see {@link bufferCount}
55 *
56 * @param {number} windowSize The maximum number of values emitted by each
57 * window.
58 * @param {number} [startWindowEvery] Interval at which to start a new window.
59 * For example if `startWindowEvery` is `2`, then a new window will be started
60 * on every other value from the source. A new window is started at the
61 * beginning of the source by default.
62 * @return A function that returns an Observable of windows, which in turn are
63 * Observable of values.
64 */
65export declare function windowCount<T>(windowSize: number, startWindowEvery?: number): OperatorFunction<T, Observable<T>>;
66//# sourceMappingURL=windowCount.d.ts.map
\No newline at end of file