File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed
packages/svelte/tests/runtime-runes/samples/each-updates-9 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+ async test ( { assert, target, logs } ) {
6+ const [ btn1 ] = target . querySelectorAll ( 'button' ) ;
7+
8+ btn1 . click ( ) ;
9+ flushSync ( ) ;
10+
11+ await Promise . resolve ( ) ;
12+ await Promise . resolve ( ) ;
13+
14+ assert . deepEqual ( logs , [ 'cleanup' ] ) ;
15+ }
16+ } ) ;
Original file line number Diff line number Diff line change 1+ <script >
2+ import { createSubscriber } from ' svelte/reactivity' ;
3+
4+ class MyStore {
5+ #subscribe;
6+ #data = $state ([
7+ [' a' , [1 , 2 ]],
8+ [' b' , [3 , 4 ]]
9+ ]);
10+ #id;
11+
12+ constructor (options ) {
13+ options? .someBoolean ;
14+ this .#id = options? .id ;
15+ this .#subscribe = createSubscriber (() => {
16+ debugger
17+ return () => {
18+ console .log (' cleanup' );
19+ };
20+ });
21+ }
22+
23+ get data () {
24+ this .#subscribe ();
25+ return this .#data;
26+ }
27+ set data (v ) {
28+ this .#data = v;
29+ }
30+ }
31+
32+ let storeOptions = $state ({
33+ someBoolean: false ,
34+ id: 0
35+ });
36+
37+ let myStore = $derived (new MyStore (storeOptions));
38+ < / script>
39+
40+ < button
41+ onclick= {() => {
42+ storeOptions .someBoolean = ! storeOptions .someBoolean ;
43+ }}> + < / button
44+ >
45+
46+ {#each myStore .data as _}{/ each}
You can’t perform that action at this time.
0 commit comments