File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
packages/svelte/tests/runtime-runes/samples/guard-derived-short-circuit Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { test } from '../../test' ;
2
+ import { flushSync } from 'svelte' ;
3
+
4
+ export default test ( {
5
+ mode : [ 'client' ] ,
6
+ async test ( { target, assert } ) {
7
+ const button = target . querySelector ( 'button' ) ;
8
+
9
+ flushSync ( ( ) => button ?. click ( ) ) ;
10
+
11
+ assert . equal ( target . textContent ?. trim ( ) , 'Trigger' ) ;
12
+ }
13
+ } ) ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ let virtualItems = $state ([{ index: 0 }, { index: 1 }, { index: 2 }]);
3
+ let centerRows = $state ([{ depth: 2 }, { depth: 1 }, { depth: 1 }]);
4
+
5
+ let someChange = $state (false );
6
+ $effect (() => {
7
+ if (someChange) centerRows = [];
8
+ });
9
+ </script >
10
+
11
+ {#each virtualItems as row (row .index )}
12
+ {@const centerRow = centerRows [row .index ]}
13
+ {#if centerRow != undefined && centerRow .depth != undefined && typeof centerRow === " object" && " depth" in centerRow && typeof centerRow .depth === " number" }
14
+ {#if centerRow .depth != undefined && centerRow .depth > 0 }
15
+ Hello World<br />
16
+ {/if }
17
+ {/if }
18
+ {/each }
19
+
20
+ <button onclick ={() => (someChange = true )}>Trigger</button >
You can’t perform that action at this time.
0 commit comments