lifecycle
Global lifecycle hook system for VoltX.js Provides beforeMount, afterMount, beforeUnmount, and afterUnmount hooks
registerGlobalHook
Register a global lifecycle hook. Global hooks run for every mount/unmount operation in the application.
export function registerGlobalHook(name: GlobalHookName, cb: MountHookCallback | UnmountHookCallback): () => voidExample:
// Log every mount operation
registerGlobalHook('beforeMount', (root, scope) => {
console.log('Mounting', root, 'with scope', scope);
});
// Track mounted elements
const mountedElements = new Set<Element>();
registerGlobalHook('afterMount', (root) => {
mountedElements.add(root);
});
registerGlobalHook('beforeUnmount', (root) => {
mountedElements.delete(root);
});unregisterGlobalHook
Unregister a global lifecycle hook.
export function unregisterGlobalHook(name: GlobalHookName, cb: MountHookCallback | UnmountHookCallback): booleanclearGlobalHooks
Clear all global hooks for a specific lifecycle event.
export function clearGlobalHooks(name: GlobalHookName): voidclearAllGlobalHooks
export function clearAllGlobalHooks(): voidgetGlobalHooks
Get all registered hooks for a specific lifecycle event. Used internally by the binder system.
export function getGlobalHooks(name: GlobalHookName): Array<MountHookCallback | UnmountHookCallback>executeGlobalHooks
Execute all registered hooks for a lifecycle event. Used internally by the binder system.
export function executeGlobalHooks(hookName: GlobalHookName, root: Element, scope?: Scope): voidregisterElementHook
Register a per-element lifecycle hook. These hooks are specific to individual elements.
export function registerElementHook(element: Element, hookType: "mount" | "unmount", cb: () => void): voidnotifyElementMounted
Notify that an element has been mounted. Executes all registered onMount callbacks for the element.
export function notifyElementMounted(element: Element): voidnotifyElementUnmounted
Notify that an element is being unmounted. Executes all registered onUnmount callbacks for the element.
export function notifyElementUnmounted(element: Element): voidnotifyBindingCreated
Notify that a binding has been created on an element.
export function notifyBindingCreated(element: Element, name: string): voidnotifyBindingDestroyed
Notify that a binding has been destroyed on an element.
export function notifyBindingDestroyed(element: Element, name: string): voidisElementMounted
Check if an element is currently mounted.
export function isElementMounted(element: Element): booleangetElementBindings
Get all bindings on an element.
export function getElementBindings(element: Element): string[]