API reference / @jsprismarine/content / HookTable
Class: HookTable<H>
Defined in: packages/content/src/hooks.ts:61
The dispatch table one resolved type binds once at load.
Every hook becomes a frozen array of handlers in contribution order, so a call costs one map lookup and a loop with no allocation. A contribution marked override clears the handlers collected so far for the hooks it implements, which is how a permutation replaces a base component.
Type Parameters
H
H extends HookSignatures<H>
Constructors
Constructor
new HookTable<
H>(contributions):HookTable<H>
Defined in: packages/content/src/hooks.ts:66
Parameters
contributions
Iterable<HookContribution<H>>
Components in declaration order, then behaviors in attachment order.
Returns
HookTable<H>
Methods
contributors()
contributors(
hook): readonlystring[]
Defined in: packages/content/src/hooks.ts:100
The component or behavior behind each handler, in the same order as HookTable.handlers.
Parameters
hook
keyof H & string
Returns
readonly string[]
dispatch()
dispatch<
K>(hook, ...args):void
Defined in: packages/content/src/hooks.ts:105
Calls every handler for the hook in dispatch order, discarding their results.
Type Parameters
K
K extends string
Parameters
hook
K
args
...Parameters<H[K]>
Returns
void
dispatchFirst()
dispatchFirst<
K>(hook, ...args):ReturnType<H[K]> |undefined
Defined in: packages/content/src/hooks.ts:116
Calls handlers in dispatch order until one returns a value other than undefined, which is how a cancelable hook reports that it handled the event.
Type Parameters
K
K extends string
Parameters
hook
K
args
...Parameters<H[K]>
Returns
ReturnType<H[K]> | undefined
That handler's result, or undefined when every handler declines.
handlers()
handlers<
K>(hook): readonlyH[K][]
Defined in: packages/content/src/hooks.ts:93
The handlers for one hook in dispatch order, frozen and empty when nothing implements it.
Type Parameters
K
K extends string
Parameters
hook
K
Returns
readonly H[K][]
has()
has(
hook):boolean
Defined in: packages/content/src/hooks.ts:88
Whether anything implements the hook.
Parameters
hook
keyof H & string
Returns
boolean