From e54012e8112a54643962c08595e44d6ff570a450 Mon Sep 17 00:00:00 2001 From: Toby Mao Date: Thu, 14 Oct 2021 00:29:26 -0700 Subject: [PATCH] chore(docs): remove outdated note about eventlisteners from README This functionality was always unnecessary, because the example could be done with a curried function for example: ```js function makeEventListener(number) { return (event) => console.log("button " + number + " was clicked!"); } ``` ISSUES FIXED: #988 --- README.md | 37 ------------------------------------- 1 file changed, 37 deletions(-) diff --git a/README.md b/README.md index c92e090..7c9f715 100644 --- a/README.md +++ b/README.md @@ -618,43 +618,6 @@ In JSX, you can use `on` like this:
``` -Very often, however, you're not really interested in the event object -itself. Often you have some data associated with the element that -triggers an event and you want that data passed along instead. - -Consider a counter application with three buttons, one to increment -the counter by 1, one to increment the counter by 2 and one to -increment the counter by 3. You don't really care exactly which button -was pressed. Instead you're interested in what number was associated -with the clicked button. The event listeners module allows one to -express that by supplying an array at the named event property. The -first element in the array should be a function that will be invoked -with the value in the second element once the event occurs. - -```mjs -function clickHandler(number) { - console.log("button " + number + " was clicked!"); -} -h("div", [ - h("a", { on: { click: [clickHandler, 1] } }), - h("a", { on: { click: [clickHandler, 2] } }), - h("a", { on: { click: [clickHandler, 3] } }), -]); -``` - -Each handler is called not only with the given arguments but also with the current event and vnode appended to the argument list. It also supports using multiple listeners per event by specifying an array of handlers: - -```mjs -stopPropagation = function (ev) { - ev.stopPropagation(); -}; -sendValue = function (func, ev, vnode) { - func(vnode.elm.value); -}; - -h("a", { on: { click: [[sendValue, console.log], stopPropagation] } }); -``` - Snabbdom allows swapping event handlers between renders. This happens without actually touching the event handlers attached to the DOM.