Skip to content

Commit

Permalink
Merge pull request #1378 from sveltejs/gh-1286
Browse files Browse the repository at this point in the history
recalculate each block values lazily
  • Loading branch information
Rich-Harris authored Apr 29, 2018
2 parents d8ca0e3 + f0bf1ef commit 7246997
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/compile/nodes/EachBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')}
Expand Down
4 changes: 2 additions & 2 deletions test/js/samples/deconflict-builtins/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions test/js/samples/deconflict-builtins/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions test/js/samples/each-block-changed-check/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions test/js/samples/each-block-changed-check/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7246997

Please sign in to comment.