Skip to content

Commit 80f06ac

Browse files
docs(events): add events listner options
1 parent f07a58a commit 80f06ac

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

content/techniques/events.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,30 @@ handleOrderCreatedEvent(payload: OrderCreatedEvent) {
8585

8686
> warning **Warning** Event subscribers cannot be request-scoped.
8787
88-
The first argument can be a `string` or `symbol` for a simple event emitter and a `string | symbol | Array<string | symbol>` in a case of a wildcard emitter. The second argument (optional) is a listener options object ([read more](https://github.com/EventEmitter2/EventEmitter2#emitteronevent-listener-options-objectboolean)).
88+
The first argument can be a `string` or `symbol` for a simple event emitter and a `string | symbol | Array<string | symbol>` in a case of a wildcard emitter.
89+
90+
The second argument (optional) is a listener options object as follows:
91+
92+
93+
```typescript
94+
export type OnEventOptions = OnOptions & {
95+
/**
96+
* If "true", prepends (instead of append) the given listener to the array of listeners.
97+
*
98+
* @see https://github.com/EventEmitter2/EventEmitter2#emitterprependlistenerevent-listener-options
99+
*
100+
* @default false
101+
*/
102+
prependListener?: boolean;
103+
104+
/**
105+
* If "true", the onEvent callback will not throw an error while handling the event. Otherwise, if "false" it will throw an error.
106+
*
107+
* @default true
108+
*/
109+
suppressErrors?: boolean;
110+
};
111+
```
89112

90113
```typescript
91114
@OnEvent('order.created', { async: true })
@@ -94,6 +117,9 @@ handleOrderCreatedEvent(payload: OrderCreatedEvent) {
94117
}
95118
```
96119

120+
> info **Hint** read more about ([listener options object](https://github.com/EventEmitter2/EventEmitter2#emitteronevent-listener-options-objectboolean)).
121+
122+
97123
To use namespaces/wildcards, pass the `wildcard` option into the `EventEmitterModule#forRoot()` method. When namespaces/wildcards are enabled, events can either be strings (`foo.bar`) separated by a delimiter or arrays (`['foo', 'bar']`). The delimiter is also configurable as a configuration property (`delimiter`). With namespaces feature enabled, you can subscribe to events using a wildcard:
98124

99125
```typescript

0 commit comments

Comments
 (0)