File tree Expand file tree Collapse file tree 2 files changed +64
-0
lines changed
packages/svelte/tests/runtime-runes/samples/transition-each Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { flushSync } from '../../../../src/index-client.js' ;
2
+ import { test } from '../../test' ;
3
+
4
+ export default test ( {
5
+ test ( { assert, raf, target } ) {
6
+ const [ btn1 , btn2 ] = target . querySelectorAll ( 'button' ) ;
7
+
8
+ btn1 ?. click ( ) ;
9
+ btn1 ?. click ( ) ;
10
+ btn1 ?. click ( ) ;
11
+ flushSync ( ) ;
12
+ assert . htmlEqual (
13
+ target . innerHTML ,
14
+ '<button>Push</button><button>Remove</button><ul><li>0</li><li>1</li><li>2</li></ul'
15
+ ) ;
16
+
17
+ btn2 ?. click ( ) ;
18
+ flushSync ( ) ;
19
+ raf . tick ( 50 ) ;
20
+
21
+ const li = /** @type {HTMLElement & { foo: number } } */ ( target . querySelector ( 'ul > li' ) ) ;
22
+
23
+ assert . equal ( li . foo , 0.5 ) ;
24
+
25
+ btn1 ?. click ( ) ;
26
+ flushSync ( ) ;
27
+
28
+ assert . equal ( li . foo , 0.5 ) ;
29
+ assert . htmlEqual (
30
+ target . innerHTML ,
31
+ '<button>Push</button><button>Remove</button><ul><li>0</li><li>1</li><li>2</li><li>3</li></ul'
32
+ ) ;
33
+ }
34
+ } ) ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ function foo (node , params ) {
3
+ return {
4
+ duration: 100 ,
5
+ tick : (t , u ) => {
6
+ node .foo = t;
7
+ }
8
+ };
9
+ }
10
+
11
+ let list = $state ([]);
12
+ let id = 0 ;
13
+
14
+ function push () {
15
+ list .push ({ id: id++ })
16
+ }
17
+
18
+ function removeFirst () {
19
+ list .splice (0 , 1 );
20
+ }
21
+ </script >
22
+
23
+ <button onclick ={push }>Push</button >
24
+ <button onclick ={removeFirst }>Remove</button >
25
+
26
+ <ul >
27
+ {#each list as item (item .id )}
28
+ <li out:foo >{item .id }</li >
29
+ {/each }
30
+ </ul >
You can’t perform that action at this time.
0 commit comments