Created
April 26, 2024 13:43
-
-
Save tzachbon/92017737cab63d071a4e5858bb370e8e to your computer and use it in GitHub Desktop.
Simple effect method based on the https://github.com/tc39/proposal-signals
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Signal } from 'signal-polyfill'; | |
| import { effect } from 'signal-effect'; | |
| export function setupCounter(element: HTMLButtonElement) { | |
| const counter = new Signal.State(0); | |
| effect(() => (element.innerText = String(counter.get()))); | |
| element.addEventListener('click', () => counter.set(counter.get() + 1)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment