-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73204af
commit 9236d04
Showing
2 changed files
with
28 additions
and
65 deletions.
There are no files selected for viewing
This file contains 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
52 changes: 8 additions & 44 deletions
52
packages/svelte/tests/runtime-runes/samples/derived-dependencies-2/main.svelte
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,13 @@ | ||
<script> | ||
import { writable } from "svelte/store"; | ||
let a = $state(true); | ||
let b = $state({ c: true }); | ||
const store = writable({ | ||
url: { | ||
pathname: '123' | ||
} | ||
}) | ||
const page = { | ||
subscribe(fn) { | ||
return store.subscribe(fn); | ||
} | ||
} | ||
let data = $state({ | ||
event: { | ||
author: 'John Doe', | ||
body: 'Body', | ||
foo: '123' | ||
}, | ||
}); | ||
const { event } = $derived(data); | ||
const x = $derived(b); | ||
</script> | ||
|
||
{#if event} | ||
<h1>{event.author}</h1> | ||
<p>{event.body}</p> | ||
<div>{$page.url.pathname}</div> | ||
{/if} | ||
|
||
<button onclick={() => { | ||
data = {} | ||
store.update(v => ({...v})); | ||
}}>hide</button> | ||
|
||
<button onclick={() => { | ||
data = { | ||
event: { | ||
author: 'John Doe', | ||
body: 'Body', | ||
foo: '123' | ||
}, | ||
} | ||
queueMicrotask(() => { | ||
store.update(v => ({...v})); | ||
}) | ||
}}>show</button> | ||
<button onclick={() => (a = !a)}>toggle a</button> | ||
<button onclick={() => (b = b ? null : { c: true })}>toggle b</button> | ||
|
||
{#if x} | ||
{a}/{x.c}/{x.c} | ||
{/if} |
You only need them because you were using
queueMicrotask
— if you just do the state update separately it becomes unnecessary