@broxus/js-core
Version:
MobX-based JavaScript Core library
49 lines (48 loc) • 1.89 kB
TypeScript
import { type CreateObservableOptions } from 'mobx';
import { type ObjectLiteral } from './types';
export declare abstract class AbstractStore<T extends ObjectLiteral = ObjectLiteral, U extends ObjectLiteral = ObjectLiteral> {
/**
* Store data (e.g. user data, account data, form data etc.)
* @protected
*/
protected _data: T;
/**
* Store state (e.g. interface states, notations, errors etc.)
* @protected
*/
protected _state: U;
protected constructor(options?: CreateObservableOptions);
/**
* Set partial data with `key:value` hash or pass a function as
* an argument that takes the argument of the current data object.
* @template {object} T
* @template {keyof T & string} K
* @param {Pick<T, K> | ((prevData: Readonly<T>) => Pick<T, K>)} dataOrFn
*/
setData<K extends keyof T & string>(dataOrFn: Pick<T, K> | ((prevData: Readonly<T>) => (T | Pick<T, K>))): this;
/**
* Set data by the given key and value.
* @template {object} T
* @template {keyof T & string} K
* @param {K} key
* @param {T[K]} value
*/
setData<K extends keyof T & string>(key: K, value: T[K]): this;
/**
* Set partial state with `key:value` hash or pass a function as
* an argument that takes the argument of the current state object.
* @template {object} U
* @template {keyof U & string} K
* @param {Pick<U, K> | ((prevState: Readonly<U>) => Pick<U, K>)} stateOrFn
*/
setState<K extends keyof U & string>(stateOrFn: Pick<U, K> | ((prevState: Readonly<U>) => (U | Pick<U, K>))): this;
/**
* Set state by the given key and value.
* @template {object} U
* @template {keyof U & string} K
* @param {K} key
* @param {U[K]} [value]
*/
setState<K extends keyof U & string>(key: K, value?: U[K]): this;
toJSON(): T;
}