From df7c449bd357e16d7dc8a2478c2f2fa7f90e1a51 Mon Sep 17 00:00:00 2001 From: Chris Reeves Date: Tue, 15 Jan 2019 18:08:53 -0500 Subject: [PATCH] propagate mutation change tracking upward through deps so that adjacent scopes generate proper update code - fixes #1985 --- src/compile/nodes/shared/TemplateScope.ts | 10 ++++++---- .../_config.js | 12 ++++++++++++ .../main.html | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 test/runtime/samples/mutation-tracking-across-sibling-scopes/_config.js create mode 100644 test/runtime/samples/mutation-tracking-across-sibling-scopes/main.html diff --git a/src/compile/nodes/shared/TemplateScope.ts b/src/compile/nodes/shared/TemplateScope.ts index 45a8895505..c9b81070b8 100644 --- a/src/compile/nodes/shared/TemplateScope.ts +++ b/src/compile/nodes/shared/TemplateScope.ts @@ -1,6 +1,6 @@ export default class TemplateScope { names: Set; - dependenciesForName: Map; + dependenciesForName: Map>; mutables: Set; parent?: TemplateScope; @@ -11,7 +11,7 @@ export default class TemplateScope { this.mutables = new Set(); } - add(name, dependencies) { + add(name, dependencies: Set) { this.names.add(name); this.dependenciesForName.set(name, dependencies); return this; @@ -23,8 +23,10 @@ export default class TemplateScope { } setMutable(name: string) { - if (this.names.has(name)) this.mutables.add(name); - else if (this.parent) this.parent.setMutable(name); + if (this.names.has(name)) { + this.mutables.add(name); + if (this.parent && this.dependenciesForName.has(name)) this.dependenciesForName.get(name).forEach(dep => this.parent.setMutable(dep)); + } else if (this.parent) this.parent.setMutable(name); else this.mutables.add(name); } diff --git a/test/runtime/samples/mutation-tracking-across-sibling-scopes/_config.js b/test/runtime/samples/mutation-tracking-across-sibling-scopes/_config.js new file mode 100644 index 0000000000..038db6dbbb --- /dev/null +++ b/test/runtime/samples/mutation-tracking-across-sibling-scopes/_config.js @@ -0,0 +1,12 @@ +export default { + async test({ assert, component, target }) { + assert.htmlEqual(component.div.innerHTML, '
+
-
'); + + const event = new window.Event('change'); + const input = target.querySelector('input'); + input.checked = false; + await input.dispatchEvent(event); + + assert.htmlEqual(component.div.innerHTML, '
-
-
'); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/mutation-tracking-across-sibling-scopes/main.html b/test/runtime/samples/mutation-tracking-across-sibling-scopes/main.html new file mode 100644 index 0000000000..9ed06657d7 --- /dev/null +++ b/test/runtime/samples/mutation-tracking-across-sibling-scopes/main.html @@ -0,0 +1,18 @@ +{#each things as thing} +
+ +
+{/each} + +
+ {#each things as other} +
+ {other.ok ? '+' : '-'} +
+ {/each} +
+ + \ No newline at end of file