From ece6aeb892c8f52c1466247b058c22ff310bd20c Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 24 Oct 2018 09:38:19 -0400 Subject: [PATCH] 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 c26d2a07b092..22515206c15d 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 000000000000..33184f740799 --- /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 000000000000..83fb0e6b8ec6 --- /dev/null +++ b/test/runtime/samples/each-block-index-only/main.html @@ -0,0 +1,3 @@ +{#each things as _, i} +

{i}

+{/each}