a reactive (signals based) hypermedia web framework (wip)
stormlightlabs.github.io/volt/
hypermedia
frontend
signals
1---
2version: 1.0
3updated: 2025-10-18
4---
5
6# lifecycle
7
8Global lifecycle hook system for VoltX.js
9Provides beforeMount, afterMount, beforeUnmount, and afterUnmount hooks
10
11## registerGlobalHook
12
13Register a global lifecycle hook.
14Global hooks run for every mount/unmount operation in the application.
15
16```typescript
17export function registerGlobalHook(name: GlobalHookName, cb: MountHookCallback | UnmountHookCallback): () => void
18```
19
20**Example:**
21
22```typescript
23// Log every mount operation
24registerGlobalHook('beforeMount', (root, scope) => {
25 console.log('Mounting', root, 'with scope', scope);
26});
27
28// Track mounted elements
29const mountedElements = new Set<Element>();
30registerGlobalHook('afterMount', (root) => {
31 mountedElements.add(root);
32});
33registerGlobalHook('beforeUnmount', (root) => {
34 mountedElements.delete(root);
35});
36```
37
38## unregisterGlobalHook
39
40Unregister a global lifecycle hook.
41
42```typescript
43export function unregisterGlobalHook(name: GlobalHookName, cb: MountHookCallback | UnmountHookCallback): boolean
44```
45
46## clearGlobalHooks
47
48Clear all global hooks for a specific lifecycle event.
49
50```typescript
51export function clearGlobalHooks(name: GlobalHookName): void
52```
53
54## clearAllGlobalHooks
55
56```typescript
57export function clearAllGlobalHooks(): void
58```
59
60## getGlobalHooks
61
62Get all registered hooks for a specific lifecycle event.
63Used internally by the binder system.
64
65```typescript
66export function getGlobalHooks(name: GlobalHookName): Array<MountHookCallback | UnmountHookCallback>
67```
68
69## executeGlobalHooks
70
71Execute all registered hooks for a lifecycle event.
72Used internally by the binder system.
73
74```typescript
75export function executeGlobalHooks(hookName: GlobalHookName, root: Element, scope?: Scope): void
76```
77
78## registerElementHook
79
80Register a per-element lifecycle hook.
81These hooks are specific to individual elements.
82
83```typescript
84export function registerElementHook(element: Element, hookType: "mount" | "unmount", cb: () => void): void
85```
86
87## notifyElementMounted
88
89Notify that an element has been mounted.
90Executes all registered onMount callbacks for the element.
91
92```typescript
93export function notifyElementMounted(element: Element): void
94```
95
96## notifyElementUnmounted
97
98Notify that an element is being unmounted.
99Executes all registered onUnmount callbacks for the element.
100
101```typescript
102export function notifyElementUnmounted(element: Element): void
103```
104
105## notifyBindingCreated
106
107Notify that a binding has been created on an element.
108
109```typescript
110export function notifyBindingCreated(element: Element, name: string): void
111```
112
113## notifyBindingDestroyed
114
115Notify that a binding has been destroyed on an element.
116
117```typescript
118export function notifyBindingDestroyed(element: Element, name: string): void
119```
120
121## isElementMounted
122
123Check if an element is currently mounted.
124
125```typescript
126export function isElementMounted(element: Element): boolean
127```
128
129## getElementBindings
130
131Get all bindings on an element.
132
133```typescript
134export function getElementBindings(element: Element): string[]
135```