Skip to content

Commit f2a8e39

Browse files
docs: add docs about multilevel wildcards
1 parent f2d678e commit f2a8e39

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

content/techniques/events.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ EventEmitterModule.forRoot({
5252

5353
#### Dispatching Events
5454

55-
To dispatch an event, first inject `EventEmitter2` using standard constructor injection:
55+
To dispatch (i.e., fire) an event, first inject `EventEmitter2` using standard constructor injection:
5656

5757
```typescript
5858
constructor(private eventEmitter: EventEmitter2) {}
@@ -101,4 +101,16 @@ handleOrderEvents(payload: OrderCreatedEvent | OrderRemovedEvent | OrderUpdatedE
101101
}
102102
```
103103

104+
Note that such a wildcard only applies to one block. The argument `order.*` will match, for example, the events `order.created` and `order.shipped` but not `order.delayed.out_of_stock`. In order to listen to such events,
105+
use the `multilevel wildcard` pattern (i.e, `**`), described in the `EventEmitter2` package.
106+
107+
With this pattern, you can, for example, create an event listener that catches all events.
108+
109+
```typescript
110+
@OnEvent('**')
111+
handleEverything(payload: any) {
112+
console.log('listener triggered');
113+
}
114+
```
115+
104116
> info **Hint** `EventEmitter2` class provides several useful methods for interacting with events, like `waitFor` and `onAny`. You can read more about them [here](https://github.com/EventEmitter2/EventEmitter2).

0 commit comments

Comments
 (0)