/** * Useable - Base class for reactive data sources that work with use() * * Extend this class to create custom data sources (Context, Stream, Shared, etc.) * * @example * ```tsx * class MySource extends Useable { * getInitial() { return this.initialValue } * subscribe(params, callback) { * // setup subscription * return () => { // cleanup } * } * } * * const source = new MySource(...) * const [value] = use(source) * ``` * * @typeParam T - The value type * @typeParam P - The params type for subscribe/send * @typeParam Actions - Tuple of additional actions returned by use() after the value */ declare abstract class Useable { /** * Unique identifier for this Useable type * Used internally by use() for type checking */ readonly _useableTag: true; /** * Get the initial/current value synchronously * Called when use() first accesses this source */ abstract getInitial(params?: P): T; /** * Subscribe to value changes * Called by use() to receive updates * * @param params - Optional parameters for the subscription * @param callback - Function called when value changes * @returns Cleanup function to unsubscribe */ abstract subscribe(params: P | undefined, callback: (value: T) => void): () => void; /** * Get additional actions to include in the use() tuple * Override this to return [action1, action2, ...] that will be appended to [value, ...] * * @example * ```tsx * class SendableStream extends Useable { * getActions() { * return [this.send.bind(this)] * } * } * * const [value, send] = use(stream) * ``` */ getActions(): Actions | undefined; } /** * Type guard to check if a value is a Useable instance */ declare function isUseable(value: unknown): value is Useable; declare function resetContext(): void; /** * Context for passing data through the component tree * * @example * ```tsx * const ThemeContext = new Context('light') * * function App() { * return ( * * * * ) * } * * function Child() { * const [theme] = use(ThemeContext) * return
{theme}
* } * ``` */ declare class Context extends Useable { readonly id: symbol; readonly defaultValue: T; readonly Provider: (props: { value: T; children: unknown; }) => unknown; constructor(defaultValue: T); /** * Get current context value or default */ getInitial(): T; /** * Context doesn't have traditional subscriptions * Reactivity is handled by component re-rendering */ subscribe(_params: undefined, _callback: (value: T) => void): () => void; } declare function getContextValue(ctx: Context): T; declare function pushContext(id: symbol, value: unknown): unknown; declare function popContext(id: symbol, prevValue: unknown): void; type Setter = (newValue: T | ((prev: T) => T)) => void; type ResourceControl

= { refetch: (params?: P) => Promise; readonly loading: boolean; readonly error: unknown; readonly status: 'idle' | 'loading' | 'success' | 'error'; }; interface UseContext

{ onCleanup: (fn: () => void) => void; params?: P; } interface UseOptions { key?: unknown[]; name?: string; } declare function releaseGlobalKeyImpl(key: string): void; /** * Force-evict a globally-keyed signal from the registry. * * Normally registry entries are reference-counted: each component reading a global * key increments refCount on mount and decrements on unmount. The entry is auto-evicted * when refCount reaches 0. * * Use this only when you need to explicitly clear cached state (e.g., invalidating a * cache, logout flow). Active subscribers will be left with a dangling reference if * you force-evict — call this only when you're sure nothing reads the key anymore. * * @example * releaseGlobalKey(JSON.stringify(['user', userId])) */ declare const releaseGlobalKey: typeof releaseGlobalKeyImpl; /** * Consume a Context value provided by an ancestor Provider. * * @example * const [theme] = use(ThemeContext); * * @param ctx - The Context object created with `createContext` * @returns Tuple of [contextValue, undefined] */ declare function use(ctx: Context): [T, undefined]; /** * Subscribe to a Useable data source (Stream, Shared, or any custom Useable). * * @example * const [messages, send] = use(chatStream, { roomId }); * * @param source - A Useable object (e.g. Stream, Shared) * @param params - Optional parameters forwarded to the Useable's subscribe call * @returns Tuple of [currentValue, ...actions] where actions come from the Useable */ declare function use(source: Useable, params?: P): [T, ...A]; /** * Create an async resource that fetches data and tracks loading/error state. * * @example * const [user, ctrl] = use(async () => fetchUser(id)); * if (ctrl.loading) return html``; * ctrl.refetch(); * * @param fn - Async function (optionally using `ctx.onCleanup`) that returns a Promise * @param depsOrOptions - Dependency array or UseOptions (key, name) * @param options - UseOptions when `depsOrOptions` is a deps array * @returns Tuple of [resolvedValue | undefined, ResourceControl] */ declare function use(fn: (ctx: UseContext

) => Promise, depsOrOptions?: unknown[] | UseOptions, options?: UseOptions): [T | undefined, ResourceControl

]; /** * Create a computed (derived) value that re-runs when its deps change. * * @example * const [doubled, ctrl] = use((ctx) => count() * 2, [count]); * * @param fn - Sync computation function; receives a UseContext for cleanup registration * @param depsOrOptions - Dependency array that controls when `fn` re-runs, or UseOptions * @param options - UseOptions when `depsOrOptions` is a deps array * @returns Tuple of [computedValue, ResourceControl] */ declare function use(fn: (ctx: UseContext) => T, depsOrOptions?: unknown[] | UseOptions, options?: UseOptions): [T, ResourceControl]; /** * Create a local reactive signal with an initial value. * * @example * const [count, setCount] = use(0); * setCount(c => c + 1); * * @param initialValue - Initial value of the signal (must not be a function) * @param options - Optional UseOptions (key for global registry, name for DevTools) * @returns Tuple of [currentValue, setter] */ declare function use(initialValue: T extends (...args: unknown[]) => unknown ? never : T, options?: UseOptions): [T, Setter]; export { Context as C, type ResourceControl as R, type Setter as S, type UseContext as U, type UseOptions as a, Useable as b, popContext as c, resetContext as d, getContextValue as g, isUseable as i, pushContext as p, releaseGlobalKey as r, use as u };