1 | import { 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 } from 'rxjs';
|
---|
23 | * import { bufferCount } from 'rxjs/operators';
|
---|
24 | *
|
---|
25 | * const clicks = fromEvent(document, 'click');
|
---|
26 | * const buffered = clicks.pipe(bufferCount(2));
|
---|
27 | * buffered.subscribe(x => console.log(x));
|
---|
28 | * ```
|
---|
29 | *
|
---|
30 | * On every click, emit the last two click events as an array
|
---|
31 | *
|
---|
32 | * ```ts
|
---|
33 | * import { fromEvent } from 'rxjs';
|
---|
34 | * import { bufferCount } from 'rxjs/operators';
|
---|
35 | *
|
---|
36 | * const clicks = fromEvent(document, 'click');
|
---|
37 | * const buffered = clicks.pipe(bufferCount(2, 1));
|
---|
38 | * buffered.subscribe(x => console.log(x));
|
---|
39 | * ```
|
---|
40 | *
|
---|
41 | * @see {@link buffer}
|
---|
42 | * @see {@link bufferTime}
|
---|
43 | * @see {@link bufferToggle}
|
---|
44 | * @see {@link bufferWhen}
|
---|
45 | * @see {@link pairwise}
|
---|
46 | * @see {@link windowCount}
|
---|
47 | *
|
---|
48 | * @param {number} bufferSize The maximum size of the buffer emitted.
|
---|
49 | * @param {number} [startBufferEvery] Interval at which to start a new buffer.
|
---|
50 | * For example if `startBufferEvery` is `2`, then a new buffer will be started
|
---|
51 | * on every other value from the source. A new buffer is started at the
|
---|
52 | * beginning of the source by default.
|
---|
53 | * @return {Observable<T[]>} An Observable of arrays of buffered values.
|
---|
54 | * @method bufferCount
|
---|
55 | * @owner Observable
|
---|
56 | */
|
---|
57 | export declare function bufferCount<T>(bufferSize: number, startBufferEvery?: number): OperatorFunction<T, T[]>;
|
---|