-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
V2: Replace singly linked lists with Set objects #37
base: master
Are you sure you want to change the base?
Conversation
BREAKING CHANGE
To avoid duplicated side effects, `EventEmitter` subclasses that override the `[$addListener]` method should only apply side effects when a single function is passed. BREAKING CHANGE
Use the exported `$listeners` symbol, instead. BREAKING CHANGE
src/types.ts
Outdated
export type EventIn<T, K extends EventKey<T>> = Id<In<T[K]>> | ||
export type EventOut<T, K extends EventKey<T>> = Id<Out<T[K]> | void> | ||
/** Extract an array type of valid event keys */ | ||
export type EventKey<T> = keyof T & string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
qq: Are you removing support for output values in v2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sort of. You'll still be able to use getListeners
with Array.from
like this:
const results = Array.from(ee.getListeners('key'), fn => fn())
Note: getListeners
of v2 is not equivalent to listeners
of v1. The former returns a Set
of listeners, the latter returns an iterable.
The "*" key is reserved for removing the listeners of all events, like this: ee.on("test", () => {}) ee.off("*") ee.getListeners("test").size // => 0
To make your EventEmitter readonly, cast it as an EventSource.
You cannot freeze a Set object like that. lol
or else some bundlers complain
You can use `ee.getListeners()` instead
Codecov Report
@@ Coverage Diff @@
## master #37 +/- ##
=========================================
Coverage ? 94.87%
=========================================
Files ? 1
Lines ? 39
Branches ? 15
=========================================
Hits ? 37
Misses ? 2
Partials ? 0
Continue to review full report at Codecov.
|
Pass another `EventSource` or `EventEmitter` type as the type parameter of the `EventSource` type to use the same events. Useful for converting an `EventEmitter` to an `EventSource`, as well as omitting properties not related to events.
No description provided.