You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/packages/svelte/tests/runtime-runes/samples/class-state-constructor/main.svelte

19 lines
325 B

<script>
class Counter {
/** @type {number} */
#count;
constructor(initial) {
this.#count = $state(initial);
this.doubled = $derived(this.#count * 2);
}
increment = () => {
this.#count++;
}
}
const counter = new Counter(10);
</script>
<button onclick={counter.increment}>{counter.doubled}</button>