From db5646821d6eb4f684520497bbc108ef346165a1 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 18 Oct 2017 08:51:46 -0400 Subject: [PATCH 1/2] add failing test for each block updates --- .../samples/each-block-destructured-array/_config.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/runtime/samples/each-block-destructured-array/_config.js b/test/runtime/samples/each-block-destructured-array/_config.js index cd29960426..99933effcf 100644 --- a/test/runtime/samples/each-block-destructured-array/_config.js +++ b/test/runtime/samples/each-block-destructured-array/_config.js @@ -9,5 +9,12 @@ export default { html: `

raccoon: hands

eagle: wings

- ` + `, + + test ( assert, component, target ) { + component.set({ animalPawsEntries: [['foo', 'bar']] }); + assert.htmlEqual( target.innerHTML, ` +

foo: bar

+ `); + }, }; From f0aea9b086ad4a40f20fd5f60d130305196219d5 Mon Sep 17 00:00:00 2001 From: Jacob Mischka Date: Wed, 18 Oct 2017 09:43:59 -0500 Subject: [PATCH 2/2] Fix updates for destructured each arrays Add dependencies for destructuredContexts Fixes #896 --- src/generators/dom/preprocess.ts | 13 +++++++------ .../server-side-rendering/visitors/EachBlock.ts | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/generators/dom/preprocess.ts b/src/generators/dom/preprocess.ts index 9b98539897..93e7126afa 100644 --- a/src/generators/dom/preprocess.ts +++ b/src/generators/dom/preprocess.ts @@ -229,12 +229,6 @@ const preprocessors = { const contexts = new Map(block.contexts); contexts.set(node.context, context); - if (node.destructuredContexts) { - for (const i = 0; i < node.destructuredContexts.length; i++) { - contexts.set(node.destructuredContexts[i], `${context}[${i}]`); - } - } - const indexes = new Map(block.indexes); if (node.index) indexes.set(node.index, node.context); @@ -244,6 +238,13 @@ const preprocessors = { const contextDependencies = new Map(block.contextDependencies); contextDependencies.set(node.context, dependencies); + if (node.destructuredContexts) { + for (const i = 0; i < node.destructuredContexts.length; i++) { + contexts.set(node.destructuredContexts[i], `${context}[${i}]`); + contextDependencies.set(node.destructuredContexts[i], dependencies); + } + } + node._block = block.child({ comment: createDebuggingComment(node, generator), name: generator.getUniqueName('create_each_block'), diff --git a/src/generators/server-side-rendering/visitors/EachBlock.ts b/src/generators/server-side-rendering/visitors/EachBlock.ts index 09342bf26b..b2e7c8ad58 100644 --- a/src/generators/server-side-rendering/visitors/EachBlock.ts +++ b/src/generators/server-side-rendering/visitors/EachBlock.ts @@ -18,18 +18,19 @@ export default function visitEachBlock( const contexts = new Map(block.contexts); contexts.set(node.context, node.context); - if (node.destructuredContexts) { - for (const i = 0; i < node.destructuredContexts.length; i++) { - contexts.set(node.destructuredContexts[i], `${node.context}[${i}]`); - } - } - const indexes = new Map(block.indexes); if (node.index) indexes.set(node.index, node.context); const contextDependencies = new Map(block.contextDependencies); contextDependencies.set(node.context, dependencies); + if (node.destructuredContexts) { + for (const i = 0; i < node.destructuredContexts.length; i++) { + contexts.set(node.destructuredContexts[i], `${node.context}[${i}]`); + contextDependencies.set(node.destructuredContexts[i], dependencies); + } + } + const childBlock = block.child({ contexts, indexes,