import Agile from "../agile"; import Dep from "./dep"; import { StorageKey } from "../storage"; export declare type StateKey = string | number; export interface PersistSettingsInterface { isPersisted: boolean; persistKey?: string | number; } export default class State { agileInstance: () => Agile; _key?: StateKey; valueType?: string; dep: Dep; watchers: { [key: string]: (value: any) => void; }; sideEffects?: Function; isSet: boolean; persistSettings: PersistSettingsInterface; output?: any; isPlaceholder: boolean; initialState: ValueType; _value: ValueType; previousState: ValueType; nextState: ValueType; constructor(agileInstance: Agile, initialState: ValueType, key?: StateKey, deps?: Array); set value(value: ValueType); get value(): ValueType; set key(value: StateKey | undefined); get key(): StateKey | undefined; /** * Directly set state to a new value */ set(value: ValueType, options?: { background?: boolean; sideEffects?: boolean; }): this; /** * @internal * Will ingest the nextState or the computedValue (rebuilds state) */ ingest(options?: { background?: boolean; sideEffects?: boolean; forceRerender?: boolean; }): void; /** * This is thought for js users.. because ts users can set the type in <> * @param type - wished type of the state */ type(type: any): this; /** * Will set the state to the previous State */ undo(): void; /** * Will reset the state to the initial value */ reset(): this; /** * Will merge the changes into the state */ patch(targetWithChanges: object, options?: { addNewProperties?: boolean; background?: boolean; }): this; /** * Will always be called if the state changes * @param key - The key of the watch method * @param callback - The callback function */ watch(key: string, callback: (value: ValueType) => void): this; /** * Removes a watcher called after the key * @param key - the key of the watcher function */ removeWatcher(key: string): this; /** * Saves the state in the local storage or in a own configured storage * @param key - the storage key (if no key passed it will take the state key) */ persist(key?: StorageKey): this; /** * Returns a fresh copy of the current value */ copy(): ValueType; /** * Checks if the State exists */ get exists(): boolean; /** * @internal * Returns 100% the public value of a state because at some points (group) the _value contains only keys */ getPublicValue(): ValueType; /** * @internal * Will set a new _value and handles the stuff around like storage, .. */ privateWrite(value: any): void; /** * @internal * Will return the perstiable Value of this state.. * some classes which extends state might have another peristiableValue than this.value (like the selector) */ getPersistableValue(): any; /** * @internal * Checks if the 'value' has the same type as state.value */ private isCorrectType; }