rynex
Version:
A minimalist TypeScript framework for building reactive web applications with no virtual DOM
62 lines • 1.76 kB
TypeScript
/**
* Rynex Context & State Management Utilities
* Provides context API similar to React's Context and global store management
*/
/**
* Create a context
* Returns a unique key for the context
*/
export declare function createContext<T>(defaultValue?: T): {
key: symbol;
Provider: (props: {
value: T;
children: HTMLElement;
}) => HTMLElement;
defaultValue?: T;
};
/**
* Use context value
* Retrieves the nearest context value from the context stack
*/
export declare function useContext<T>(context: {
key: symbol;
defaultValue?: T;
}): T;
/**
* Provider component - wraps children with context value
* This is a generic provider that can be used with any context
*/
export declare function provider<T>(contextKey: symbol, value: T, children: HTMLElement): HTMLElement;
/**
* Create a global store
* Returns a reactive store with actions
*/
export declare function createStore<T extends object, A extends Record<string, Function>>(name: string, initialState: T, actions?: (state: T) => A): {
state: T;
actions: A;
subscribe: (listener: () => void) => () => void;
getState: () => T;
};
/**
* Use store hook
* Retrieves a store by name and optionally subscribes to updates
*/
export declare function useStore<T extends object, A extends Record<string, Function>>(name: string): {
state: T;
actions: A;
subscribe: (listener: () => void) => () => void;
getState: () => T;
} | null;
/**
* Get all registered stores
*/
export declare function getStores(): string[];
/**
* Remove a store from registry
*/
export declare function removeStore(name: string): boolean;
/**
* Clear all stores
*/
export declare function clearStores(): void;
//# sourceMappingURL=context.d.ts.map