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

events: support emit on nodeeventtarget #35851

Closed
wants to merge 1 commit into from

Conversation

benjamingr
Copy link
Member

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the worker Issues and PRs related to Worker support. label Oct 28, 2020
@@ -160,6 +161,14 @@ ObjectDefineProperty(Event.prototype, SymbolToStringTag, {
value: 'Event',
});

class NodeCustomEvent extends Event {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name bikeshedding - welcome

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 from me

@@ -463,6 +475,22 @@ class NodeEventTarget extends EventTarget {
this.addEventListener(type, listener, { [kIsNodeStyleListener]: true });
return this;
}
emit(type, arg) {
if (arguments.length > 2) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this is the right error to throw and I am not sure throwing is the right behavior.

Other alternatives can be:

  • Wrap it in an array
  • Ignore additional arguments and emit the first one
  • Behave differently for emitter style and target style listeners.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore additional arguments and emit the first one

I think I’d have a mild preference for this one, but really only a mild one.

@@ -160,6 +161,14 @@ ObjectDefineProperty(Event.prototype, SymbolToStringTag, {
value: 'Event',
});

class NodeCustomEvent extends Event {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 from me

@@ -463,6 +475,22 @@ class NodeEventTarget extends EventTarget {
this.addEventListener(type, listener, { [kIsNodeStyleListener]: true });
return this;
}
emit(type, arg) {
if (arguments.length > 2) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore additional arguments and emit the first one

I think I’d have a mild preference for this one, but really only a mild one.

Comment on lines 483 to 484
'Passing more than one argument to NodeEventTarget' +
' dispatch is not supported'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NodeEventTarget is purely internal, so I would not mention it here, tbh. Maybe just say `.emit()` on a Node.js `EventTarget`?

lib/internal/worker/io.js Show resolved Hide resolved
@benjamingr benjamingr added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Oct 28, 2020
@benjamingr
Copy link
Member Author

cc @nodejs/workers

@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 29, 2020
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@@ -463,6 +474,14 @@ class NodeEventTarget extends EventTarget {
this.addEventListener(type, listener, { [kIsNodeStyleListener]: true });
return this;
}
emit(type, arg) {
if (typeof type !== 'string') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestion: use validateString from /internal/validators.

Suggested change
if (typeof type !== 'string') {
validateString(type, 'type')

@benjamingr benjamingr marked this pull request as draft October 31, 2020 09:33
@benjamingr
Copy link
Member Author

Accidentially converted to draft - will convert back, mixed this up with the AbortSignal PR 😅

@benjamingr benjamingr marked this pull request as ready for review October 31, 2020 09:35
@benjamingr benjamingr added the request-ci Add this label to start a Jenkins CI on a PR. label Oct 31, 2020
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 31, 2020
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@benjamingr benjamingr added the request-ci Add this label to start a Jenkins CI on a PR. label Nov 4, 2020
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Nov 4, 2020
@nodejs-github-bot
Copy link
Collaborator

@benjamingr benjamingr added the request-ci Add this label to start a Jenkins CI on a PR. label Nov 5, 2020
@benjamingr benjamingr added the commit-queue Add this label to land a pull request using GitHub Actions. label Nov 6, 2020
@github-actions github-actions bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Nov 6, 2020
@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2020

Commit Queue failed
- Loading data for nodejs/node/pull/35851
✔  Done loading data for nodejs/node/pull/35851
----------------------------------- PR info ------------------------------------
Title      events: support emit on nodeeventtarget (#35851)
   ⚠  Could not retrieve the email or name of the PR author's from user's GitHub profile!
Branch     benjamingr:node-event-target-emit -> nodejs:master
Labels     author ready, lts-watch-v14.x, worker
Commits    1
 - events: support emit on nodeeventtarget
Committers 1
 - Benjamin Gruenbaum 
PR-URL: https://github.com/nodejs/node/pull/35851
Reviewed-By: Anna Henningsen 
Reviewed-By: Rich Trott 
Reviewed-By: Yongsheng Zhang 
Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/35851
Reviewed-By: Anna Henningsen 
Reviewed-By: Rich Trott 
Reviewed-By: Yongsheng Zhang 
Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
--------------------------------------------------------------------------------
   ⚠  Commits were pushed since the last review:
   ⚠  - events: support emit on nodeeventtarget
   ✔  Last GitHub Actions successful
   ℹ  Last Full PR CI on 2020-11-06T10:15:15Z: https://ci.nodejs.org/job/node-test-pull-request/34119/
- Querying data for job/node-test-pull-request/34119/
✔  Build data downloaded
   ✔  Last Jenkins CI successful
   ℹ  This PR was created on Wed, 28 Oct 2020 14:25:09 GMT
   ✔  Approvals: 4
   ✔  - Anna Henningsen (@addaleax): https://github.com/nodejs/node/pull/35851#pullrequestreview-518726152
   ✔  - Rich Trott (@Trott) (TSC): https://github.com/nodejs/node/pull/35851#pullrequestreview-519608507
   ✔  - Yongsheng Zhang (@ZYSzys): https://github.com/nodejs/node/pull/35851#pullrequestreview-519795411
   ✔  - Ricky Zhou (@rickyes): https://github.com/nodejs/node/pull/35851#pullrequestreview-521105281
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu

Commit Queue action: https://github.com/nodejs/node/actions/runs/349293015

@addaleax addaleax added commit-queue Add this label to land a pull request using GitHub Actions. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Nov 6, 2020
@github-actions github-actions bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Nov 6, 2020
@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2020

Landed in 2a1273c...c5477be

@github-actions github-actions bot closed this Nov 6, 2020
nodejs-github-bot pushed a commit that referenced this pull request Nov 6, 2020
PR-URL: #35851
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
danielleadams pushed a commit that referenced this pull request Nov 9, 2020
PR-URL: #35851
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
@danielleadams danielleadams mentioned this pull request Nov 9, 2020
targos pushed a commit to targos/node that referenced this pull request Apr 24, 2021
PR-URL: nodejs#35851
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
targos pushed a commit to targos/node that referenced this pull request Apr 26, 2021
PR-URL: nodejs#35851
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
targos pushed a commit to targos/node that referenced this pull request Apr 30, 2021
PR-URL: nodejs#35851
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
targos pushed a commit that referenced this pull request Apr 30, 2021
PR-URL: #35851
Backport-PR-URL: #38386
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
@targos targos added backported-to-v14.x and removed author ready PRs that have at least one approval, no pending requests for changes, and a CI started. backport-open-v14.x labels Apr 30, 2021
@danielleadams danielleadams mentioned this pull request May 3, 2021
@F3n67u F3n67u mentioned this pull request Jun 21, 2022
deokjinkim added a commit that referenced this pull request Feb 20, 2023
NodeEventTarget.emit() is not described in document. Plus, make
type parameter of removeAllListeners as optional.

Refs: #35851
PR-URL: #46356
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
targos pushed a commit that referenced this pull request Mar 13, 2023
NodeEventTarget.emit() is not described in document. Plus, make
type parameter of removeAllListeners as optional.

Refs: #35851
PR-URL: #46356
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
danielleadams pushed a commit that referenced this pull request Apr 11, 2023
NodeEventTarget.emit() is not described in document. Plus, make
type parameter of removeAllListeners as optional.

Refs: #35851
PR-URL: #46356
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
abhishekumar-tyagi pushed a commit to abhishekumar-tyagi/node that referenced this pull request May 5, 2024
NodeEventTarget.emit() is not described in document. Plus, make
type parameter of removeAllListeners as optional.

Refs: nodejs/node#35851
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
worker Issues and PRs related to Worker support.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants