Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upevents: support emit on nodeeventtarget #35851
Conversation
| @@ -160,6 +161,14 @@ ObjectDefineProperty(Event.prototype, SymbolToStringTag, { | |||
| value: 'Event', | |||
| }); | |||
|
|
|||
| class NodeCustomEvent extends Event { | |||
benjamingr
Oct 28, 2020
Author
Member
Name bikeshedding - welcome
Name bikeshedding - welcome
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) { | |||
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.
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.
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.
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 { | |||
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) { | |||
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.
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' |
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`?
NodeEventTarget is purely internal, so I would not mention it here, tbh. Maybe just say `.emit()` on a Node.js `EventTarget`?
| @@ -463,6 +474,14 @@ class NodeEventTarget extends EventTarget { | |||
| this.addEventListener(type, listener, { [kIsNodeStyleListener]: true }); | |||
| return this; | |||
| } | |||
| emit(type, arg) { | |||
| if (typeof type !== 'string') { | |||
ZYSzys
Oct 29, 2020
Member
Minor suggestion: use validateString from /internal/validators.
Suggested change
if (typeof type !== 'string') {
validateString(type, 'type')
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 |
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes