import type { Agile } from '../agile'; import { StateIngestConfigInterface, StateObserver } from './state.observer'; import { Observer } from '../runtime'; export declare class State { agileInstance: () => Agile; _key?: StateKey; isSet: boolean; isPlaceholder: boolean; initialStateValue: ValueType; _value: ValueType; previousStateValue: ValueType; nextStateValue: ValueType; observers: StateObserversInterface; sideEffects: { [key: string]: SideEffectInterface>; }; /** * A State manages a piece of Information * that we need to remember globally at a later point in time. * While providing a toolkit to use and mutate this piece of Information. * * You can create as many global States as you need. * * [Learn more..](https://agile-ts.org/docs/core/state/) * * @public * @param agileInstance - Instance of Agile the State belongs to. * @param initialValue - Initial value of the State. * @param config - Configuration object */ constructor(agileInstance: Agile, initialValue: ValueType, config?: StateConfigInterface); /** * Assigns a new value to the State * and re-renders all subscribed Components. * * [Learn more..](https://agile-ts.org/docs/core/state/properties#value) * * @public * @param value - New State value. */ set value(value: ValueType); /** * Returns a reference-free version of the current State value. * * [Learn more..](https://agile-ts.org/docs/core/state/properties#value) * * @public */ get value(): ValueType; /** * Updates the key/name identifier of the State. * * [Learn more..](https://agile-ts.org/docs/core/state/properties#key) * * @public * @param value - New key/name identifier. */ set key(value: StateKey | undefined); /** * Returns the key/name identifier of the State. * * [Learn more..](https://agile-ts.org/docs/core/state/properties#key) * * @public */ get key(): StateKey | undefined; /** * Updates the key/name identifier of the State. * * [Learn more..](https://agile-ts.org/docs/core/state/methods/#setkey) * * @public * @param value - New key/name identifier. */ setKey(value: StateKey | undefined): this; /** * Assigns a new value to the State * and re-renders all subscribed UI-Components. * * [Learn more..](https://agile-ts.org/docs/core/state/methods/#set) * * @public * @param value - New State value * @param config - Configuration object */ set(value: ValueType | ((value: ValueType) => ValueType), config?: StateIngestConfigInterface): this; /** * Ingests the State without any specified new value into the runtime. * * Since no new value was defined either the new State value is computed * based on a compute method (Computed Class) * or the `nextStateValue` is taken as the next State value. * * [Learn more..](https://agile-ts.org/docs/core/state/methods/#ingest) * * @internal * @param config - Configuration object */ ingest(config?: StateIngestConfigInterface): this; /** * * Registers a `callback` function that is executed in the `runtime` * as a side effect of State changes. * * For example, it is called when the State value changes from 'jeff' to 'hans'. * * A typical side effect of a State change * could be the updating of the external Storage value. * * @internal * @param key - Key/Name identifier of the to register side effect. * @param callback - Callback function to be fired on each State value change. * @param config - Configuration object */ addSideEffect>(key: string, callback: SideEffectFunctionType, config?: AddSideEffectConfigInterface): this; /** * Removes a side effect callback with the specified key/name identifier from the State. * * [Learn more..](https://agile-ts.org/docs/core/state/methods/#removesideeffect) * * @internal * @param key - Key/Name identifier of the side effect callback to be removed. */ removeSideEffect(key: string): this; /** * Returns a boolean indicating whether a side effect callback with the specified `key` * exists in the State or not. * * [Learn more..](https://agile-ts.org/docs/core/state/methods/#hassideeffect) * * @internal * @param key - Key/Name identifier of the side effect callback to be checked for existence. */ hasSideEffect(key: string): boolean; } export declare type StateKey = string | number; export interface StateObserversInterface { /** * Observer responsible for the value of the State. */ value: StateObserver; } export interface StateConfigInterface { /** * Key/Name identifier of the State. * @default undefined */ key?: StateKey; /** * Observers that depend on the State. * @default [] */ dependents?: Array; /** * Whether the State should be a placeholder * and therefore should only exist in the background. * @default false */ isPlaceholder?: boolean; } export declare type SideEffectFunctionType = (instance: Instance, properties?: { [key: string]: any; }) => void; export interface SideEffectInterface { /** * Callback function to be called on every State value change. * @return () => {} */ callback: SideEffectFunctionType; /** * Weight of the side effect. * The weight determines the order of execution of the registered side effects. * The higher the weight, the earlier it is executed. */ weight: number; } export interface AddSideEffectConfigInterface { /** * Weight of the side effect. * The weight determines the order of execution of the registered side effects. * The higher the weight, the earlier it is executed. */ weight?: number; }