Home > @xoram/core > onEvent
onEvent() function
Listen to all the events of a source at once and cleanly stop to listen when the plugin is disposed off.
Only use this overload when you need to listen to all the events, if you need to listen to just a subset of the events consider passing an array of those events.
Signature:
typescript
export declare function onEvent<notifications extends Notifications>(target: EventTarget<notifications>, on: '*', handler: WildcardHandler<notifications>): EventCleanup;
1
Parameters
Parameter | Type | Description |
---|---|---|
target | EventTarget<notifications> | something to listen events on |
on | '*' | ask to subscribe to everything |
handler | WildcardHandler<notifications> | callback to invoke when any event is emitted by |
Returns:
Example
ts
// target getter
onEvent(app => app.services.myService, '*', console.log);
onEvent(({services}) => services.myService, '*', console.log);
// direct target
onEvent(myCustomEmitter, '*', console.log);
// service id
onEvent('myService', '*', console.log);
1
2
3
4
5
6
7
2
3
4
5
6
7