pull/3539/head
Rich Harris 6 years ago
parent af1057b4a3
commit e2d6ce1de5

@ -394,7 +394,7 @@ export default class Block {
} }
render() { render() {
const key = this.key && { type: 'Identifier', name: this.get_unique_name('key') }; const key = this.key && this.get_unique_name('key');
const args: any[] = [x`#ctx`]; const args: any[] = [x`#ctx`];

@ -209,7 +209,7 @@ export default class EachBlockWrapper extends Wrapper {
const initial_anchor_node: Identifier = { type: 'Identifier', name: parent_node ? 'null' : 'anchor' }; const initial_anchor_node: Identifier = { type: 'Identifier', name: parent_node ? 'null' : 'anchor' };
const initial_mount_node: Identifier = { type: 'Identifier', name: parent_node || '#target' }; const initial_mount_node: Identifier = { type: 'Identifier', name: parent_node || '#target' };
const update_anchor_node = needs_anchor const update_anchor_node = needs_anchor
? block.get_unique_name(`${this.var}_anchor`) ? block.get_unique_name(`${this.var.name}_anchor`)
: (this.next && this.next.var) || { type: 'Identifier', name: 'null' }; : (this.next && this.next.var) || { type: 'Identifier', name: 'null' };
const update_mount_node: Identifier = this.get_update_mount_node((update_anchor_node as Identifier)); const update_mount_node: Identifier = this.get_update_mount_node((update_anchor_node as Identifier));
@ -333,7 +333,7 @@ export default class EachBlockWrapper extends Wrapper {
} = this.vars; } = this.vars;
const get_key = block.get_unique_name('get_key'); const get_key = block.get_unique_name('get_key');
const lookup = block.get_unique_name(`${this.var}_lookup`); const lookup = block.get_unique_name(`${this.var.name}_lookup`);
block.add_variable(iterations, x`[]`); block.add_variable(iterations, x`[]`);
block.add_variable(lookup, x`new @_Map()`); block.add_variable(lookup, x`new @_Map()`);
@ -351,9 +351,7 @@ export default class EachBlockWrapper extends Wrapper {
} }
block.chunks.init.push(b` block.chunks.init.push(b`
const ${get_key} = #ctx => ${ const ${get_key} = #ctx => ${this.node.key.manipulate(block)};
// @ts-ignore todo: probably error
this.node.key.render()};
for (let #i = 0; #i < ${data_length}; #i += 1) { for (let #i = 0; #i < ${data_length}; #i += 1) {
let child_ctx = ${this.vars.get_each_context}(#ctx, ${this.vars.each_block_value}, #i); let child_ctx = ${this.vars.get_each_context}(#ctx, ${this.vars.each_block_value}, #i);
@ -395,11 +393,11 @@ export default class EachBlockWrapper extends Wrapper {
block.chunks.update.push(b` block.chunks.update.push(b`
const ${this.vars.each_block_value} = ${snippet}; const ${this.vars.each_block_value} = ${snippet};
${this.block.has_outros && `@group_outros();`} ${this.block.has_outros && b`@group_outros();`}
${this.node.has_animation && `for (let #i = 0; #i < ${view_length}; #i += 1) ${iterations}[#i].r();`} ${this.node.has_animation && b`for (let #i = 0; #i < ${view_length}; #i += 1) ${iterations}[#i].r();`}
${iterations} = @update_keyed_each(${iterations}, changed, ${get_key}, ${dynamic ? '1' : '0'}, #ctx, ${this.vars.each_block_value}, ${lookup}, ${update_mount_node}, ${destroy}, ${create_each_block}, ${update_anchor_node}, ${this.vars.get_each_context}); ${iterations} = @update_keyed_each(${iterations}, #changed, ${get_key}, ${dynamic ? '1' : '0'}, #ctx, ${this.vars.each_block_value}, ${lookup}, ${update_mount_node}, ${destroy}, ${create_each_block}, ${update_anchor_node}, ${this.vars.get_each_context});
${this.node.has_animation && `for (let #i = 0; #i < ${view_length}; #i += 1) ${iterations}[#i].a();`} ${this.node.has_animation && b`for (let #i = 0; #i < ${view_length}; #i += 1) ${iterations}[#i].a();`}
${this.block.has_outros && `@check_outros();`} ${this.block.has_outros && b`@check_outros();`}
`); `);
if (this.block.has_outros) { if (this.block.has_outros) {

@ -177,7 +177,7 @@ export default class IfBlockWrapper extends Wrapper {
const needs_anchor = this.next ? !this.next.is_dom_node() : !parent_node || !this.parent.is_dom_node(); const needs_anchor = this.next ? !this.next.is_dom_node() : !parent_node || !this.parent.is_dom_node();
const anchor = needs_anchor const anchor = needs_anchor
? block.get_unique_name(`${name}_anchor`) ? block.get_unique_name(`${this.var.name}_anchor`)
: (this.next && this.next.var) || 'null'; : (this.next && this.next.var) || 'null';
const has_else = !(this.branches[this.branches.length - 1].condition); const has_else = !(this.branches[this.branches.length - 1].condition);

@ -49,7 +49,7 @@ export default class Wrapper {
// children need to be created first // children need to be created first
const needs_anchor = this.next ? !this.next.is_dom_node() : !parent_node || !this.parent.is_dom_node(); const needs_anchor = this.next ? !this.next.is_dom_node() : !parent_node || !this.parent.is_dom_node();
const anchor = needs_anchor const anchor = needs_anchor
? block.get_unique_name(`${this.var}_anchor`) ? block.get_unique_name(`${this.var.name}_anchor`)
: (this.next && this.next.var) || { type: 'Identifier', name: 'null' }; : (this.next && this.next.var) || { type: 'Identifier', name: 'null' };
if (needs_anchor) { if (needs_anchor) {

Loading…
Cancel
Save