Skip to content

Instantly share code, notes, and snippets.

@tzachbon
Created April 26, 2024 13:43
Show Gist options
  • Select an option

  • Save tzachbon/92017737cab63d071a4e5858bb370e8e to your computer and use it in GitHub Desktop.

Select an option

Save tzachbon/92017737cab63d071a4e5858bb370e8e to your computer and use it in GitHub Desktop.
Simple effect method based on the https://github.com/tc39/proposal-signals
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