UNPKG

@rbxts/planck-flamecs-hooks

Version:

A @rbxts/planck plugin that provides support for @rbxts/flamecs hooks.

30 lines (29 loc) 1.3 kB
type Cleanup<T> = (state: T) => boolean; interface HookStorage<T> { cleanup?: Cleanup<T>; states: Map<string, T>; } export declare const secondaryStack: Array<defined>; /** * Starts a new stack frame for a function, ensuring cleanup after execution. * Intended to be used in systems. * * @param node - The node to store the state for the current function. * @param callback - The function to execute within the new stack frame. */ export declare function start(node: Record<string, HookStorage<unknown>>, callback: () => void): void; /** * Creates or retrieves a state object for a hook, keyed by a unique identifier. * * @template T The type of the hook state. * @param key - A unique string identifier for the hook state. * @param discriminator - An optional value to further distinguish different * states within the same key. Defaults to the key itself. * @param cleanup - An optional function that determines whether the state * should be cleaned up. It should return true if the state should be removed. * If not provided, the state will be cleaned up when the hook was not * accessed in the current context. * @returns The state object of type T. */ export declare function useHookState<T>(key: string, discriminator: unknown, cleanup?: Cleanup<T>): T; export {};