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
Add support for objects with handleEvent in event handlers #1939
Comments
We should probably support this, yes... I discovered that interface recently probably as a ripple of that article. It should be noted that the interface only works with |
I took an initial run at it here. Still need to add tests and see if this thing actually works. But a few things I'm unsure of:
|
It looks like a good start... Regarding your questions:
I'll add a few comments in line... |
Commited some updates, I believe it's now handling element.onevent cases in addition to addEventListener with functions, objects. Hoping it's not adding too much overhead. Have some working demos running in the browser. Started adding some tests, however it's failing and I wonder if the domMock dispatchEvent supports EventListener objects? |
Nope, it doesn't. |
Added support for EventListener objects where you pointed out. Added tests which seem to be working now. I also created a built branch so we can try it in the browser. |
I did find a bug, but it looks like it is a pre-existing issue. Example - Clicking "Add" should increment once, then the event listener should be removed. I can reproduce this with current Mithril in this example. You'll need to use your browser's mobile emulator (touchstart is an event that must be added with Finally, using |
Should be fixed now by #1949. |
Expected Behavior
When adding event handlers, Mithril should support objects with a
handleEvent
function property in addition to plain functions.Current Behavior
Only functions will be used as event handlers
Possible Solution
Test if the object supplied to an
on[event]
attrs property has a handleEvent function property. Example:Steps to Reproduce (for bugs)
Demo of lack of support
Context
This makes it quite easy to avoid re-creating event handler functions every redraw, and doesn't require binding for
this
context. See this article (pointed out by @JAForbes.)Your Environment
Affects all browsers.
The text was updated successfully, but these errors were encountered: