Home > @xoram/core > onEvent
onEvent() function
Listen to multiple events from the same source at once and cleanly stop to listen when the plugin is disposed off.
Signature:
typescript
export declare function onEvent<notifications extends Notifications, events extends (keyof notifications)[]>(target: EventTarget<notifications>, on: events, handler: Handler<MergedEvents<notifications, events>>): EventCleanup;
1
Parameters
Parameter | Type | Description |
---|---|---|
target | EventTarget<notifications> | something to listen events on |
on | events | a list of events to listen to |
handler | Handler<MergedEvents<notifications, events>> | callback to invoke when any of the events in |
Returns:
Example
ts
// target getter
onEvent(app => app.services.myService, ['an-event', 'another-event'], console.log);
onEvent(({services}) => services.myService, ['an-event', 'another-event'], console.log);
// direct target
onEvent(myCustomEmitter, ['an-event', 'another-event'], console.log);
// service id
onEvent('myService', ['an-event', 'another-event'], console.log);
1
2
3
4
5
6
7
2
3
4
5
6
7