Callbacks

Execute logic when a listener library loads.

Define a listenerLoaded callback function within a listener library:

loadedExample.ts
import { ListenerEvent } from "@listener-js/listener"

export class LoadedExample {
  private listenerLoaded(
    lid: string[],
    event: ListenerEvent
  ) {
    // setup logic goes here
  }
}

export default new LoadedExample()

Callbacks functions can be asynchronous. When a library has asynchronous callbacks, the end user can await the promise returned by listener.load.

The import in this example has no effect on compiled output. It is purely for accessing types.

Callback arguments

Callbacks receive two arguments, a listener id (lid) and a listener event object:

interface ListenerEvent {
  instance: any
  listener: Listener
  existing?: string[]
  instances?: Record<string, any>
  options?: Record<string, any>
}

Available callbacks

Last updated