PATH:
usr
/
local
/
lib
/
node_modules
/
ghost-cli
/
node_modules
/
rxjs
/
src
/
internal
/
operators
import { Operator } from '../Operator'; import { Subscriber } from '../Subscriber'; import { Observable } from '../Observable'; import { OperatorFunction, TeardownLogic } from '../types'; /** * Buffers the source Observable values until the size hits the maximum * `bufferSize` given. * * <span class="informal">Collects values from the past as an array, and emits * that array only when its size reaches `bufferSize`.</span> * *  * * Buffers a number of values from the source Observable by `bufferSize` then * emits the buffer and clears it, and starts a new buffer each * `startBufferEvery` values. If `startBufferEvery` is not provided or is * `null`, then new buffers are started immediately at the start of the source * and when each buffer closes and is emitted. * * ## Examples * * Emit the last two click events as an array * * ```ts * import { fromEvent } from 'rxjs'; * import { bufferCount } from 'rxjs/operators'; * * const clicks = fromEvent(document, 'click'); * const buffered = clicks.pipe(bufferCount(2)); * buffered.subscribe(x => console.log(x)); * ``` * * On every click, emit the last two click events as an array * * ```ts * import { fromEvent } from 'rxjs'; * import { bufferCount } from 'rxjs/operators'; * * const clicks = fromEvent(document, 'click'); * const buffered = clicks.pipe(bufferCount(2, 1)); * buffered.subscribe(x => console.log(x)); * ``` * * @see {@link buffer} * @see {@link bufferTime} * @see {@link bufferToggle} * @see {@link bufferWhen} * @see {@link pairwise} * @see {@link windowCount} * * @param {number} bufferSize The maximum size of the buffer emitted. * @param {number} [startBufferEvery] Interval at which to start a new buffer. * For example if `startBufferEvery` is `2`, then a new buffer will be started * on every other value from the source. A new buffer is started at the * beginning of the source by default. * @return {Observable<T[]>} An Observable of arrays of buffered values. * @method bufferCount * @owner Observable */ export function bufferCount<T>(bufferSize: number, startBufferEvery: number = null): OperatorFunction<T, T[]> { return function bufferCountOperatorFunction(source: Observable<T>) { return source.lift(new BufferCountOperator<T>(bufferSize, startBufferEvery)); }; } class BufferCountOperator<T> implements Operator<T, T[]> { private subscriberClass: any; constructor(private bufferSize: number, private startBufferEvery: number) { if (!startBufferEvery || bufferSize === startBufferEvery) { this.subscriberClass = BufferCountSubscriber; } else { this.subscriberClass = BufferSkipCountSubscriber; } } call(subscriber: Subscriber<T[]>, source: any): TeardownLogic { return source.subscribe(new this.subscriberClass(subscriber, this.bufferSize, this.startBufferEvery)); } } /** * We need this JSDoc comment for affecting ESDoc. * @ignore * @extends {Ignored} */ class BufferCountSubscriber<T> extends Subscriber<T> { private buffer: T[] = []; constructor(destination: Subscriber<T[]>, private bufferSize: number) { super(destination); } protected _next(value: T): void { const buffer = this.buffer; buffer.push(value); if (buffer.length == this.bufferSize) { this.destination.next(buffer); this.buffer = []; } } protected _complete(): void { const buffer = this.buffer; if (buffer.length > 0) { this.destination.next(buffer); } super._complete(); } } /** * We need this JSDoc comment for affecting ESDoc. * @ignore * @extends {Ignored} */ class BufferSkipCountSubscriber<T> extends Subscriber<T> { private buffers: Array<T[]> = []; private count: number = 0; constructor(destination: Subscriber<T[]>, private bufferSize: number, private startBufferEvery: number) { super(destination); } protected _next(value: T): void { const { bufferSize, startBufferEvery, buffers, count } = this; this.count++; if (count % startBufferEvery === 0) { buffers.push([]); } for (let i = buffers.length; i--; ) { const buffer = buffers[i]; buffer.push(value); if (buffer.length === bufferSize) { buffers.splice(i, 1); this.destination.next(buffer); } } } protected _complete(): void { const { buffers, destination } = this; while (buffers.length > 0) { let buffer = buffers.shift(); if (buffer.length > 0) { destination.next(buffer); } } super._complete(); } }
[-] toArray.ts
[edit]
[-] window.ts
[edit]
[-] retry.ts
[edit]
[-] mergeAll.ts
[edit]
[-] windowWhen.ts
[edit]
[-] every.ts
[edit]
[-] timeout.ts
[edit]
[-] debounceTime.ts
[edit]
[-] index.ts
[edit]
[-] takeWhile.ts
[edit]
[-] audit.ts
[edit]
[-] reduce.ts
[edit]
[-] mapTo.ts
[edit]
[-] count.ts
[edit]
[-] debounce.ts
[edit]
[-] throwIfEmpty.ts
[edit]
[-] auditTime.ts
[edit]
[-] scan.ts
[edit]
[-] switchAll.ts
[edit]
[-] map.ts
[edit]
[-] bufferCount.ts
[edit]
[-] mergeScan.ts
[edit]
[-] publish.ts
[edit]
[-] min.ts
[edit]
[+]
..
[-] publishReplay.ts
[edit]
[-] bufferTime.ts
[edit]
[-] share.ts
[edit]
[-] repeat.ts
[edit]
[-] distinct.ts
[edit]
[-] concatMapTo.ts
[edit]
[-] buffer.ts
[edit]
[-] concatMap.ts
[edit]
[-] max.ts
[edit]
[-] partition.ts
[edit]
[-] observeOn.ts
[edit]
[-] bufferWhen.ts
[edit]
[-] dematerialize.ts
[edit]
[-] throttle.ts
[edit]
[-] groupBy.ts
[edit]
[-] withLatestFrom.ts
[edit]
[-] exhaust.ts
[edit]
[-] exhaustMap.ts
[edit]
[-] retryWhen.ts
[edit]
[-] zipAll.ts
[edit]
[-] find.ts
[edit]
[-] mergeMap.ts
[edit]
[-] single.ts
[edit]
[-] last.ts
[edit]
[-] combineLatest.ts
[edit]
[-] publishLast.ts
[edit]
[-] pluck.ts
[edit]
[-] pairwise.ts
[edit]
[-] distinctUntilChanged.ts
[edit]
[-] timeInterval.ts
[edit]
[-] shareReplay.ts
[edit]
[-] skipUntil.ts
[edit]
[-] findIndex.ts
[edit]
[-] windowToggle.ts
[edit]
[-] startWith.ts
[edit]
[-] timeoutWith.ts
[edit]
[-] concat.ts
[edit]
[-] materialize.ts
[edit]
[-] timestamp.ts
[edit]
[-] onErrorResumeNext.ts
[edit]
[-] subscribeOn.ts
[edit]
[-] takeUntil.ts
[edit]
[-] skipLast.ts
[edit]
[-] throttleTime.ts
[edit]
[-] mergeMapTo.ts
[edit]
[-] multicast.ts
[edit]
[-] merge.ts
[edit]
[-] takeLast.ts
[edit]
[-] delayWhen.ts
[edit]
[-] sampleTime.ts
[edit]
[-] tap.ts
[edit]
[-] take.ts
[edit]
[-] sample.ts
[edit]
[-] filter.ts
[edit]
[-] skip.ts
[edit]
[-] expand.ts
[edit]
[-] publishBehavior.ts
[edit]
[-] sequenceEqual.ts
[edit]
[-] ignoreElements.ts
[edit]
[-] catchError.ts
[edit]
[-] endWith.ts
[edit]
[-] refCount.ts
[edit]
[-] windowCount.ts
[edit]
[-] defaultIfEmpty.ts
[edit]
[-] windowTime.ts
[edit]
[-] switchMapTo.ts
[edit]
[-] switchMap.ts
[edit]
[-] delay.ts
[edit]
[-] bufferToggle.ts
[edit]
[-] repeatWhen.ts
[edit]
[-] concatAll.ts
[edit]
[-] first.ts
[edit]
[-] zip.ts
[edit]
[-] elementAt.ts
[edit]
[-] skipWhile.ts
[edit]
[-] race.ts
[edit]
[-] finalize.ts
[edit]
[-] combineAll.ts
[edit]
[-] distinctUntilKeyChanged.ts
[edit]
[-] isEmpty.ts
[edit]