[6a3a178] | 1 | import { Observable } from '../Observable';
|
---|
| 2 | import { 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 | * Ignore every 3rd click event, starting from the first one
|
---|
| 23 | * ```ts
|
---|
| 24 | * import { fromEvent } from 'rxjs';
|
---|
| 25 | * import { windowCount, map, mergeAll, skip } from 'rxjs/operators';
|
---|
| 26 | *
|
---|
| 27 | * const clicks = fromEvent(document, 'click');
|
---|
| 28 | * const result = clicks.pipe(
|
---|
| 29 | * windowCount(3),
|
---|
| 30 | * map(win => win.pipe(skip(1))), // skip first of every 3 clicks
|
---|
| 31 | * mergeAll() // flatten the Observable-of-Observables
|
---|
| 32 | * );
|
---|
| 33 | * result.subscribe(x => console.log(x));
|
---|
| 34 | * ```
|
---|
| 35 | *
|
---|
| 36 | * Ignore every 3rd click event, starting from the third one
|
---|
| 37 | * ```ts
|
---|
| 38 | * import { fromEvent } from 'rxjs';
|
---|
| 39 | * import { windowCount, mergeAll } from 'rxjs/operators';
|
---|
| 40 | *
|
---|
| 41 | * const clicks = fromEvent(document, 'click');
|
---|
| 42 | * const result = clicks.pipe(
|
---|
| 43 | * windowCount(2, 3),
|
---|
| 44 | * mergeAll(), // flatten the Observable-of-Observables
|
---|
| 45 | * );
|
---|
| 46 | * result.subscribe(x => console.log(x));
|
---|
| 47 | * ```
|
---|
| 48 | *
|
---|
| 49 | * @see {@link window}
|
---|
| 50 | * @see {@link windowTime}
|
---|
| 51 | * @see {@link windowToggle}
|
---|
| 52 | * @see {@link windowWhen}
|
---|
| 53 | * @see {@link bufferCount}
|
---|
| 54 | *
|
---|
| 55 | * @param {number} windowSize The maximum number of values emitted by each
|
---|
| 56 | * window.
|
---|
| 57 | * @param {number} [startWindowEvery] Interval at which to start a new window.
|
---|
| 58 | * For example if `startWindowEvery` is `2`, then a new window will be started
|
---|
| 59 | * on every other value from the source. A new window is started at the
|
---|
| 60 | * beginning of the source by default.
|
---|
| 61 | * @return {Observable<Observable<T>>} An Observable of windows, which in turn
|
---|
| 62 | * are Observable of values.
|
---|
| 63 | * @method windowCount
|
---|
| 64 | * @owner Observable
|
---|
| 65 | */
|
---|
| 66 | export declare function windowCount<T>(windowSize: number, startWindowEvery?: number): OperatorFunction<T, Observable<T>>;
|
---|