nexora
Version:
A lightweight, production-ready JavaScript library for building user interfaces, supporting JSX.
45 lines (44 loc) • 1.68 kB
TypeScript
/**
* ## Reactive State ##
* @description
* - This class is used to manage the state and reactivity of the components.
*/
declare class ReactiveState {
stateIndexes: WeakMap<Function, number>;
currentComponentFn: Function | null;
private rootElement;
private states;
/**
* Creates a state for the given component.
* @param initialValue - The initial value of the state.
* @returns A tuple containing the getter and setter for the state.
*/
createState<T>(initialValue: T): [() => T, (newValue: T | ((prev: T) => T)) => void];
/**
* Checks if the given component function has state.
* @param componentFn - The component function to check.
* @returns True if the component function has state, false otherwise.
*/
hasState(componentFn: Function): boolean;
/**
* Triggers an update for the given component function.
* @param componentFn - The component function to trigger an update for.
*/
triggerUpdate(componentFn: Function): void;
/**
* Finds the element by the given component function.
* @param root - The root element to search within.
* @param componentFn - The component function to search for.
* @returns The element that matches the component function.
*/
private findElementByComponent;
/**
* Renders the given component function.
* @param ComponentFn - The component function to render.
* @returns The VNode of the component.
*/
private render;
}
export declare const reactive: ReactiveState;
export declare function createState<T>(initialValue: T): [() => T, (newValue: T | ((prev: T) => T)) => void];
export {};