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: replace NodeCustomEvent with CustomEvent #43876

Merged
merged 1 commit into from
May 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,15 +408,6 @@ ObjectDefineProperties(CustomEvent.prototype, {
detail: kEnumerableProperty,
});

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.

If you keep this as class NodeCustomEvent extends CustomEvent {}, that might even be a bit nicer since it’s a way to differentiate between events coming from a user and events coming from a Node.js EventEmitter .emit() call?

Copy link
Member Author

Choose a reason for hiding this comment

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

Could you help me understand what specific usercase do we need to support? I don't understand in which scenario we would need to differentiate between events coming from a user and events coming from a Node.js EventEmitter .emit() call.

constructor(type, options) {
super(type, options);
if (options?.detail) {
this.detail = options.detail;
}
}
}

// Weak listener cleanup
// This has to be lazy for snapshots to work
let weakListenersState = null;
Expand Down Expand Up @@ -837,7 +828,7 @@ class EventTarget {
}

[kCreateEvent](nodeValue, type) {
return new NodeCustomEvent(type, { detail: nodeValue });
return new CustomEvent(type, { detail: nodeValue });
}
[customInspectSymbol](depth, options) {
if (!isEventTarget(this))
Expand Down