EventListener doesn't support argument passing
tobymao opened this issue · comments
The documentation claims to support eventHandlers with argument passing
function clickHandler(number) {
console.log("button " + number + " was clicked!");
}
h("div", [
h("a", { on: { click: [clickHandler, 1] } }),
]);
But trying this in my app and looking at the code, it doesn't work. InvokeHandler doesn't have a special case to ever call the handler with the 2nd argument of a list and there are no unit tests for this so I'm wondering if the documentation is out of date or if this is a bug?
Yes, this is outdated documentation, sorry. You could easily emulate this with a curried function:
function makeClickHandler(number) {
return function handler(event) {
console.log("button " + number + " was clicked");
}
}
h("div", [
h("a", { on: { click: makeClickHandler(1) } }),
]);
A PR to fix the documentation would be very welcome :)