rvx
Version:
A signal based rendering library
60 lines (59 loc) • 1.92 kB
TypeScript
import type { Context } from "../context.js";
import type { TeardownHook } from "../lifecycle.js";
/**
* Represents a stack frame that teardown hooks can be pushed into.
*
* Note that this may be an array.
*/
export interface TeardownFrame {
push(hook: TeardownHook): void;
}
/**
* A function that is called by a signal or batch when updated.
*/
export interface NotifyHook {
(): void;
}
/**
* A function that is called by a signal when accessed.
*/
export interface AccessHook {
/**
* @param hooks See `Signal.#hooks`.
*/
(hooks: Set<NotifyHook>): void;
}
export declare const LEAK: TeardownFrame;
/**
* A stack where the last item may be an object which teardown hooks are captured in.
*
* `undefined` indicates that hooks are intentionally not captured.
*/
export declare const TEARDOWN_STACK: (TeardownFrame | undefined)[];
/**
* A stack where the top value controls if signal accesses are currently tracked.
*/
export declare const TRACKING_STACK: boolean[];
/**
* A stack where the top value is called for each tracked signal access.
*/
export declare const ACCESS_STACK: (AccessHook | undefined)[];
/**
* Stack of context windows.
*
* Each context window is a stack of contexts where a value was provided during that window.
*/
export declare const CONTEXT_WINDOWS: Context<unknown>[][];
/**
* Internal utility to call a function with a specific stack frame.
*/
export declare function useStack<T, R>(stack: T[], frame: T, fn: () => R): R;
export type LeakHook = (hook: TeardownHook) => void;
/**
* Register a hook to be called when any teardown hooks are registered outside of any capture calls.
*
* Errors thrown from the leak hook will be thrown by the **teardown** calls.
*/
export declare function onLeak(hook: LeakHook): void;
export declare function getLeakHook(): LeakHook | undefined;
export declare function setLeakHook(hook: LeakHook | undefined): void;