You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've searched for any related issues and avoided creating a duplicate issue.
Description
The Node EventTarget class supports both a function as the listener, and an object with a handleEvent function. I.e. addEventListener(name: string, listener: Function | { handleEvent: Function })
I've read through #1818 and see it is unlikely this package will use the native Node EventTarget. I think it would be helpful to add this to the EventTarget shim to more closely match the Node implementation.
My use case is generated code which I don't control that is generating addEventListener(name, { handleEvent: () => {}). Valid in the browser, but breaks with Node using ws
I am currently working around by using the following. In an implementation in this package, it might be simpler to use handler.handleEvent.call(handler) to keep the this context
socket.addEventListener('message', { handleEvent: e => console.log(e) }) should work identically to socket.addEventListener('message', e => console.log(e))
Actual result
The handleEvent object does not get added and the listener is never called
Attachments
No response
The text was updated successfully, but these errors were encountered:
Is there an existing issue for this?
Description
The Node
EventTarget
class supports both a function as the listener, and an object with ahandleEvent
function. I.e.addEventListener(name: string, listener: Function | { handleEvent: Function })
Node docs
I've read through #1818 and see it is unlikely this package will use the native Node
EventTarget
. I think it would be helpful to add this to theEventTarget
shim to more closely match the Node implementation.My use case is generated code which I don't control that is generating
addEventListener(name, { handleEvent: () => {})
. Valid in the browser, but breaks with Node usingws
I am currently working around by using the following. In an implementation in this package, it might be simpler to use
handler.handleEvent.call(handler)
to keep the this contextws version
8.10.0
Node.js Version
16.17.0
System
OS: macOS 12.3.1
Expected result
socket.addEventListener('message', { handleEvent: e => console.log(e) })
should work identically tosocket.addEventListener('message', e => console.log(e))
Actual result
The
handleEvent
object does not get added and the listener is never calledAttachments
No response
The text was updated successfully, but these errors were encountered: