import * as i0 from '@angular/core'; import { NgZone, ChangeDetectorRef, InjectionToken, Provider } from '@angular/core'; import { coalescingObj, RxCoalescingOptions } from '@rx-angular/cdk/coalescing'; import { RxNotification } from '@rx-angular/cdk/notifications'; import { Observable, MonoTypeOperatorFunction } from 'rxjs'; interface ScheduleOnStrategyOptions { scope?: object; strategy?: string; patchZone?: false | NgZone; } type RxRenderWork = (cdRef: ChangeDetectorRef, scope?: coalescingObj, notification?: RxNotification) => void; type RxRenderBehavior = (params: { work: () => any; scope?: coalescingObj; ngZone?: NgZone; }) => (o: Observable) => Observable; interface RxStrategyCredentials { name: S; work: RxRenderWork; behavior: RxRenderBehavior; } type RxCustomStrategyCredentials = Record; type RxNativeStrategyNames = 'native' | 'local' | 'noop'; type RxConcurrentStrategyNames = 'immediate' | 'userBlocking' | 'normal' | 'low' | 'idle'; type RxDefaultStrategyNames = RxNativeStrategyNames | RxConcurrentStrategyNames; type RxStrategyNames = RxDefaultStrategyNames | T; type RxStrategies = RxCustomStrategyCredentials>; type RxConcurrentStrategies = RxCustomStrategyCredentials; declare const RX_CONCURRENT_STRATEGIES: RxConcurrentStrategies; interface RxRenderStrategiesConfig { primaryStrategy?: RxStrategyNames; customStrategies?: RxCustomStrategyCredentials; patchZone?: boolean; /** * @deprecated This flag will be dropped soon, as it is no longer required when using signal based view & content queries */ parent?: boolean; } declare const RX_RENDER_STRATEGIES_CONFIG: InjectionToken>; /** * @description * Can be used to set the default render strategy or create custom render strategies. * * With this function you can customize the behavior of: * - `rxLet` directive * - `rxFor` directive * - `rxIf` directive * - `rxVirtualFor` directive * - `rxVirtualView` directive * - `RxStrategyProvider` service. * * @example * import { provideRxRenderStrategies } from '@rx-angular/cdk/render-strategies'; * * const appConfig: ApplicationConfig = { * providers: [ * provideRxRenderStrategies({ * primaryStrategy: 'sync', * customStrategies: { * sync: { * name: 'sync', * work: (cdRef) => { cdRef.detectChanges(); }, * behavior: ({ work }) => (o$) => o$.pipe(tap(() => work())) * }, * asap: { * name: 'asap', * work: (cdRef) => { cdRef.detectChanges(); }, * behavior: ({ work }) => (o$) => o$.pipe(delay(0, asapScheduler), tap(() => work())) * }, * }), * ], * }; * * @param config - The configuration object. * @returns A provider that can be used to set the default render strategy or create custom render strategies. */ declare function provideRxRenderStrategies(config: RxRenderStrategiesConfig | (() => RxRenderStrategiesConfig)): Provider; type RxNativeStrategies = RxCustomStrategyCredentials; declare const RX_NATIVE_STRATEGIES: RxNativeStrategies; /** * @internal * * @param value * @param strategy * @param workFactory * @param options */ declare function onStrategy(value: T, strategy: RxStrategyCredentials, workFactory: (value: T, work: RxRenderWork, options: RxCoalescingOptions) => void, options?: RxCoalescingOptions & { ngZone?: NgZone; }): Observable; interface RxStrategyHandler { strategy$: Observable; next(name: RxStrategyNames | Observable): void; } /** * @internal * * A factory function returning an object to handle the process of turning strategy names into `RxStrategyCredentials` * You can next a strategy name as Observable or string and get an Observable of `RxStrategyCredentials` * * @param defaultStrategyName * @param strategies */ declare function strategyHandling(defaultStrategyName: string, strategies: RxCustomStrategyCredentials): RxStrategyHandler; /** * @description * RxStrategyProvider is a wrapper service that you can use to consume strategies and schedule your code execution. * * @example * Component({ * selector: 'app-service-communicator', * template: `` * }); * export class ServiceCommunicationComponent { * private currentUserSettings; * * constructor( * private strategyProvider: RxStrategyProvider, * private userService: UserService, * private backgroundSync: BackgroundSyncService * ) { * this.userService.fetchCurrentUserSettings * .pipe( * tap(settings => (this.currentUserSettings = settings)), * this.strategyProvider.scheduleWith( * settings => this.backgroundSync.openConnection(settings), * { strategy: 'idle' } * ) * ) * .subscribe(); * } * } * * @docsCategory RxStrategyProvider * @docsPage RxStrategyProvider */ declare class RxStrategyProvider { private _strategies$; private _primaryStrategy$; private readonly _cfg; /** * @description * Returns current `RxRenderStrategiesConfig` used in the service. * Config includes: * - strategy that currently in use - `primaryStrategy` * - array of custom user defined strategies - `customStrategies` * - setting that is responsible for running in our outside of the zone.js - `patchZone` */ get config(): Required>; /** * @description * Returns object that contains key-value pairs of strategy names and their credentials (settings) that are available in the service. */ get strategies(): RxStrategies; /** * @description * Returns an array of strategy names available in the service. */ get strategyNames(): string[]; /** * @description * Returns current strategy of the service. */ get primaryStrategy(): RxStrategyNames; /** * @description * Set's the strategy that will be used by the service. */ set primaryStrategy(strategyName: RxStrategyNames); /** * @description * Current strategy of the service as an observable. */ readonly primaryStrategy$: Observable; /** * @description * Returns observable of an object that contains key-value pairs of strategy names and their credentials (settings) that are available in the service. */ readonly strategies$: Observable>; /** * @description * Returns an observable of an array of strategy names available in the service. */ readonly strategyNames$: Observable; /** * @internal */ constructor(cfg: RxRenderStrategiesConfig); /** * @description * Allows to schedule a work inside rxjs `pipe`. Accepts the work and configuration options object. * - work is any function that should be executed * - (optional) options includes strategy, patchZone and scope * * Scope is by default a subscription but you can also pass `this` and then the scope will be current component. * Scope setup is useful if your work is some of the methods of `ChangeDetectorRef`. Only one change detection will be triggered if you have multiple schedules of change detection methods and scope is set to `this`. * * @example * myObservable$.pipe( * this.strategyProvider.scheduleWith(() => myWork(), {strategy: 'idle', patchZone: false}) * ).subscribe(); * * @return MonoTypeOperatorFunction */ scheduleWith(work: (v?: R) => void, options?: ScheduleOnStrategyOptions): MonoTypeOperatorFunction; /** * @description * Allows to schedule a work as an observable. Accepts the work and configuration options object. * - work is any function that should be executed * - (optional) options includes strategy, patchZone and scope * * Scope is by default a subscription but you can also pass `this` and then the scope will be current component. * Scope setup is especially useful if you provide work that will trigger a change detection. * * @example * this.strategyProvider.schedule(() => myWork(), {strategy: 'idle', patchZone: false}).subscribe(); * * @return Observable */ schedule(work: () => R, options?: ScheduleOnStrategyOptions): Observable; /** * @description * Allows to schedule a change detection cycle. Accepts the ChangeDetectorRef and configuration options object. * Options include: * - afterCD which is the work that should be executed after change detection cycle. * - abortCtrl is an AbortController that you can use to cancel the scheduled cycle. * * @example * this.strategyProvider.scheduleCD(this.changeDetectorRef, {afterCD: myWork()}); * * @return AbortController */ scheduleCD(cdRef: ChangeDetectorRef, options?: ScheduleOnStrategyOptions & { afterCD?: () => void; abortCtrl?: AbortController; }): AbortController; static ɵfac: i0.ɵɵFactoryDeclaration, [{ optional: true; }]>; static ɵprov: i0.ɵɵInjectableDeclaration>; } export { RX_CONCURRENT_STRATEGIES, RX_NATIVE_STRATEGIES, RX_RENDER_STRATEGIES_CONFIG, RxStrategyProvider, onStrategy, provideRxRenderStrategies, strategyHandling }; export type { RxConcurrentStrategies, RxConcurrentStrategyNames, RxCustomStrategyCredentials, RxDefaultStrategyNames, RxNativeStrategies, RxNativeStrategyNames, RxRenderBehavior, RxRenderStrategiesConfig, RxRenderWork, RxStrategies, RxStrategyCredentials, RxStrategyNames, ScheduleOnStrategyOptions };