File tree Expand file tree Collapse file tree 3 files changed +71
-0
lines changed
packages/svelte/tests/runtime-runes/samples/non-local-mutation-inherited-owner-6 Expand file tree Collapse file tree 3 files changed +71
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { tick } from 'svelte' ;
2
+ import { test } from '../../test' ;
3
+
4
+ /** @type {typeof console.warn } */
5
+ let warn ;
6
+
7
+ /** @type {any[] } */
8
+ let warnings = [ ] ;
9
+
10
+ export default test ( {
11
+ compileOptions : {
12
+ dev : true
13
+ } ,
14
+
15
+ before_test : ( ) => {
16
+ warn = console . warn ;
17
+
18
+ console . warn = ( ...args ) => {
19
+ warnings . push ( ...args ) ;
20
+ } ;
21
+ } ,
22
+
23
+ after_test : ( ) => {
24
+ console . warn = warn ;
25
+ warnings = [ ] ;
26
+ } ,
27
+
28
+ async test ( { assert, target } ) {
29
+ const btn = target . querySelector ( 'button' ) ;
30
+
31
+ await btn ?. click ( ) ;
32
+ await tick ( ) ;
33
+ assert . deepEqual ( warnings . length , 0 ) ;
34
+ }
35
+ } ) ;
Original file line number Diff line number Diff line change
1
+ <script lang =" ts" >
2
+ import { setContext } from ' svelte' ;
3
+ import Sub from ' ./sub.svelte' ;
4
+
5
+ class Person1 {
6
+ value = $state ({ person: ' John' , age: 33 })
7
+ }
8
+ const class_nested_state = $state (new Person1 ());
9
+
10
+ class Person2 {
11
+ person = $state (' John' );
12
+ age = $state (33 );
13
+ }
14
+ const state_nested_class = $state ({ value: new Person2 () });
15
+
16
+ const nested_state = $state ({ person: ' John' , age: 33 });
17
+
18
+ setContext (' foo' , {
19
+ nested_state ,
20
+ get class_nested_state() { return class_nested_state },
21
+ get state_nested_class() { return state_nested_class }
22
+ })
23
+ </script >
24
+
25
+ <Sub {class_nested_state } {state_nested_class } {nested_state } />
Original file line number Diff line number Diff line change
1
+ <script >
2
+ import { getContext } from " svelte" ;
3
+
4
+ const foo = getContext (' foo' )
5
+ </script >
6
+
7
+ <button onclick ={() => {
8
+ foo .class_nested_state .value .age ++ ;
9
+ foo .state_nested_class .value .age ++ ;
10
+ foo .nested_state .age ++ ;
11
+ }}>mutate</button >
You can’t perform that action at this time.
0 commit comments