Just a question on hyperscript event handling - did not find anything in the documentation so asking as an issue.
When you register a handler like this, does the listener get added directly to the dom element
m("button", {onclick: function() {count++}}, count + " clicks"),
Or does it end up as a "delegated event" similar to jQuery.on where there is a single listener for all descendent elements.
$( "#dataTable tbody" ).on( "click", "tr", function() {
});
Curious as to how many handlers get added when say we have a edit button on each row of a table with 1000 records.
It's added directly to the element via addEventListener. So if you had a table of 1k records, each one with that button, you'd have 1k listeners (in which case I'd advise adding it to a parent element instead).
Thanks - I'd still be able to get the row that was clicked right?
Knockout has the dataFor(element) for getting the record that was clicked on.(http://knockoutjs.com/documentation/unobtrusive-event-handling.html)
Is there anything similar in Mithril? Or a recommended way to do this?
@ajaishankar this may help: http://lhorie.github.io/mithril-blog/asymmetrical-data-bindings.html
Thanks @pygy! Just what I was looking for, excited to try out Mithril for some projects...
I wrote delegated to handle event delegation because doing it manually was no fun.
@tivac I had completely forgotten about that lib... thanks for the reminder :-)
Most helpful comment
I wrote delegated to handle event delegation because doing it manually was no fun.