-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
addEventListener, object with a handleEvent() method support. #8196
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
Comments
Are you referring to adding an event like this?
Then that has nothing to do with Svelte. If you reference a function like that,
I do not see any wrong behavior here. |
There is something off about how the event handler object is attached, though... If the listen(button1, "click", /*listenerObjHandleEvent*/ ctx[1]) If an increment statement is added ( listen(button1, "click", function () {
if (is_function(/*listenerObjHandleEvent*/ ctx[1]))
/*listenerObjHandleEvent*/ ctx[1].apply(this, arguments);
}) And since the handler object is not a function, it will no longer work. |
Thank you for quick reply, yes I saw compiled code in REPL
My Intension is to want svelte compiler support listener object with a handleEvent() according to the DOM API specification. |
Closing per discussion on #15856 |
Describe the problem
I'm not sure this is a bug or the framework's intention.
According to the DOM API specification document
addEventListener(type, listener)
listener could be an object that has a handleEvent() method.

Ref: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
I tried writing the following code in the svelte REPL:
Svelte REPL: https://svelte.dev/repl/538e3dbe765947a9b0a04a88cb050c6a?version=3.55.1
Svelte compiler seems to work with listener objects via handleEvent(), but it produce different results when referencing by object name and "this" including to reactive ui.
Describe the proposed solution
svelte compiler should support addEventListener object with handleEvent()
Alternatives considered
svelte compiler should support addEventListener object with handleEvent()
Importance
nice to have
The text was updated successfully, but these errors were encountered: