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

Open
wants to merge 3 commits into
base: master
from

Conversation

@benjamingr
Copy link
Member

@benjamingr benjamingr commented Oct 28, 2020

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
@benjamingr benjamingr requested a review from addaleax Oct 28, 2020
@@ -160,6 +161,14 @@ ObjectDefineProperty(Event.prototype, SymbolToStringTag, {
value: 'Event',
});

class NodeCustomEvent extends Event {

This comment has been minimized.

@benjamingr

benjamingr Oct 28, 2020
Author Member

Name bikeshedding - welcome

This comment has been minimized.

@addaleax

addaleax Oct 28, 2020
Member

👍 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) {

This comment has been minimized.

@benjamingr

benjamingr Oct 28, 2020
Author Member

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.

This comment has been minimized.

@addaleax

addaleax Oct 28, 2020
Member

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 {

This comment has been minimized.

@addaleax

addaleax Oct 28, 2020
Member

👍 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) {

This comment has been minimized.

@addaleax

addaleax Oct 28, 2020
Member

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.

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

This comment has been minimized.

@addaleax

addaleax Oct 28, 2020
Member

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
Copy link
Member Author

@benjamingr benjamingr commented Oct 29, 2020

@github-actions github-actions bot removed the request-ci label Oct 29, 2020
@Trott
Trott approved these changes Oct 29, 2020
@ZYSzys
ZYSzys approved these changes Oct 29, 2020
@@ -463,6 +474,14 @@ class NodeEventTarget extends EventTarget {
this.addEventListener(type, listener, { [kIsNodeStyleListener]: true });
return this;
}
emit(type, arg) {
if (typeof type !== 'string') {

This comment has been minimized.

@ZYSzys

ZYSzys Oct 29, 2020
Member

Minor suggestion: use validateString from /internal/validators.

Suggested change
if (typeof type !== 'string') {
validateString(type, 'type')
@benjamingr benjamingr marked this pull request as draft Oct 31, 2020
@benjamingr
Copy link
Member Author

@benjamingr benjamingr commented Oct 31, 2020

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

@benjamingr benjamingr marked this pull request as ready for review Oct 31, 2020
@github-actions github-actions bot removed the request-ci label Oct 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.