@uplink-protocol/form-controller
Version:
Reactive multi-step form controller with dynamic validation and state management
38 lines (37 loc) • 1.15 kB
TypeScript
/**
* Base class for reactive services.
* Provides common state management and subscription functionality for all derived services.
*
* @typeParam T - The type of data managed by this service
*/
export declare class BaseService<T> {
/** The current value of the service state */
protected current: T;
/** Array of callback functions subscribed to state changes */
protected _callbacks: ((value: T) => void)[];
/**
* Creates a new BaseService instance
*
* @param initialValue - The initial state value
*/
constructor(initialValue: T);
/**
* Subscribe to changes in the service value.
* Callback is immediately invoked with the current value.
*
* @param callback - Function to be called when value changes
* @returns An unsubscribe function that removes this subscription
*/
subscribe(callback: (value: T) => void): () => void;
/**
* Update the service value and notify all subscribers.
*
* @param value - New value to set
*/
set(value: T): void;
/**
* Get the current value
* @returns Current value
*/
get(): T;
}