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/effect-dependencies/main.svelte

32 lines
473 B

<script context="module">
class Things {
tab = $state('A');
data = $state([{no: 1}, {no: 2}]);
list = $derived(this.filter());
filter() {
this.tab;
return this.data;
}
}
const things = new Things();
</script>
<div>
<button onclick={() => things.tab = 'A'} >A</button>
<button onclick={() => things.tab = 'B'} >B</button>
</div>
<div>
{#if things.tab === 'A'}
A
{:else}
B
{#each things.list as item}
{item.no}
{/each}
{/if}
</div>