-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Conversation
@@ -160,6 +161,14 @@ ObjectDefineProperty(Event.prototype, SymbolToStringTag, { | |||
value: 'Event', | |||
}); | |||
|
|||
class NodeCustomEvent extends Event { |
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.
Name bikeshedding - welcome
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.
👍 from me
lib/internal/event_target.js
Outdated
@@ -463,6 +475,22 @@ class NodeEventTarget extends EventTarget { | |||
this.addEventListener(type, listener, { [kIsNodeStyleListener]: true }); | |||
return this; | |||
} | |||
emit(type, arg) { | |||
if (arguments.length > 2) { |
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.
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.
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.
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 { |
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.
👍 from me
lib/internal/event_target.js
Outdated
@@ -463,6 +475,22 @@ class NodeEventTarget extends EventTarget { | |||
this.addEventListener(type, listener, { [kIsNodeStyleListener]: true }); | |||
return this; | |||
} | |||
emit(type, arg) { | |||
if (arguments.length > 2) { |
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.
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.
lib/internal/event_target.js
Outdated
'Passing more than one argument to NodeEventTarget' + | ||
' dispatch is not supported' |
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.
NodeEventTarget
is purely internal, so I would not mention it here, tbh. Maybe just say `.emit()` on a Node.js `EventTarget`
?
cc @nodejs/workers |
@@ -463,6 +474,14 @@ class NodeEventTarget extends EventTarget { | |||
this.addEventListener(type, listener, { [kIsNodeStyleListener]: true }); | |||
return this; | |||
} | |||
emit(type, arg) { | |||
if (typeof type !== '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.
Minor suggestion: use validateString
from /internal/validators
.
if (typeof type !== 'string') { | |
validateString(type, 'type') |
Accidentially converted to draft - will convert back, mixed this up with the AbortSignal PR 😅 |
4c1d6a7
to
f8e9bfc
Compare
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 <[email protected]> ------------------------------ 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 <[email protected]> -------------------------------------------------------------------------------- ⚠ 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 |
Landed in 2a1273c...c5477be |
PR-URL: #35851 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Ricky Zhou <[email protected]>
PR-URL: #35851 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Ricky Zhou <[email protected]>
PR-URL: nodejs#35851 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Ricky Zhou <[email protected]>
PR-URL: nodejs#35851 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Ricky Zhou <[email protected]>
PR-URL: nodejs#35851 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Ricky Zhou <[email protected]>
PR-URL: #35851 Backport-PR-URL: #38386 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Ricky Zhou <[email protected]>
NodeEventTarget.emit() is not described in document. Plus, make type parameter of removeAllListeners as optional. Refs: #35851 PR-URL: #46356 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
NodeEventTarget.emit() is not described in document. Plus, make type parameter of removeAllListeners as optional. Refs: #35851 PR-URL: #46356 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
NodeEventTarget.emit() is not described in document. Plus, make type parameter of removeAllListeners as optional. Refs: #35851 PR-URL: #46356 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
NodeEventTarget.emit() is not described in document. Plus, make type parameter of removeAllListeners as optional. Refs: nodejs/node#35851
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes