UNPKG

1.97 kBTypeScriptView Raw
1import { OperatorFunction } from '../types';
2/**
3 * Buffers the source Observable values until the size hits the maximum
4 * `bufferSize` given.
5 *
6 * <span class="informal">Collects values from the past as an array, and emits
7 * that array only when its size reaches `bufferSize`.</span>
8 *
9 * ![](bufferCount.png)
10 *
11 * Buffers a number of values from the source Observable by `bufferSize` then
12 * emits the buffer and clears it, and starts a new buffer each
13 * `startBufferEvery` values. If `startBufferEvery` is not provided or is
14 * `null`, then new buffers are started immediately at the start of the source
15 * and when each buffer closes and is emitted.
16 *
17 * ## Examples
18 *
19 * Emit the last two click events as an array
20 *
21 * ```ts
22 * import { fromEvent, bufferCount } from 'rxjs';
23 *
24 * const clicks = fromEvent(document, 'click');
25 * const buffered = clicks.pipe(bufferCount(2));
26 * buffered.subscribe(x => console.log(x));
27 * ```
28 *
29 * On every click, emit the last two click events as an array
30 *
31 * ```ts
32 * import { fromEvent, bufferCount } from 'rxjs';
33 *
34 * const clicks = fromEvent(document, 'click');
35 * const buffered = clicks.pipe(bufferCount(2, 1));
36 * buffered.subscribe(x => console.log(x));
37 * ```
38 *
39 * @see {@link buffer}
40 * @see {@link bufferTime}
41 * @see {@link bufferToggle}
42 * @see {@link bufferWhen}
43 * @see {@link pairwise}
44 * @see {@link windowCount}
45 *
46 * @param {number} bufferSize The maximum size of the buffer emitted.
47 * @param {number} [startBufferEvery] Interval at which to start a new buffer.
48 * For example if `startBufferEvery` is `2`, then a new buffer will be started
49 * on every other value from the source. A new buffer is started at the
50 * beginning of the source by default.
51 * @return A function that returns an Observable of arrays of buffered values.
52 */
53export declare function bufferCount<T>(bufferSize: number, startBufferEvery?: number | null): OperatorFunction<T, T[]>;
54//# sourceMappingURL=bufferCount.d.ts.map
\No newline at end of file