import { Observable } from 'rxjs'; import { BaseStore } from './base-store'; import { StoreConfigOptions } from './config'; import { Actions, ProjectsOrKeys, QueryableStore, WriteableStore } from './store-accessories'; /** * @example * const createWeatherState: WeatherState = () => { * return { * isRaining: true, * isSunny: false, * precipitation: { * mm: 7 * } * } * } * * `@`StoreConfig({ // <= decorator * name: 'WEATHER-STORE' * }) * export class WeatherStore extends Store { * * constructor() { * super(createWeatherState()) * } * } */ export declare class Store extends BaseStore implements QueryableStore, WriteableStore { protected readonly _whenLoaded$: Observable | null>; /** * Synchronous initialization. */ constructor(initialValue: T, storeConfig?: StoreConfigOptions); /** * Asynchronous or delayed initialization. * The store will be set into loading state till initialization. */ constructor(initialValue: null, storeConfig?: StoreConfigOptions); /** * Dynamic initialization. */ constructor(initialValue: T | null, storeConfig?: StoreConfigOptions); protected _select$(projectsOrKeys?: ProjectsOrKeys, action?: Actions | string): Observable>; protected _update(valueOrFunction: ((value: Readonly) => Partial) | Partial | T, isMerge: boolean, actionName: string, onUpdate?: (nextState: T, prevState: Readonly) => void | T): void; /** * Returns the state's value as an Observable. * @example * weatherStore.select$().subscribe(value => { * // do something with the weather... * }); */ select$(): Observable; /** * Returns the extracted partial state's value as an Observable based on the provided projection method. * @example * weatherStore.select$(value => value.isRaining) * .subscribe(isRaining => { * if (isRaining) { * // do something when it's raining... * } * }); */ select$(project: (value: Readonly) => R): Observable; /** * Returns an array values as an Observable based on the provided projections methods. * @example * weatherStore.select$([value => value.isRaining, value => value.precipitation]) * .subscribe(result => { * const [isRaining, precipitation] = result * // do something... * }); */ select$, M extends ((value: Readonly) => any)>(projects: M[]): Observable; /** * Returns an array values as an Observable based on the provided projections methods. * - This overload allows to manually define the return type. * @example * weatherStore.select$([value => value.isRaining, value => value.precipitation]) * .subscribe(result => { * const [isRaining, precipitation] = result * // do something... * }); */ select$(projects: ((value: Readonly) => any)[]): Observable; /** * Returns as single the state's value property based on the provided key. * @example * weatherStore.select$('precipitation') * .subscribe(precipitation => { * // do something... * }); */ select$(key: K): Observable; /** * Returns the extracted partial state's value as an Observable based on the provided keys. * @example * weatherStore.select$(['precipitation', 'isRaining']) * .subscribe(result => { * if (result.isRaining && result.precipitation.mm > 10) { * // do something... * } * }); */ select$(keys: K[]): Observable>; /** * This is an dynamic overload. Use this approach only id necessary because it's not strongly typed. * @example * function selectFactory(dynamic?) { * return weatherStore.select$(dynamic?); * } */ select$(dynamic?: ProjectsOrKeys): Observable; onAction(action: Actions | string): Pick, 'select$'>; /** * Updates the store's state using a partial state. The provided partial state will be then merged with current store's state. * - If you want to override the current store's state, use the `override` method. * @example * weatherStore.update({ isWindy: true }); */ update(value: Partial, actionName?: string): void; /** * Updates the store's state using a function that will be called by the store. * The function will be provided with the current state as a parameter and it must return a new partial state. * The returned partial state will be then merged with current store's state. * - If you want to override the current store's state, use the `override` method. * @example * weatherStore.update(state => ({ * isSunny: !state.isRaining * })); */ update(valueFunction: (value: Readonly) => Partial, actionName?: string): void; /** * Overrides the current state's value completely. */ override(newValue: T, actionName?: string): void; }