Skip to content

Commit b968bd0

Browse files
authored
Merge pull request #5 from MatrixAI/feature-default-fall-through
feat: introduce `EventAll` and `EventDefault`
2 parents 76076f8 + 6c4e19e commit b968bd0

29 files changed

+4129
-2052
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,19 @@ x.addEventListener(EventCustom.name, (e) => {
5454
console.log(e as EventCustom);
5555
});
5656

57-
// Handle any event
58-
x.addEventListener((e) => {
57+
// Handle unhandled events
58+
x.addEventListener(EventDefault.name, (e) => {
59+
// This is the wrapped underlying event
60+
console.log((e as EventDefault).detail);
61+
})
62+
63+
// Handle all events
64+
x.addEventListener(EventAll.name, (e) => {
5965
// This is the wrapped underlying event
6066
console.log((e as EventAny).detail);
6167
})
6268
```
6369

64-
Note that all events pass through the any event handler, it is not a "fall through" handler.
65-
6670
You can use this style to handle relevant events to perform side-effects, as well as propagate upwards irrelevant events.
6771

6872
Note that some side-effects you perform may trigger an infinite loop by causing something to emit the specific event type that you are handling. In these cases you should specialise handling of those events with a `once: true` option, so that they are only handled once.

docs/assets/main.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/assets/search.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)