Skip to content

API - Hooks

Allows events to be passed between plugins and the core app, as well as allowing plugins to augment or replace certain behaviour.

When extending BasePlugin, these functions can be accessed via this.hooks.*

When extending BaseComponent, these functions can be accessed via this.plugin.hooks.*

Functions

addHandler(name, callback=null)

Adds a hook handler.

Field Type Description Example
name string Name to use when triggering the hook 'controls.key.down'
callback Function Function to execute when handler is triggered. If this function returns a truthy value, the hook is interrupted function (data) { console.log('hook triggered') }

removeHandler(name, callback=null)

Removes a hook handler.

Field Type Description Example
name string Name of the hook to remove 'controls.key.down'
callback Function Same function used when adding the handler function (data) { console.log('hook triggered') }

trigger(name, data=null) : Promise<boolean>

Triggers a hook. The first handler which returns a truthy value will be returned. Note that listeners are able to modify the contents of the data object parameter.

Field Type Description Example
name string Name of the hook to trigger 'my-custom-hook'
data object Data that needs to be passed to the handler { color: '#FFFFFF' }

Global Hooks

The following hooks are exposed from the core app and available to use in any plugins or components.

  • 'controls.key.down' - Triggered when a key is pressed. Returns a KeyboardEvent
  • 'controls.key.up' - Triggered when a key is released. Returns a KeyboardEvent
Back to top