File tree 4 files changed +94
-3
lines changed
src/compiler/compile/render_dom/wrappers/InlineComponent
test/runtime/samples/component-binding-store
4 files changed +94
-3
lines changed Original file line number Diff line number Diff line change @@ -359,18 +359,25 @@ export default class InlineComponentWrapper extends Wrapper {
359
359
args . push ( renderer . reference ( name ) ) ;
360
360
} ) ;
361
361
362
-
363
362
block . chunks . init . push ( b `
364
363
function ${ id } (#value) {
365
- ${ callee } .call(null, #value, ${ args } );
364
+ if (!${ updating } ) {
365
+ ${ updating } = true;
366
+ ${ callee } .call(null, #value, ${ args } );
367
+ @add_flush_callback(() => ${ updating } = false);
368
+ }
366
369
}
367
370
` ) ;
368
371
369
372
block . maintain_context = true ; // TODO put this somewhere more logical
370
373
} else {
371
374
block . chunks . init . push ( b `
372
375
function ${ id } (#value) {
373
- ${ callee } .call(null, #value);
376
+ if (!${ updating } ) {
377
+ ${ updating } = true;
378
+ ${ callee } .call(null, #value);
379
+ @add_flush_callback(() => ${ updating } = false);
380
+ }
374
381
}
375
382
` ) ;
376
383
}
Original file line number Diff line number Diff line change
1
+ <script >
2
+ export let value = ' ' ;
3
+ </script >
4
+
5
+ <input bind:value />
Original file line number Diff line number Diff line change
1
+ export default {
2
+ html : `
3
+ <input />
4
+ <input />
5
+ <div></div>
6
+ ` ,
7
+
8
+ async test ( { assert, component, target, window } ) {
9
+ let count = 0 ;
10
+ component . callback = ( ) => {
11
+ count ++ ;
12
+ } ;
13
+
14
+ const [ input1 , input2 ] = target . querySelectorAll ( "input" ) ;
15
+
16
+ input1 . value = "1" ;
17
+ await input1 . dispatchEvent ( new window . Event ( "input" ) ) ;
18
+
19
+ assert . htmlEqual (
20
+ target . innerHTML ,
21
+ `
22
+ <input />
23
+ <input />
24
+ <div>1</div>
25
+ `
26
+ ) ;
27
+ assert . equal ( input1 . value , "1" ) ;
28
+ assert . equal ( input2 . value , "1" ) ;
29
+ assert . equal ( count , 1 ) ;
30
+
31
+ input2 . value = "123" ;
32
+ await input2 . dispatchEvent ( new window . Event ( "input" ) ) ;
33
+
34
+ assert . htmlEqual (
35
+ target . innerHTML ,
36
+ `
37
+ <input />
38
+ <input />
39
+ <div>123</div>
40
+ `
41
+ ) ;
42
+ assert . equal ( input1 . value , "123" ) ;
43
+ assert . equal ( input2 . value , "123" ) ;
44
+ assert . equal ( count , 2 ) ;
45
+
46
+ input1 . value = "456" ;
47
+ await input1 . dispatchEvent ( new window . Event ( "input" ) ) ;
48
+
49
+ assert . htmlEqual (
50
+ target . innerHTML ,
51
+ `
52
+ <input />
53
+ <input />
54
+ <div>456</div>
55
+ `
56
+ ) ;
57
+ assert . equal ( input1 . value , "456" ) ;
58
+ assert . equal ( input2 . value , "456" ) ;
59
+ assert . equal ( count , 3 ) ;
60
+ } ,
61
+ } ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ import { writable } from ' svelte/store' ;
3
+ import Input from ' ./Input.svelte' ;
4
+
5
+ let value = writable ({ value: ' ' });
6
+
7
+ export let callback = () => {};
8
+
9
+ value .subscribe (() => {
10
+ callback ();
11
+ })
12
+ </script >
13
+
14
+ <input bind:value ={$value .value } />
15
+
16
+ <Input bind:value ={$value .value }/>
17
+
18
+ <div >{$value .value }</div >
You can’t perform that action at this time.
0 commit comments