From f0bf1ef8d5814e36b4d556753cfe953755e329b4 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 28 Apr 2018 23:51:05 -0400 Subject: [PATCH] recalculate each block values lazily - fixes #1286 --- src/compile/nodes/EachBlock.ts | 4 ++-- test/js/samples/deconflict-builtins/expected-bundle.js | 4 ++-- test/js/samples/deconflict-builtins/expected.js | 4 ++-- test/js/samples/each-block-changed-check/expected-bundle.js | 4 ++-- test/js/samples/each-block-changed-check/expected.js | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/compile/nodes/EachBlock.ts b/src/compile/nodes/EachBlock.ts index cb58b31411..f96b330064 100644 --- a/src/compile/nodes/EachBlock.ts +++ b/src/compile/nodes/EachBlock.ts @@ -443,9 +443,9 @@ export default class EachBlock extends Node { `; block.builders.update.addBlock(deindent` - var ${each_block_value} = ${snippet}; - if (${condition}) { + ${each_block_value} = ${snippet}; + for (var #i = ${start}; #i < ${each_block_value}.${length}; #i += 1) { var ${this.each_context} = @assign(@assign({}, ctx), { ${this.contextProps.join(',\n')} diff --git a/test/js/samples/deconflict-builtins/expected-bundle.js b/test/js/samples/deconflict-builtins/expected-bundle.js index 4bc21f60a6..b677e75e29 100644 --- a/test/js/samples/deconflict-builtins/expected-bundle.js +++ b/test/js/samples/deconflict-builtins/expected-bundle.js @@ -186,9 +186,9 @@ function create_main_fragment(component, ctx) { }, p: function update(changed, ctx) { - var each_value = ctx.createElement; - if (changed.createElement) { + each_value = ctx.createElement; + for (var i = 0; i < each_value.length; i += 1) { var each_context = assign(assign({}, ctx), { each_value: each_value, diff --git a/test/js/samples/deconflict-builtins/expected.js b/test/js/samples/deconflict-builtins/expected.js index aa928967c4..ce7e2fa52f 100644 --- a/test/js/samples/deconflict-builtins/expected.js +++ b/test/js/samples/deconflict-builtins/expected.js @@ -34,9 +34,9 @@ function create_main_fragment(component, ctx) { }, p: function update(changed, ctx) { - var each_value = ctx.createElement; - if (changed.createElement) { + each_value = ctx.createElement; + for (var i = 0; i < each_value.length; i += 1) { var each_context = assign(assign({}, ctx), { each_value: each_value, diff --git a/test/js/samples/each-block-changed-check/expected-bundle.js b/test/js/samples/each-block-changed-check/expected-bundle.js index 560c0514ae..f4d29ba84a 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -192,9 +192,9 @@ function create_main_fragment(component, ctx) { }, p: function update(changed, ctx) { - var each_value = ctx.comments; - if (changed.comments || changed.elapsed || changed.time) { + each_value = ctx.comments; + for (var i = 0; i < each_value.length; i += 1) { var each_context = assign(assign({}, ctx), { each_value: each_value, diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index 6b15078c79..75dfc20a7d 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -38,9 +38,9 @@ function create_main_fragment(component, ctx) { }, p: function update(changed, ctx) { - var each_value = ctx.comments; - if (changed.comments || changed.elapsed || changed.time) { + each_value = ctx.comments; + for (var i = 0; i < each_value.length; i += 1) { var each_context = assign(assign({}, ctx), { each_value: each_value,