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

87 lines (80 loc) 2.86 kB
import { Observable } from 'rxjs'; import { Signal } from '@angular/core'; import { ToObservableOptions } from '@angular/core/rxjs-interop'; /** * Type to specify an object of observables */ type ObservableMap = Record<string, Observable<any>>; /** * Type to map `ObservableMap` to a static record type * the 'in' syntax forces the type specification by key */ type ObservableAccumulation<T extends ObservableMap> = { [K in keyof T]: ExtractObservableValue<T[K]>; }; /** * This type avoids empty objects */ type NotEmpty<T, U = { [K in keyof T]: Pick<T, K>; }> = Partial<T> & U[keyof U]; type ExtractObservableValue<T> = T extends Observable<infer R> ? R : never; /** * This Observable creation function helps to accumulate an object of key & Observable of values to * an Observable of objects of key & value. * This comes in handy if you quickly want to create subsets as objects/state-slices of different Observables. * * The resulting Observable filters out undefined values forwards only distinct values and shared the aggregated output. * * @example * * Default usage: * * const object$: Observable<{ * prop1: number, * prop2: string, * prop3: string * }> = accumulateObservables({ * prop1: interval(42), * prop2: of('lorem'), * prop3: 'test' * }); * * Usage with custom duration selector: * * const object$: Observable<{ * prop1: number, * prop2: string, * prop3: string * }> = accumulateObservables({ * prop1: interval(42), * prop2: of('lorem'), * prop3: 'test' * }, timer(0, 20)); * * @param obj - An object of key & Observable values pairs * @param durationSelector - An Observable determining the duration for the internal coalescing method */ declare function accumulateObservables<T extends ObservableMap & NotEmpty<T>>(obj: T, durationSelector?: Observable<any>): Observable<{ [K in keyof T]: ExtractObservableValue<T[K]>; }>; /** * @description * * This function returns the zone un-patched API for the a specific Browser API. * If no target is passed the window is used instead * * @param name - The name of the API to check. * @param target - The target to get un-patched API from. * @return {Function} - The zone un-patched API in question. * */ declare function getZoneUnPatchedApi<N extends keyof (Window & typeof globalThis)>(name: N): (Window & typeof globalThis)[N]; declare function getZoneUnPatchedApi<T extends object, N extends keyof T>(target: T, name: N): T[N]; /** * */ declare function timeoutSwitchMapWith<T>(): (o$: Observable<T>) => Observable<T>; declare function toObservableMicrotaskInternal<T>(source: Signal<T>, options?: ToObservableOptions): Observable<T>; export { accumulateObservables, getZoneUnPatchedApi, timeoutSwitchMapWith, toObservableMicrotaskInternal }; export type { ObservableAccumulation, ObservableMap };