File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed
packages/svelte/tests/runtime-runes/samples/inspect-deep-array Expand file tree Collapse file tree 2 files changed +62
-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
+ compileOptions : {
6
+ dev : true
7
+ } ,
8
+
9
+ async test ( { target, assert, logs } ) {
10
+ const button = target . querySelector ( 'button' ) ;
11
+
12
+ flushSync ( ( ) => {
13
+ button ?. click ( ) ;
14
+ } ) ;
15
+
16
+ assert . deepEqual ( logs , [
17
+ 'init' ,
18
+ [ 1 , 2 , 3 , 7 ] ,
19
+ 'update' ,
20
+ [ 2 , 2 , 3 , 7 ] ,
21
+ 'update' ,
22
+ [ 2 , 3 , 3 , 7 ] ,
23
+ 'update' ,
24
+ [ 2 , 3 , 7 , 7 ] ,
25
+ 'update' ,
26
+ [ 2 , 3 , 7 ]
27
+ ] ) ;
28
+ }
29
+ } ) ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ function createState (init ) {
3
+ let values = $state (init);
4
+
5
+ return {
6
+ get value () {
7
+ return $state .snapshot (values);
8
+ },
9
+
10
+ get workedValues () {
11
+ let newValue = [];
12
+ for (const value of values) {
13
+ if (value === undefined ) {
14
+ throw new Error (' undefined found' );
15
+ }
16
+
17
+ newValue .push (value);
18
+ }
19
+ return newValue;
20
+ },
21
+
22
+ doSplice () {
23
+ values .splice (0 , 1 );
24
+ }
25
+ };
26
+ }
27
+
28
+ const myState = createState ([1 , 2 , 3 , 7 ]);
29
+
30
+ $inspect (myState .workedValues );
31
+ </script >
32
+
33
+ <button onclick ={() => myState .doSplice ()}>Delete</button >
You can’t perform that action at this time.
0 commit comments