import { Observable } from 'rxjs'; declare interface BaseStoreSettings { /** * Determines if the store's state will be tracked or not (defaults to `false`). * Pass it when initializing the Observable Store. * When `true`, you can access the store's state history by calling the `stateHistory` property. */ trackStateHistory?: boolean; /** * Log any store state changes to the browser console (defaults to `false`). */ logStateChanges?: boolean; } /** * Core functionality for ObservableStore * providing getState(), setState() and additional functionality */ export declare class ObservableStore { private readonly _settings; private readonly _stateDispatcher$; private readonly _stateWithChangesDispatcher$; /** * Subscribe to store changes in the particular slice of state updated by a Service. * If the store contains 'n' slices of state each being managed by one of 'n' services, then changes in any * of the other slices of state will not generate values in the `stateChanged` stream. * Returns an RxJS Observable containing the current store state (or a specific slice of state if a `stateSliceSelector` has been specified). */ readonly stateChanged: Observable; /** * Subscribe to store changes in the particular slice of state updated by a Service and also include the properties that changed as well. * Upon subscribing to `stateWithPropertyChanges` you will get back an object containing state (which has the current slice of store state) * and `stateChanges` (which has the individual properties/data that were changed in the store). */ readonly stateWithPropertyChanges: Observable>; /** * Subscribe to global store changes i.e. changes in any slice of state of the store. The global store may consist of 'n' * slices of state each managed by a particular service. This property notifies of a change in any of the 'n' slices of state. * Returns an RxJS Observable containing the current store state. */ readonly globalStateChanged: Observable; /** * Subscribe to global store changes i.e. changes in any slice of state of the store and also include the properties that changed as well. * The global store may consist of 'n' slices of state each managed by a particular service. * This property notifies of a change in any of the 'n' slices of state. Upon subscribing to `globalStateWithPropertyChanges` you will get * back an object containing state (which has the current store state) and `stateChanges` * (which has the individual properties/data that were changed in the store). */ readonly globalStateWithPropertyChanges: Observable>; /** * Retrieve state history. Assumes trackStateHistory setting was set on the store. */ get stateHistory(): StateHistory[]; constructor(settings: ObservableStoreSettings); /** * get/set global settings throughout the application for ObservableStore. * See the [Observable Store Settings](https://github.com/danwahlin/observable-store#store-settings-per-service) documentation * for additional information. Note that global settings can only be set once as the application first loads. */ static get globalSettings(): ObservableStoreGlobalSettings | null; static set globalSettings(settings: ObservableStoreGlobalSettings); /** * Provides access to all services that interact with ObservableStore. Useful for extensions * that need to be able to access a specific service. */ static get allStoreServices(): unknown[]; /** * Used to add an extension into ObservableStore. The extension must implement the * `ObservableStoreExtension` interface. */ static addExtension(extension: ObservableStoreExtension): void; /** * Used to initialize the store's starting state. An error will be thrown if this is called and store state already exists. * No notifications are sent out when the store state is initialized by calling initializeStoreState(). */ static initializeState(state: Record): void; /** * Used to reset the state of the store to a desired value for all services that derive * from ObservableStore to a desired value. * A state change notification and global state change notification is sent out to subscribers if the dispatchState parameter is true (the default value). */ static resetState(state: Record, dispatchState?: boolean): void; /** * Clear/null the store state for all services that use it. */ static clearState(dispatchState?: boolean): void; /** * Determines if the ObservableStore has already been initialized through the use of ObservableStore.initializeState() */ static get isStoreInitialized(): boolean; private static dispatchToAllServices; /** * Retrieve store's state. If using TypeScript (optional) then the state type defined when the store * was created will be returned rather than `any`. The deepCloneReturnedState boolean parameter (default is true) can be used * to determine if the returned state will be deep cloned or not. If set to false, a reference to the store state will * be returned and it's up to the user to ensure the state isn't change from outside the store. Setting it to false can be * useful in cases where read-only cached data is stored and must be retrieved as quickly as possible without any cloning. */ protected getState(deepCloneReturnedState?: boolean): T; /** * Retrieve a specific property from the store's state which can be more efficient than getState() * since only the defined property value will be returned (and cloned) rather than the entire * store value. If using TypeScript (optional) then the generic property type used with the * function call will be the return type. */ protected getStateProperty(propertyName: string, deepCloneReturnedState?: boolean): TProp; /** * Retrieve a specific property from the store's state which can be more efficient than getState() * since only the defined property value will be returned (and cloned) rather than the entire * store value. If using TypeScript (optional) then the generic property type used with the * function call will be the return type. * If a `stateSliceSelector` has been set, the specific slice will be searched first. */ protected getStateSliceProperty(propertyName: string, deepCloneReturnedState?: boolean): TProp | null; /** * Set store state. Pass the state to be updated as well as the action that is occurring. * The state value can be a function [(see example)](https://github.com/danwahlin/observable-store#store-api). * The latest store state is returned. * The dispatchState parameter can be set to false if you do not want to send state change notifications to subscribers. * The deepCloneReturnedState boolean parameter (default is true) can be used * to determine if the state will be deep cloned before it is added to the store. Setting it to false can be * useful in cases where read-only cached data is stored and must added to the store as quickly as possible without any cloning. */ protected setState(state: Partial | stateFunc, action?: string, dispatchState?: boolean, deepCloneState?: boolean): T; /** * Add a custom state value and action into the state history. Assumes `trackStateHistory` setting was set * on store or using the global settings. */ protected logStateAction(state: unknown, action: string): void; /** * Reset the store's state history to an empty array. */ protected resetStateHistory(): void; private _updateState; private _getStateOrSlice; /** * Dispatch the store's state without modifying the store state. Service state can be dispatched as well as the global store state. * If `dispatchGlobalState` is false then global state will not be dispatched to subscribers (defaults to `true`). */ protected dispatchState(stateChanges: Partial, dispatchGlobalState?: boolean): void; /** * Unregister this service from the global store and complete its state dispatchers. * Call this when a service is destroyed (e.g., in Angular's ngOnDestroy) to prevent memory leaks. */ destroy(): void; } export declare interface ObservableStoreExtension { /** Function used to initialize the extension. */ init(): void; } export declare interface ObservableStoreGlobalSettings extends BaseStoreSettings { /** * Not currently used. Reserved for future use. */ isProduction?: boolean; } export declare interface ObservableStoreSettings extends BaseStoreSettings, StateSliceSelector { } /** * Executes a function on `state` and returns a version of T * @param state - the original state model */ export declare type stateFunc = (state: T) => Partial; export declare interface StateHistory { action: string; beginState: T; endState: T; } export declare interface StateSliceSelector { /** * Function to select the slice of the store being managed by this particular service. * If specified then the specific state slice is returned. * If not specified then the total state is returned (defaults to `null`). */ stateSliceSelector?: (state: T) => Partial; } export declare interface StateWithPropertyChanges { state: T; stateChanges: Partial; } export { }