From c8bf8dccaff6cb23742d8ca7699cd118eaf20ce0 Mon Sep 17 00:00:00 2001 From: Jan Andrle Date: Fri, 25 Aug 2023 12:04:15 +0200 Subject: [PATCH] :recycle: Rename `listen` to `on` --- README.md | 2 +- src/events.js | 2 +- test/index.js | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1d6230c..2d1a637 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,6 @@ const value= S(""); document.body.append( el("span", { style: { fontWeight: "bold" }, textContent: value }), el("input", { type: "text" }, - listen("change", event=> value(event.target.value))) + on("change", event=> value(event.target.value))) ); ``` diff --git a/src/events.js b/src/events.js index 393481b..7866b17 100644 --- a/src/events.js +++ b/src/events.js @@ -1,5 +1,5 @@ import { isSignal } from './signals.js'; -export function listen(event, listener, options){ +export function on(event, listener, options){ if(isSignal(event)) return event.listeners.add(listener); return element=> element.addEventListener(event, listener, options); } diff --git a/test/index.js b/test/index.js index 6d2978f..eae8b0d 100644 --- a/test/index.js +++ b/test/index.js @@ -1,9 +1,9 @@ -import { S, watch, el, namespace, assign, listen, dispatch } from "../index.js"; -Object.assign(globalThis, { S, watch, el, namespace, assign, listen, dispatch }); +import { S, watch, el, namespace, assign, on, dispatch } from "../index.js"; +Object.assign(globalThis, { S, watch, el, namespace, assign, on, dispatch }); const { style, css }= createStyle(); globalThis.test= console.log; -const app= el(component, null, listen("change", globalThis.test)); +const app= el(component, null, on("change", globalThis.test)); dispatch("change", "Peter")(app); console.log(app, app instanceof HTMLDivElement); @@ -23,7 +23,7 @@ function component({ name= "World", surname= "" }= {}){ `; const store= S({ name, surname }); const full_name= S(()=> store.name()+" "+store.surname()); - listen(full_name, console.log); + on(full_name, console.log); return el("div", { className }).append( el("p").append( @@ -34,12 +34,12 @@ function component({ name= "World", surname= "" }= {}){ el("label").append( el("#text", { textContent: "Set name:" }), el("input", { type: "text", value: store.name }, - listen("change", ev=> store.name(ev.target.value))), + on("change", ev=> store.name(ev.target.value))), ), el("label").append( el("#text", { textContent: "Set surname:" }), el("input", { type: "text", value: store.surname }, - listen("change", ev=> store.surname(ev.target.value))), + on("change", ev=> store.surname(ev.target.value))), ) ) }