Skip to main content

Class: HookRegistry<TFilterMap, TActionMap>

Defined in: Plugin/HookRegistry.ts:23

Type Parameters

TFilterMap

TFilterMap = Record<string, unknown>

TActionMap

TActionMap = Record<string, unknown>

Constructors

Constructor

new HookRegistry<TFilterMap, TActionMap>(): HookRegistry<TFilterMap, TActionMap>

Returns

HookRegistry<TFilterMap, TActionMap>

Methods

addAction()

addAction<K>(hook, handler, priority?): () => void

Defined in: Plugin/HookRegistry.ts:107

Register an action hook handler. Lower priority runs first (default: 10). Returns an unsubscribe function.

Type Parameters

K

K extends string

Parameters

hook

K

handler

ActionHandler<TActionMap[K]>

priority?

number = 10

Returns

() => void


addFilter()

addFilter<K>(hook, handler, priority?): () => void

Defined in: Plugin/HookRegistry.ts:36

Register a filter hook handler. Lower priority runs first (default: 10). Returns an unsubscribe function.

Type Parameters

K

K extends string

Parameters

hook

K

handler

FilterHandler<TFilterMap[K]>

priority?

number = 10

Returns

() => void


applyFilters()

applyFilters<K>(hook, initialValue): Promise<TFilterMap[K]>

Defined in: Plugin/HookRegistry.ts:63

Run the filter chain for a hook. Returns the final transformed value. If no handlers are registered, returns initialValue unchanged.

Type Parameters

K

K extends string

Parameters

hook

K

initialValue

TFilterMap[K]

Returns

Promise<TFilterMap[K]>


applyFiltersSync()

applyFiltersSync<K>(hook, initialValue): TFilterMap[K]

Defined in: Plugin/HookRegistry.ts:81

Synchronous variant — only use when you know all handlers are sync. Throws if a handler returns a Promise.

Type Parameters

K

K extends string

Parameters

hook

K

initialValue

TFilterMap[K]

Returns

TFilterMap[K]


clear()

clear(): void

Defined in: Plugin/HookRegistry.ts:180

Remove all registered handlers (useful for testing / shutdown)

Returns

void


fireActions()

fireActions<K>(hook, value): void

Defined in: Plugin/HookRegistry.ts:155

Fire-and-forget variant — kicks off action handlers without awaiting. Useful in hot paths where you don't want to block the response.

Type Parameters

K

K extends string

Parameters

hook

K

value

TActionMap[K]

Returns

void


hasActions()

hasActions<K>(hook): boolean

Defined in: Plugin/HookRegistry.ts:174

Check if any handlers are registered for an action hook

Type Parameters

K

K extends string

Parameters

hook

K

Returns

boolean


hasFilters()

hasFilters<K>(hook): boolean

Defined in: Plugin/HookRegistry.ts:168

Check if any handlers are registered for a filter hook

Type Parameters

K

K extends string

Parameters

hook

K

Returns

boolean


runActions()

runActions<K>(hook, value): Promise<void>

Defined in: Plugin/HookRegistry.ts:134

Fire an action hook. All handlers run; errors are logged, not thrown. Uses Promise.allSettled so one failing handler doesn't block others.

Type Parameters

K

K extends string

Parameters

hook

K

value

TActionMap[K]

Returns

Promise<void>