From 4003b3fd8279d165054300c7572fa943cd885b18 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 24 Oct 2018 09:38:19 -0400 Subject: [PATCH 1/2] detach each block iterations with no update method - fixes #1795 --- src/compile/render-dom/wrappers/EachBlock.ts | 2 +- .../samples/each-block-index-only/_config.js | 27 +++++++++++++++++++ .../samples/each-block-index-only/main.html | 3 +++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/each-block-index-only/_config.js create mode 100644 test/runtime/samples/each-block-index-only/main.html diff --git a/src/compile/render-dom/wrappers/EachBlock.ts b/src/compile/render-dom/wrappers/EachBlock.ts index c26d2a07b0..22515206c1 100644 --- a/src/compile/render-dom/wrappers/EachBlock.ts +++ b/src/compile/render-dom/wrappers/EachBlock.ts @@ -462,7 +462,7 @@ export default class EachBlockWrapper extends Wrapper { `; } else { destroy = deindent` - for (; #i < ${iterations}.length; #i += 1) { + for (${this.block.hasUpdateMethod ? `` : `#i = ${this.vars.each_block_value}.${length}`}; #i < ${iterations}.length; #i += 1) { ${iterations}[#i].d(1); } ${iterations}.length = ${this.vars.each_block_value}.${length}; diff --git a/test/runtime/samples/each-block-index-only/_config.js b/test/runtime/samples/each-block-index-only/_config.js new file mode 100644 index 0000000000..33184f7407 --- /dev/null +++ b/test/runtime/samples/each-block-index-only/_config.js @@ -0,0 +1,27 @@ +export default { + data: { + things: [0, 0, 0, 0, 0] + }, + + html: ` +

0

+

1

+

2

+

3

+

4

+ `, + + test(assert, component, target) { + console.group('set'); + component.set({ + things: [0, 0, 0] + }); + console.groupEnd(); + + assert.htmlEqual(target.innerHTML, ` +

0

+

1

+

2

+ `); + } +}; diff --git a/test/runtime/samples/each-block-index-only/main.html b/test/runtime/samples/each-block-index-only/main.html new file mode 100644 index 0000000000..83fb0e6b8e --- /dev/null +++ b/test/runtime/samples/each-block-index-only/main.html @@ -0,0 +1,3 @@ +{#each things as _, i} +

{i}

+{/each} From a1ec36414ed0300c9aedffe33e6790b4d0e2901d Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 24 Oct 2018 09:39:13 -0400 Subject: [PATCH 2/2] remove leftover logging --- test/runtime/samples/each-block-index-only/_config.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/runtime/samples/each-block-index-only/_config.js b/test/runtime/samples/each-block-index-only/_config.js index 33184f7407..8250f94cf7 100644 --- a/test/runtime/samples/each-block-index-only/_config.js +++ b/test/runtime/samples/each-block-index-only/_config.js @@ -12,11 +12,9 @@ export default { `, test(assert, component, target) { - console.group('set'); component.set({ things: [0, 0, 0] }); - console.groupEnd(); assert.htmlEqual(target.innerHTML, `

0