import { Observable, Subscription, ObservedValueOf } from 'rxjs'; import * as i0 from '@angular/core'; import { OnDestroy, Signal, ValueEqualityFn, InjectionToken, Type, Provider } from '@angular/core'; interface SelectConfig { debounce?: boolean; equal?: ValueEqualityFn; } declare const INITIAL_STATE_TOKEN: InjectionToken; type SelectorResults[]> = { [Key in keyof Selectors]: Selectors[Key] extends Observable ? U : never; }; type Projector[], Result> = (...args: SelectorResults) => Result; type SignalsProjector[], Result> = (...values: { [Key in keyof Signals]: Signals[Key] extends Signal ? Value : never; }) => Result; interface SelectSignalOptions { /** * A comparison function which defines equality for select results. */ equal?: ValueEqualityFn; } declare class ComponentStore implements OnDestroy { private readonly destroySubject$; readonly destroy$: Observable; private readonly stateSubject$; private isInitialized; readonly state$: Observable; readonly state: Signal; private ɵhasProvider; constructor(defaultState?: T); /** Completes all relevant Observable streams. */ ngOnDestroy(): void; /** * Creates an updater. * * Throws an error if updater is called with synchronous values (either * imperative value or Observable that is synchronous) before ComponentStore * is initialized. If called with async Observable before initialization then * state will not be updated and subscription would be closed. * * @param updaterFn A static updater function that takes 2 parameters (the * current state and an argument object) and returns a new instance of the * state. * @return A function that accepts one argument which is forwarded as the * second argument to `updaterFn`. Every time this function is called * subscribers will be notified of the state change. */ updater void : (observableOrValue: ValueType | Observable) => Subscription>(updaterFn: (state: T, value: OriginType) => T): ReturnType; /** * Initializes state. If it was already initialized then it resets the * state. */ private initState; /** * Sets the state specific value. * @param stateOrUpdaterFn object of the same type as the state or an * updaterFn, returning such object. */ setState(stateOrUpdaterFn: T | ((state: T) => T)): void; /** * Patches the state with provided partial state. * * @param partialStateOrUpdaterFn a partial state or a partial updater * function that accepts the state and returns the partial state. * @throws Error if the state is not initialized. */ patchState(partialStateOrUpdaterFn: Partial | Observable> | ((state: T) => Partial)): void; protected get(): T; protected get(projector: (s: T) => R): R; /** * Creates a selector. * * @param projector A pure projection function that takes the current state and * returns some new slice/projection of that state. * @param config SelectConfig that changes the behavior of selector, including * the debouncing of the values until the state is settled. * @return An observable of the projector results. */ select(projector: (s: T) => Result, config?: SelectConfig): Observable; select>>(selectorsObject: SelectorsObject, config?: SelectConfig<{ [K in keyof SelectorsObject]: ObservedValueOf; }>): Observable<{ [K in keyof SelectorsObject]: ObservedValueOf; }>; select[], Result>(...selectorsWithProjector: [ ...selectors: Selectors, projector: Projector ]): Observable; select[], Result>(...selectorsWithProjectorAndConfig: [ ...selectors: Selectors, projector: Projector, config: SelectConfig ]): Observable; /** * Creates a signal from the provided state projector function. */ selectSignal(projector: (state: T) => Result, options?: SelectSignalOptions): Signal; /** * Creates a signal by combining provided signals. */ selectSignal[], Result>(...args: [...signals: Signals, projector: SignalsProjector]): Signal; /** * Creates a signal by combining provided signals. */ selectSignal[], Result>(...args: [ ...signals: Signals, projector: SignalsProjector, options: SelectSignalOptions ]): Signal; /** * Creates an effect. * * This effect is subscribed to throughout the lifecycle of the ComponentStore. * @param generator A function that takes an origin Observable input and * returns an Observable. The Observable that is returned will be * subscribed to for the life of the component. * @return A function that, when called, will trigger the origin Observable. */ effect | unknown = Observable, ObservableType = OriginType extends Observable ? A : never, ReturnType = ProvidedType | ObservableType extends void ? (observableOrValue?: ObservableType | Observable) => Subscription : (observableOrValue: ObservableType | Observable) => Subscription>(generator: (origin$: OriginType) => Observable): ReturnType; /** * Used to check if lifecycle hooks are defined * but not used with provideComponentStore() */ private checkProviderForHooks; private assertStateIsInitialized; static ɵfac: i0.ɵɵFactoryDeclaration, [{ optional: true; }]>; static ɵprov: i0.ɵɵInjectableDeclaration>; } /** * The interface for the lifecycle hook * called after the ComponentStore is instantiated. */ interface OnStoreInit { readonly ngrxOnStoreInit: () => void; } /** * The interface for the lifecycle hook * called only once after the ComponentStore * state is first initialized. */ interface OnStateInit { readonly ngrxOnStateInit: () => void; } /** * @description * * Function that returns the ComponentStore * class registered as a provider, * and uses a factory provider to instantiate the * ComponentStore and run the lifecycle hooks * defined on the ComponentStore. * * @param componentStoreClass The ComponentStore with lifecycle hooks * @returns Provider[] * * @usageNotes * * ```ts * @Injectable() * export class MyStore * extends ComponentStore<{ init: boolean }> * implements OnStoreInit, OnStateInit * { * * constructor() { * super({ init: true }); * } * * ngrxOnStoreInit() { * // runs once after store has been instantiated * } * * ngrxOnStateInit() { * // runs once after store state has been initialized * } * } * * @Component({ * providers: [ * provideComponentStore(MyStore) * ] * }) * export class MyComponent { * constructor(private myStore: MyStore) {} * } * ``` */ declare function provideComponentStore(componentStoreClass: Type>): Provider[]; export { ComponentStore, INITIAL_STATE_TOKEN, provideComponentStore }; export type { OnStateInit, OnStoreInit, Projector, SelectConfig, SelectorResults };