File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed
packages/svelte/tests/runtime-runes/samples/toStore-teardown Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ import { flushSync } from 'svelte' ;
2+ import { test } from '../../test' ;
3+
4+ export default test ( {
5+ async test ( { assert, target } ) {
6+ let [ , btn2 ] = target . querySelectorAll ( 'button' ) ;
7+
8+ btn2 . click ( ) ;
9+ flushSync ( ) ;
10+
11+ assert . htmlEqual ( target . innerHTML , `<button>Set data</button><button>Clear data</button>` ) ;
12+ }
13+ } ) ;
Original file line number Diff line number Diff line change 1+ <script >
2+ import { toStore } from ' svelte/store'
3+
4+ let { data } = $props ()
5+ const currentValue = toStore (() => data .value )
6+ </script >
7+
8+ <p >
9+ Current value:
10+ <span >{$currentValue }</span >
11+ </p >
Original file line number Diff line number Diff line change 1+ <script >
2+ import Child from ' ./child.svelte'
3+
4+ let data = $state ({ value: ' hello' });
5+
6+ const setData = () => (data = { value: ' hello' })
7+ const clearData = () => (data = undefined )
8+ </script >
9+
10+ <button onclick ={setData }>Set data</button >
11+ <button onclick ={clearData }>Clear data</button >
12+
13+ {#if data }
14+ <Child {data } />
15+ {/if }
You can’t perform that action at this time.
0 commit comments