Skip to content

Support CustomEvent #40678

Description

@alshdavid

Is your feature request related to a problem? Please describe.
When trying to mimic browser APIs surrounding EventTarget, we frequently use CustomEvent which is currently unavailable in Node.

It's useful in that it allows us to dispatch events through an EventTarget and include a custom data payload.

In a some way, this is the closest we have to a standardised Observable API (specifically Subject) and it's very useful.

Describe the solution you'd like
CustomEvent exists

Describe alternatives you've considered
Writing a polyfill

class CustomEvent extends Event { 
  constructor(message, data) {
    super(message, data)
    this.detail = data.detail
  }
}

const et = new EventTarget()
et.addEventListener('message', ev => console.log(ev.detail))
et.dispatchEvent(new CustomEvent('message', { detail: 'foo' }))

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    eventtargetIssues and PRs related to the EventTarget implementation.feature requestIssues requesting new Node.js features.good first issueIssues that are suitable for first-time contributors.help wantedIssues that need assistance from volunteers or PRs that need help to proceed.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions