@jay-js/system
Version:
A powerful and flexible TypeScript library for UI, state management, lazy loading, routing and managing draggable elements in modern web applications.
52 lines (51 loc) • 2.37 kB
TypeScript
import type { TState } from "../types.js";
export declare const REACTIVE_MARKER: unique symbol;
export declare const SETVALUE_MARKER: unique symbol;
export declare const SETCHILD_MARKER: unique symbol;
export declare const DERIVED_MARKER: unique symbol;
/**
* Creates a derived state that automatically recalculates whenever states
* accessed within the function change
*
* @template T Type of derived value
* @param fn Function that calculates the derived value
* @returns A state that updates when any dependency changes
*/
export declare function derived<T>(fn: () => T): TState<T>;
/**
* Executes a function and automatically monitors any state access
* to create a reactive effect. The function will be executed again when
* any accessed state changes.
*
* @param fn Function to be executed as an effect
*/
export declare function effect(fn: () => void): void;
/**
* Creates a helper for setting values in objects reactively.
* When a state is accessed within the function, a subscription is automatically
* created to update the value when the state changes.
*
* @param fn Function that returns the value to be set
* @param element Optional HTMLElement to track subscriptions for automatic cleanup
* @returns Function for setting values in objects
*/
export declare function values(fn: () => any, element?: HTMLElement): (object: any, ...path: string[]) => void;
/**
* Creates a reactive effect for updating children of a DOM node.
* Automatically monitors state changes and triggers child updates.
*
* @param fn Function that generates the child elements
* @param nodeRefId Reference identifier for the target node
* @param setChild Callback function to execute when children need to be updated
* @param element Optional HTMLElement to track subscriptions for automatic cleanup
*/
export declare function childs(fn: any, nodeRefId: string, setChild: () => void, element?: HTMLElement): any;
/**
* Generates a unique hash identifier for a function.
* Takes into account special markers (SETVALUE_MARKER, SETCHILD_MARKER) to create
* unique identifiers for reactive functions with additional metadata.
*
* @param fn Function to generate hash for
* @returns Hexadecimal hash string with optional suffix based on function markers
*/
export declare function generateFunctionHash(fn: (...args: never) => unknown, path?: string): string;