import { BehaviorSubject, Observable, Subscription } from 'rxjs'; import { StoreDevToolsApi } from '../dev-tools'; import { ObjectCompareTypes, Storages, StoreConfigCompleteInfo, StoreConfigOptions } from './config'; import { Actions, Clone, CloneError, Compare, DestroyableStore, Freeze, HandleClasses, InitializableStore, LazyInitContext, Merge, Parse, PromiseContext, QueryContext, QueryContextsList, State, StoreTags, Stringify } from './store-accessories'; export declare abstract class BaseStore implements DestroyableStore, InitializableStore { /** @internal */ protected static _storageKeys: string[]; /** @internal */ protected static _storeNames: string[]; /** @internal */ protected _stateSource: State; /** @internal */ protected get _state(): State; protected set _state(value: State); /** @internal */ protected readonly _state$: BehaviorSubject>; readonly state$: Observable>; /** * @get Returns the state. */ get state(): State; /** @internal */ protected get _value(): Readonly | null; /** @internal */ protected readonly _value$: BehaviorSubject | null>; /** * @get Returns state's value. */ get rawValue(): T | null; /** * @get Returns state's value. * - Will throw if state's value is null. */ get value(): T | never; /** @internal */ protected readonly _isLoading$: BehaviorSubject; /** * Store's loading state observable. */ readonly isLoading$: Observable; /** * @get Returns whether ot not the store is in loading state. */ get isLoading(): boolean; /** @internal */ protected readonly _isPaused$: BehaviorSubject; isPaused$: Observable; /** * @get Returns whether ot not the store is in paused state. */ get isPaused(): boolean; set isPaused(value: boolean); /** * @get Returns string literal that represents the store's tag. */ get storeTag(): StoreTags; /** @internal */ protected _initialValue: Readonly | null; /** * @get Returns the instanced value. */ get initialValue(): Readonly | null; /** @internal */ protected _instancedValue: Readonly | null; /** * @get Returns the instanced value. */ get instancedValue(): Readonly | null; /** @internal */ protected _isDestroyed: boolean; /** * @get Returns whether or not the store is destroyed. */ get isDestroyed(): boolean; /** * @get Returns whether or not the store is initialized. */ get isInitialized(): boolean; /** @internal */ protected readonly _error$: BehaviorSubject; /** * Store's error state. */ readonly error$: Observable; /** * @get Returns the store's error state value. * @set Sets store's error state and also sets global error state if the value is not null. */ get error(): E | null; set error(value: E | null); /** @internal */ protected readonly _config: StoreConfigCompleteInfo; /** * @get Returns store's configuration. */ get config(): StoreConfigCompleteInfo; /** @internal */ protected readonly _storeName: string; /** @internal */ protected readonly _isResettable: boolean; /** @internal */ protected readonly _isSimpleCloning: boolean; /** @internal */ protected readonly _isClassHandler: boolean; /** @internal */ protected readonly _objectCompareType: ObjectCompareTypes; /** @internal */ protected readonly _storage: Storage | null; /** @internal */ protected readonly _storageDebounce: number; /** @internal */ protected readonly _storageKey: string; /** @internal */ protected readonly _clone: Clone; /** @internal */ protected readonly _compare: Compare; /** @internal */ protected readonly _freeze: Freeze; /** @internal */ protected readonly _handleClasses: HandleClasses; /** @internal */ protected readonly _stringify: Stringify; /** @internal */ protected readonly _parse: Parse; /** @internal */ protected readonly _cloneError: CloneError; /** @internal */ protected readonly _merge: Merge; /** @internal */ protected readonly _queryContextsList: Array & QueryContextsList; /** @internal */ protected _valueToStorageSub: Subscription | null; /** @internal */ protected _asyncInitPromiseContext: PromiseContext | null; /** @internal */ protected _lastAction: string | null; /** @internal */ protected _lazyInitContext: LazyInitContext | null; /** @internal */ protected get _devToolsApi(): StoreDevToolsApi; constructor(initialValueOrNull: T | null, storeConfig?: StoreConfigOptions); /** @virtual */ protected _noClone(value: V): V; /** @virtual */ protected _noFreeze(value: V): Readonly; /** @virtual */ protected _refCompare(objA: object | any[], objB: object | any[]): boolean; /** @internal */ protected _resolveObjectCompareType(objectCompareType: ObjectCompareTypes): Compare; /** @internal */ protected _resolveStorageType(storageType: Storages, customStorageApi: Storage | null): Storage | null; /** @internal */ protected _assertStoreNameValid(storeName: string): void; /** @internal */ protected _assertStorageKeyValid(storageKey: string, storeName: string): void; /** @internal */ protected _assertInitializable(reject?: (reason: any) => void): boolean | never; /** * Setts an instanced value to be used by the instanced handler for resolving types * if "isClassHandler" is set to true at the store's configurations. * - If an instanced value was not set by this method, the initial value will be used for resolving types. */ setInstancedValue(value: S): void; /** * Disposes the observable by completing the observable and removing it from query context list. */ disposeQueryContext(observable: Observable): boolean; /** @internal */ protected _initializeStore(initialValue: T, isAsync: boolean): void; /** @internal */ protected _initializeLazily(): void; /** * Method used for delayed initialization. */ initialize(initialValue: T): void; /** * Method for asynchronous initialization. * - In case of an observable, only the finite value will be used. */ initializeAsync(promise: Promise): Promise; initializeAsync(observable: Observable): Promise; initializeAsync(promiseOrObservable: Promise | Observable): Promise; /** * Method for lazy initialization. * - will initialize the store only after the first queryable request is made. * - In case of an observable, only the finite value will be used. */ initializeLazily(promise: Promise): Promise; initializeLazily(observable: Observable): Promise; initializeLazily(promiseOrObservable: Promise | Observable): Promise; /** @internal */ protected _setState(valueFnOrState: ((stateValue: Readonly) => T) | Partial>, actionName: string | Actions, stateExtension?: Partial, 'value'>>): void; /** * Resets the state's value to it's initial value. */ reset(actionName?: string): void | never; /** * Sets the following: * - State's value will be set to `null`. * - State's error will be set to `null`. * - Store's initial value will be set to `null`. * - Sets _isPaused_ to `false`. * - Sets the store into loading state. * - Clears store's cache storage if any (LocalStorage, SessionStorage, etc.). */ hardReset(): Promise; /** * There is no reason to use this method other then debugging. * This method will do everything that hard and also: * - Remove the store from DevTools. * - Complete all source observables. * - Dispose all query contexts. */ destroy(): Promise; protected _partialHardReset(action: Actions, isLoading?: boolean): void; protected _hardResetOrDestroy(executor: () => void): Promise; /** * @virtual Override to use `onBeforeInit` hook. * - Will be called before the store has completed the initialization. * - Allows state's value modification before the initialization is complete. */ protected onBeforeInit?(nextState: T): void | T; /** * @virtual Override to use `onAfterInit` hook. * - Will be called once the store has completed initialization. * - Allows state's value modification after initialization. */ protected onAfterInit?(currState: T): void | T; /** * @virtual Override to use `onAsyncInitError` hook. * - Will be called if there is an error during async initialization. * - Allows error manipulation. * - If the method returns an error, it will bubble via promise rejection. * - If method returns void, the error will will not bubble further. */ protected onAsyncInitError?(error: E): void | E; /** * @virtual Override to use `onAsyncInitSuccess` hook. * - Will be called once data is received during async initialization. * - Allows data manipulations like mapping and etc. */ protected onAsyncInitSuccess?(result: T): void | T; /** * @virtual Override to use `onUpdate` hook. * - Will be called after the update method has merged the changes with the given state and just before this state is set. * - Allows future state modification. */ protected onUpdate?(nextState: T, currState: Readonly): void | T; /** * @virtual Override to use `onOverride` hook. * - Will be called after the override method and just before the new state is set. * - Allows future state modification. */ protected onOverride?(nextState: T, prevState: Readonly): void | T; /** * @virtual Override to use `onReset` hook. * - Will be called after the reset method and just before the new state is set. * - Allows future state modification. */ protected onReset?(nextState: T, currState: Readonly): void | T; }