From 7e88a604f6362e3ba22c223fd78f1545a90160f0 Mon Sep 17 00:00:00 2001 From: Toby Mao Date: Wed, 13 Oct 2021 08:22:09 -0700 Subject: [PATCH] Update README.md fixes #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.