Links

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>
}
Property
Description
instance
Listener library instance
listener
Listener instance
existing?
Existing (already loaded) listener libraries
instances?
Library instances passed into the listener.load invocation
options?
Options passed into the listener.load invocation

Available callbacks

Callback
Timing
listenerLoaded
Once this listener library is ready
listenerLoadedAny
Once any listener library is ready
listenerBeforeLoaded
Before listenerLoaded
listenerBeforeLoadedAny
Before listenerLoadedAny
listenerAfterLoaded
After listenerLoaded
listenerAfterLoadedAny
After listenerLoadedAny
listenerReset
Before listener.reset
Last modified 4yr ago