From ffa45dd8be004e6f0b6d3d7ad0b7f1c9dba42049 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 18 Mar 2018 18:52:42 -0400 Subject: [PATCH] tweaks --- src/generators/nodes/EachBlock.ts | 2 +- src/shared/keyed-each.js | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/generators/nodes/EachBlock.ts b/src/generators/nodes/EachBlock.ts index ffc95eb485..ba9ffc11a9 100644 --- a/src/generators/nodes/EachBlock.ts +++ b/src/generators/nodes/EachBlock.ts @@ -319,7 +319,7 @@ export default class EachBlock extends Node { block.builders.update.addBlock(deindent` var ${each_block_value} = ${snippet}; - @updateKeyedEach(#component, ${key}, changed, "${this.key}", ${dynamic}, ${each_block_value}, ${head}, ${lookup}, ${updateMountNode}, ${String(this.block.hasOutroMethod)}, ${create_each_block}, function(#i) { + @updateKeyedEach(#component, ${key}, changed, "${this.key}", ${dynamic}, ${each_block_value}, ${head}, ${lookup}, ${updateMountNode}, ${String(this.block.hasOutroMethod)}, ${create_each_block}, "${mountOrIntro}", function(#i) { return @assign({}, state, { ${this.contextProps.join(',\n')} }); diff --git a/src/shared/keyed-each.js b/src/shared/keyed-each.js index d1999d4672..384a96f6ed 100644 --- a/src/shared/keyed-each.js +++ b/src/shared/keyed-each.js @@ -17,7 +17,9 @@ export function outroAndDestroyIteration(iteration, lookup) { }); } -export function updateKeyedEach(component, key, changed, key_prop, dynamic, list, head, lookup, updateMountNode, hasOutroMethod, create_each_block, get_context) { +// TODO is it possible to avoid mounting iterations that are +// already in the right place? +export function updateKeyedEach(component, key, changed, key_prop, dynamic, list, head, lookup, node, has_outro, create_each_block, intro_method, get_context) { var keep = {}; var i = list.length; @@ -36,7 +38,7 @@ export function updateKeyedEach(component, key, changed, key_prop, dynamic, list keep[key] = 1; } - var destroy = hasOutroMethod + var destroy = has_outro ? outroAndDestroyIteration : destroyIteration; @@ -55,7 +57,7 @@ export function updateKeyedEach(component, key, changed, key_prop, dynamic, list var anchor; - if (hasOutroMethod) { + if (has_outro) { var next_key = next && next.key; var neighbour = iteration.next; var anchor_key; @@ -69,7 +71,7 @@ export function updateKeyedEach(component, key, changed, key_prop, dynamic, list anchor = next && next.first; } - iteration[iteration.i ? 'i' : 'm'](updateMountNode, anchor); + iteration[intro_method](node, anchor); iteration.next = next; if (next) next.last = iteration;