Search Docs
Loading...
Skip to content

Class: EngineActions

Named, overridable actions for one engine. Actions are either JS closures you register or engine defaults (e.g. undo/redo), and either kind can override the other by reusing the id.

JS-registered actions run directly in JS, so on the web you get full fidelity: get hands back the raw function and run passes args/results by reference (non-serializable payloads like File/Blob work). The engine also keeps a JSON trampoline per action so defaults run natively and host actions stay reachable across the FFI — that path is JSON-only and async. Engine defaults you have not overridden are reachable only via run; get returns undefined.

Remarks#

Main-thread only. get is web-only; use run/has/list cross-platform.

Constructors#

Constructor#


EngineActions

Methods#

register()#


Register an action, replacing any existing one with the same id.

Type Parameters#
Type Parameter
K extends never
Parameters#
Parameter Type Description
id K The action id (e.g. undo). Reusing an engine default’s id overrides it.
fn EngineActionsRegistry[K] extends (…args) => any ? any[any] : EngineCustomActionFunction The action body (sync or async). On the web it runs directly with any JS values. Across the FFI args/results are JSON, so only serializable payloads work there.
Returns#

void

Call Signature#

register(id, fn): void;

Register an action, replacing any existing one with the same id.

Parameters#
Parameter Type Description
id string The action id (e.g. undo). Reusing an engine default’s id overrides it.
fn EngineCustomActionFunction The action body (sync or async). On the web it runs directly with any JS values. Across the FFI args/results are JSON, so only serializable payloads work there.
Returns#

void

Signatures#

register(id: K, fn: EngineActionsRegistry[K] extends (args: any[]) => any ? any[any] : EngineCustomActionFunction): void
register(id: string, fn: EngineCustomActionFunction): void

get()#


Get the raw registered function for an id so you can call it synchronously.

Returns the exact function you registered. Returns undefined for unknown ids and engine-default native actions (which have no JS function) — use run for those.

Type Parameters#
Type Parameter
K extends never
Parameters#
Parameter Type
id K
Returns#

EngineActionsRegistry[K]

Remarks#

Web-only.

Call Signature#

get(id): EngineCustomActionFunction;

Get the raw registered function for an id so you can call it synchronously.

Returns the exact function you registered. Returns undefined for unknown ids and engine-default native actions (which have no JS function) — use run for those.

Parameters#
Parameter Type
id string
Returns#
EngineCustomActionFunction
Remarks#

Web-only.

Signatures#

get(id: K): EngineActionsRegistry[K]
get(id: string): EngineCustomActionFunction

run()#


Run an action by id and return its result as a Promise.

JS-registered actions are called directly (args/result by reference). Engine defaults go across the FFI (JSON args/result).

Type Parameters#
Type Parameter
K extends never
Parameters#
Parameter Type Description
id K The action id.
args EngineActionsRegistry[K] extends (…args) => any ? A : unknown[] Arguments forwarded to the action.
Returns#

Promise<EngineActionsRegistry[K] extends (…args) => R ? Awaited<R> : unknown>

The action’s result, or a rejection if the id is unknown or it threw.

Call Signature#

run<R>(id, ...args): Promise<R>;

Run an action by id and return its result as a Promise.

JS-registered actions are called directly (args/result by reference). Engine defaults go across the FFI (JSON args/result).

Type Parameters#
Type Parameter Default type
R unknown
Parameters#
Parameter Type Description
id string The action id.
args unknown[] Arguments forwarded to the action.
Returns#

Promise<R>

The action’s result, or a rejection if the id is unknown or it threw.

Signatures#

run(id: K, args: EngineActionsRegistry[K] extends (args: A) => any ? A : unknown[]): Promise<EngineActionsRegistry[K] extends (args: any[]) => R ? Awaited<R> : unknown>
run(id: string, args: unknown[]): Promise<R>

has()#


Whether an action with this id is registered (host or engine default).

Parameters#

Parameter Type
id string

Returns#

boolean

Signature#

has(id: string): boolean

unregister()#


Remove a host action, or revert an overridden engine default to its built-in.

If you override an engine default (such as select or undo), unregistering the id restores the default rather than leaving it unhandled. A custom id you registered yourself is removed entirely. Returns false only when the id is unknown.

Parameters#

Parameter Type
id string

Returns#

boolean

Signature#

unregister(id: string): boolean

list()#


List registered actions, optionally filtered by a * glob matcher on the id.

Parameters#

Parameter Type
options? { matcher?: string; }
options.matcher? string

Returns#

EngineActionInfo[]

Signature#

list(options?: object): EngineActionInfo[]