File tree 3 files changed +62
-1
lines changed
test/runtime/samples/event-handler-each-context-invalidation
3 files changed +62
-1
lines changed Original file line number Diff line number Diff line change @@ -364,7 +364,18 @@ export default class Expression {
364
364
let body = code . slice ( node . body . start , node . body . end ) . trim ( ) ;
365
365
if ( node . body . type !== 'BlockStatement' ) {
366
366
if ( pending_assignments . size > 0 ) {
367
- const insert = Array . from ( pending_assignments ) . map ( name => component . invalidate ( name ) ) . join ( '; ' ) ;
367
+ const dependencies = new Set ( ) ;
368
+ pending_assignments . forEach ( name => {
369
+ if ( template_scope . names . has ( name ) ) {
370
+ template_scope . dependencies_for_name . get ( name ) . forEach ( dependency => {
371
+ dependencies . add ( dependency ) ;
372
+ } ) ;
373
+ } else {
374
+ dependencies . add ( name ) ;
375
+ }
376
+ } ) ;
377
+
378
+ const insert = Array . from ( dependencies ) . map ( name => component . invalidate ( name ) ) . join ( '; ' ) ;
368
379
pending_assignments = new Set ( ) ;
369
380
370
381
component . has_reactive_assignments = true ;
Original file line number Diff line number Diff line change
1
+ export default {
2
+ html : `
3
+ <button>off</button>
4
+ <button>on</button>
5
+ <button>off</button>
6
+ <p>on: 1</p>
7
+ ` ,
8
+
9
+ async test ( { assert, component, target, window } ) {
10
+ const buttons = target . querySelectorAll ( 'button' ) ;
11
+ const event = new window . MouseEvent ( 'click' ) ;
12
+
13
+ await buttons [ 0 ] . dispatchEvent ( event ) ;
14
+ assert . htmlEqual ( target . innerHTML , `
15
+ <button>on</button>
16
+ <button>on</button>
17
+ <button>off</button>
18
+ <p>on: 2</p>
19
+ ` ) ;
20
+
21
+ await buttons [ 2 ] . dispatchEvent ( event ) ;
22
+ assert . htmlEqual ( target . innerHTML , `
23
+ <button>on</button>
24
+ <button>on</button>
25
+ <button>on</button>
26
+ <p>on: 3</p>
27
+ ` ) ;
28
+
29
+ assert . deepEqual ( component . switches , [
30
+ { on : true } ,
31
+ { on : true } ,
32
+ { on : true }
33
+ ] ) ;
34
+ }
35
+ } ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ export let switches = [
3
+ { on: false },
4
+ { on: true },
5
+ { on: false }
6
+ ];
7
+ </script >
8
+
9
+ {#each switches as s }
10
+ <button on :click =" {() => s .on = ! s .on }" >
11
+ {s .on ? ' on' : ' off' }
12
+ </button >
13
+ {/each }
14
+
15
+ <p >on: {switches .filter (s => !! s .on ).length }</p >
You can’t perform that action at this time.
0 commit comments