UNPKG

@rx-angular/cdk

Version:

@rx-angular/cdk is a Component Development Kit for ergonomic and highly performant angular applications. It helps to to build Large scale applications, UI libs, state management, rendering systems and much more. Furthermore the unique way of mixing reacti

35 lines (34 loc) 1.75 kB
import { MonoTypeOperatorFunction, Observable } from 'rxjs'; /** * @description * Limits the number of synchronous emitted a value from the source Observable to * one emitted value per * durationSelector e.g. [`AnimationFrame`](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestAnimationFrame), then repeats * this process for every tick of the browsers event loop. * * The coalesce operator is based on the [throttle](https://rxjs-dev.firebaseapp.com/api/operators/throttle) operator. * In addition to that is provides emitted values for the trailing end only, as well as maintaining a context to scope * coalescing. * * @param {function(value: T): Observable} durationSelector - A function * that receives a value from the source Observable, for computing the silencing * duration for each source value, returned as an Observable or a Promise. * It defaults to `requestAnimationFrame` as durationSelector. * @param scope * Defaults to `{ leading: false, trailing: true }`. The default scoping is per subscriber. * @return {Observable<T>} An Observable that performs the coalesce operation to * limit the rate of emissions from the source. * * @usageNotes * Emit clicks at a rate of at most one click per second * ```typescript * import { interval, fromEvent } from 'rxjs'; * import { coalesceWith } from '@rx-angular/cdk/coalescing'; * * const setTimeoutDurationSelector = interval(500); * const clicks = fromEvent(document, 'click'); * const result = clicks.pipe(coalesceWith(setTimeoutDurationSelector)); * result.subscribe(x => console.log(x)); * ``` */ export declare function coalesceWith<T>(durationSelector: Observable<unknown>, scope?: Record<string, unknown>): MonoTypeOperatorFunction<T>;