Skip to main content

bufferCount

bufferCount operator collects a specified number of consecutive values from the source signal and emits them as an array. This can be particularly useful when you want to group signal emits into fixed-size arrays for processing or presentation.

bufferCount<T>(bufferSize: number, options: SignalBufferCountOptions<T> = {}): T[]

Parameters

bufferSize The number of consecutive values to collect before emitting a buffered array
optionsOptional. The combination of CreateEffectOptions and CreateSignalOptions (excluding the equal and allowSignalWrites properties)

Example

Buffered stock price history

@Component()
export class MyComponent {
stockPrice: Signal<number> = signal(10);
stockPriceHistory: Signal<number[]> = signalPipe(source, bufferCount(3)); // Analyze or visualize the buffered stock price history

ngOnInit() {
this.stockPrice.set(11);
this.stockPrice.set(12);
console.log(this.stockPriceHistory()); // [10, 11, 12]
}
}