From 1ffc84bf50edbe4612532c4e531663cd4d3348f8 Mon Sep 17 00:00:00 2001 From: Shiba <44804845+DeepDoge@users.noreply.github.com> Date: Mon, 18 Nov 2024 13:30:37 +0000 Subject: [PATCH] Updated compare example --- README.md | 2 +- .../purify.js/inputHelloAlternative.ts | 4 ++-- .../1-input-text/purify.js/util-bind.ts | 20 ++++++++----------- jsr.json | 2 +- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 0e132a6..20eb180 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ ### Syntax -[Compare Syntax](https://bafybeigfdi7ylsyo56uz3l5l5h76jsbkjb6jrtyccpsslnnqghquhsowii.ipfs.dweb.link) +[Compare Syntax](https://bafybeihfqjty6ftahk263rc6q66yxzuh24vylahprhodkocbbhvazjtjmi.ipfs.dweb.link) ## Installation 🍙 diff --git a/apps/compare/src/content/6-form-input/1-input-text/purify.js/inputHelloAlternative.ts b/apps/compare/src/content/6-form-input/1-input-text/purify.js/inputHelloAlternative.ts index 9fe04b7..45c8305 100644 --- a/apps/compare/src/content/6-form-input/1-input-text/purify.js/inputHelloAlternative.ts +++ b/apps/compare/src/content/6-form-input/1-input-text/purify.js/inputHelloAlternative.ts @@ -1,5 +1,5 @@ import { fragment, ref, tags } from "@purifyjs/core"; -import { useBind } from "./util-bind"; +import { useBindText } from "./util-bind"; const { p, input } = tags; @@ -8,6 +8,6 @@ export function InputHello() { return fragment( p().children(text), - input().effect(useBind(text, "value", "input")), + input().effect(useBindText(text)), ); } diff --git a/apps/compare/src/content/6-form-input/1-input-text/purify.js/util-bind.ts b/apps/compare/src/content/6-form-input/1-input-text/purify.js/util-bind.ts index 081c580..da632c4 100644 --- a/apps/compare/src/content/6-form-input/1-input-text/purify.js/util-bind.ts +++ b/apps/compare/src/content/6-form-input/1-input-text/purify.js/util-bind.ts @@ -1,24 +1,20 @@ import { Lifecycle, Signal } from "@purifyjs/core"; -export function useBind< - T, - P extends keyof HTMLElement | (string & {}), ->( - signal: Signal.State, - propertyName: P, - eventName: keyof HTMLElementEventMap | (string & {}), -): Lifecycle.OnConnected { +export function useBindText( + signal: Signal.State, +): Lifecycle.OnConnected { return (element) => { - const handler = () => (signal.val = element[propertyName]); - element.addEventListener(eventName, handler); + const listener = () => (signal.val = element.value); + element.addEventListener("input", listener); + const unfollow = signal.follow( - (value) => element[propertyName] === value, + (value) => (element.value = value), true, ); return () => { unfollow(); - element.removeEventListener(eventName, handler); + element.removeEventListener("input", listener); }; }; } diff --git a/jsr.json b/jsr.json index 02c0058..b0664ac 100644 --- a/jsr.json +++ b/jsr.json @@ -1,6 +1,6 @@ { "name": "@purifyjs/core", - "version": "0.0.329", + "version": "0.0.330", "exports": { ".": "./lib/mod.ts", "./aria": "./lib/aria.ts"