Skip to content
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

Open
wants to merge 48 commits into
base: master
Choose a base branch
from
Open

Conversation

aleclarson
Copy link
Owner

No description provided.

aleclarson and others added 30 commits June 5, 2020 09:39
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

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?

Copy link
Owner Author

@aleclarson aleclarson Jun 17, 2020

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-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (master@143efbb). Click here to learn what that means.
The diff coverage is 94.44%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master      #37   +/-   ##
=========================================
  Coverage          ?   94.87%           
=========================================
  Files             ?        1           
  Lines             ?       39           
  Branches          ?       15           
=========================================
  Hits              ?       37           
  Misses            ?        2           
  Partials          ?        0           
Impacted Files Coverage Δ
src/ee.ts 94.87% <94.44%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 143efbb...fb5ebc5. Read the comment docs.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants