Skip to content

Hooks

A plugin uses a hook through ctx.hooks in the role the catalogue gives it:

role call semantics
listener ctx.hooks.on(name, fn) observes; the return value is ignored; errors are caught and reported
filter ctx.hooks.filter(name, fn, {priority}) gets a value, returns it, changed or not; chained by ascending priority, then the core's, then by load order; a filter that throws, or returns undefined or a promise, is skipped
provider ctx.hooks.provide(name, impl) an exclusive slot; a second provider throws, naming both plugins, and its plugin's activation is rolled back

A name outside the catalogue, or a hook used in another role, is refused. Each call returns what removes the handler; all of them go when the plugin stops. Payloads are frozen copies. No hook fires per frame, during drags, or while a full state is applied. The catalogue is data: protocol/data/hooks.json in @taflor/protocol, with each hook's payload schema; the table below is generated from it.

hook role since what
table.state listener 1.0.0 After every full state: the first one and each reconnect. Object hooks don't fire while a state is applied.
object.added listener 1.0.0 An object came to the table (read-only copy of its data). Not during drags or a full state.
object.changed listener 1.0.0 An object's state changed (read-only copy). Never for moves alone, never while the user drags it (SPEC §7.10.3).
object.removed listener 1.0.0 An object left the table (read-only copy of its last data).
object.create filter 1.0.0 The props of an object before the client sends its creation; the server validates them again. (not called by the core yet)
selection.changed listener 1.0.0 The selected object ids.
access.changed listener 1.0.0 The user's access changed (role, hidden objects, read-only).
camera.settled listener 1.0.0 The world rectangle in view, once a pan or zoom has ended.
menu.object filter 1.0.0 The items of an object's context menu; an alternative to ui.contextMenu.contribute for reordering. (not called by the core yet)
menu.table filter 1.0.0 The items of the table's context menu. (not called by the core yet)
dice.rolled listener 1.0.0 A roll (read-only copy of dice.rolled, SPEC §8); the tray plays it, plugins may add effects.
dice.classify provider 1.0.0 Classes of a single die for its chip in the dice tray and the dice log, given frozen copies of the die and the roll; the roll's own classes come only with RollResult.classes (SPEC §8.5).
dice.summary provider 1.0.0 One line about a roll under its total in the dice tray and the dice log, given a frozen copy of the roll (with its ext); a string, or null for none. Shown as plain text (never HTML), cut to 200 characters, computed when the roll is shown, so in the viewer's language. A provider that throws shows nothing (SPEC §7.10.2, §8.5).
token.overlays filter 1.0.0 The overlay list of a token. (not called by the core yet)
message.* listener 1.0.0 A plugin message x.. (SPEC §6.6), with its payload. (through ctx.messages.on)
sheet.message listener 1.0.0 A message of the sheet protocol (SPEC §7.14). (not called by the core yet)

Server hooks (for server extensions, snake_case names such as object_changed) are a separate catalogue; they run once per change on the server, not per browser.