track whether transition is local

pull/2008/head
Richard Harris 7 years ago
parent 9ca925eebe
commit 53b17b4cd3

@ -7,6 +7,7 @@ export default class Transition extends Node {
name: string; name: string;
directive: string; directive: string;
expression: Expression; expression: Expression;
is_local: boolean;
constructor(component: Component, parent, scope, info) { constructor(component: Component, parent, scope, info) {
super(component, parent, scope, info); super(component, parent, scope, info);
@ -15,6 +16,7 @@ export default class Transition extends Node {
this.name = info.name; this.name = info.name;
this.directive = info.intro && info.outro ? 'transition' : info.intro ? 'in' : 'out'; this.directive = info.intro && info.outro ? 'transition' : info.intro ? 'in' : 'out';
this.is_local = info.modifiers.includes('local');
if ((info.intro && parent.intro) || (info.outro && parent.outro)) { if ((info.intro && parent.intro) || (info.outro && parent.outro)) {
const parentTransition = (parent.intro || parent.outro); const parentTransition = (parent.intro || parent.outro);

@ -327,7 +327,7 @@ export default class Block {
properties.addLine(`i: @noop,`); properties.addLine(`i: @noop,`);
} else { } else {
properties.addBlock(deindent` properties.addBlock(deindent`
${dev ? 'i: function intro' : 'i'}() { ${dev ? 'i: function intro' : 'i'}(#local) {
${this.hasOutros && `if (#current) return;`} ${this.hasOutros && `if (#current) return;`}
${this.builders.intro} ${this.builders.intro}
}, },
@ -338,7 +338,7 @@ export default class Block {
properties.addLine(`o: @noop,`); properties.addLine(`o: @noop,`);
} else { } else {
properties.addBlock(deindent` properties.addBlock(deindent`
${dev ? 'o: function outro' : 'o'}() { ${dev ? 'o: function outro' : 'o'}(#local) {
${this.builders.outro} ${this.builders.outro}
}, },
`); `);

@ -403,7 +403,7 @@ export default class EachBlockWrapper extends Wrapper {
const outroBlock = this.block.hasOutros && block.getUniqueName('outroBlock') const outroBlock = this.block.hasOutros && block.getUniqueName('outroBlock')
if (outroBlock) { if (outroBlock) {
block.builders.init.addBlock(deindent` block.builders.init.addBlock(deindent`
function ${outroBlock}(i, detach) { function ${outroBlock}(i, detach, local) {
if (${iterations}[i]) { if (${iterations}[i]) {
if (detach) { if (detach) {
@on_outro(() => { @on_outro(() => {
@ -412,7 +412,7 @@ export default class EachBlockWrapper extends Wrapper {
}); });
} }
${iterations}[i].o(); ${iterations}[i].o(local);
} }
} }
`); `);
@ -434,27 +434,27 @@ export default class EachBlockWrapper extends Wrapper {
${iterations}[#i].c(); ${iterations}[#i].c();
${iterations}[#i].m(${updateMountNode}, ${anchor}); ${iterations}[#i].m(${updateMountNode}, ${anchor});
} }
${has_transitions && `${iterations}[#i].i();`} ${has_transitions && `${iterations}[#i].i(1);`}
` `
: deindent` : deindent`
${iterations}[#i] = ${create_each_block}(child_ctx); ${iterations}[#i] = ${create_each_block}(child_ctx);
${iterations}[#i].c(); ${iterations}[#i].c();
${iterations}[#i].m(${updateMountNode}, ${anchor}); ${iterations}[#i].m(${updateMountNode}, ${anchor});
${has_transitions && `${iterations}[#i].i();`} ${has_transitions && `${iterations}[#i].i(1);`}
`; `;
const start = this.block.hasUpdateMethod ? '0' : `${iterations}.length`; const start = this.block.hasUpdateMethod ? '0' : `${iterations}.length`;
let destroy; let remove_old_blocks;
if (this.block.hasOutros) { if (this.block.hasOutros) {
destroy = deindent` remove_old_blocks = deindent`
@group_outros(); @group_outros();
for (; #i < ${iterations}.length; #i += 1) ${outroBlock}(#i, 1); for (; #i < ${iterations}.length; #i += 1) ${outroBlock}(#i, 1, 1);
@check_outros(); @check_outros();
`; `;
} else { } else {
destroy = deindent` remove_old_blocks = deindent`
for (${this.block.hasUpdateMethod ? `` : `#i = ${this.vars.each_block_value}.${length}`}; #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}[#i].d(1);
} }
@ -471,7 +471,7 @@ export default class EachBlockWrapper extends Wrapper {
${forLoopBody} ${forLoopBody}
} }
${destroy} ${remove_old_blocks}
`; `;
block.builders.update.addBlock(deindent` block.builders.update.addBlock(deindent`

@ -622,17 +622,34 @@ export default class ElementWrapper extends Wrapper {
const fn = component.qualify(intro.name); const fn = component.qualify(intro.name);
block.builders.intro.addBlock(deindent` const intro_block = deindent`
@add_render_callback(() => { @add_render_callback(() => {
if (!${name}) ${name} = @create_bidirectional_transition(${this.var}, ${fn}, ${snippet}, true); if (!${name}) ${name} = @create_bidirectional_transition(${this.var}, ${fn}, ${snippet}, true);
${name}.run(1); ${name}.run(1);
}); });
`); `;
block.builders.outro.addBlock(deindent` const outro_block = deindent`
if (!${name}) ${name} = @create_bidirectional_transition(${this.var}, ${fn}, ${snippet}, false); if (!${name}) ${name} = @create_bidirectional_transition(${this.var}, ${fn}, ${snippet}, false);
${name}.run(0); ${name}.run(0);
`;
if (intro.is_local) {
block.builders.intro.addBlock(deindent`
if (#local) {
${intro_block}
}
`);
block.builders.outro.addBlock(deindent`
if (#local) {
${outro_block}
}
`); `);
} else {
block.builders.intro.addBlock(intro_block);
block.builders.outro.addBlock(outro_block);
}
block.builders.destroy.addConditional('detach', `if (${name}) ${name}.end();`); block.builders.destroy.addConditional('detach', `if (${name}) ${name}.end();`);
} }
@ -649,25 +666,37 @@ export default class ElementWrapper extends Wrapper {
const fn = component.qualify(intro.name); const fn = component.qualify(intro.name);
let intro_block;
if (outro) { if (outro) {
block.builders.intro.addBlock(deindent` intro_block = deindent`
@add_render_callback(() => { @add_render_callback(() => {
if (!${introName}) ${introName} = @create_in_transition(${this.var}, ${fn}, ${snippet}); if (!${introName}) ${introName} = @create_in_transition(${this.var}, ${fn}, ${snippet});
${introName}.start(); ${introName}.start();
}); });
`); `;
block.builders.outro.addLine(`if (${introName}) ${introName}.invalidate()`); block.builders.outro.addLine(`if (${introName}) ${introName}.invalidate()`);
} else { } else {
block.builders.intro.addBlock(deindent` intro_block = deindent`
if (!${introName}) { if (!${introName}) {
@add_render_callback(() => { @add_render_callback(() => {
${introName} = @create_in_transition(${this.var}, ${fn}, ${snippet}); ${introName} = @create_in_transition(${this.var}, ${fn}, ${snippet});
${introName}.start(); ${introName}.start();
}); });
} }
`); `;
} }
if (intro.is_local) {
intro_block = deindent`
if (#local) {
${intro_block}
}
`;
}
block.builders.intro.addBlock(intro_block);
} }
if (outro) { if (outro) {
@ -684,9 +713,19 @@ export default class ElementWrapper extends Wrapper {
// TODO hide elements that have outro'd (unless they belong to a still-outroing // TODO hide elements that have outro'd (unless they belong to a still-outroing
// group) prior to their removal from the DOM // group) prior to their removal from the DOM
block.builders.outro.addBlock(deindent` let outro_block = deindent`
${outroName} = @create_out_transition(${this.var}, ${fn}, ${snippet}); ${outroName} = @create_out_transition(${this.var}, ${fn}, ${snippet});
`); `;
if (outro_block) {
outro_block = deindent`
if (#local) {
${outro_block}
}
`;
}
block.builders.outro.addBlock(outro_block);
block.builders.destroy.addConditional('detach', `if (${outroName}) ${outroName}.end();`); block.builders.destroy.addConditional('detach', `if (${outroName}) ${outroName}.end();`);
} }

@ -239,7 +239,7 @@ export default class IfBlockWrapper extends Wrapper {
if (${name}) { if (${name}) {
${name}.c(); ${name}.c();
${name}.m(${updateMountNode}, ${anchor}); ${name}.m(${updateMountNode}, ${anchor});
${has_transitions && `${name}.i();`} ${has_transitions && `${name}.i(1);`}
} }
`; `;
@ -327,7 +327,7 @@ export default class IfBlockWrapper extends Wrapper {
${if_blocks}[${previous_block_index}].d(1); ${if_blocks}[${previous_block_index}].d(1);
${if_blocks}[${previous_block_index}] = null; ${if_blocks}[${previous_block_index}] = null;
}); });
${name}.o(); ${name}.o(1);
@check_outros(); @check_outros();
`; `;
@ -338,7 +338,7 @@ export default class IfBlockWrapper extends Wrapper {
${name}.c(); ${name}.c();
} }
${name}.m(${updateMountNode}, ${anchor}); ${name}.m(${updateMountNode}, ${anchor});
${has_transitions && `${name}.i();`} ${has_transitions && `${name}.i(1);`}
`; `;
const changeBlock = hasElse const changeBlock = hasElse
@ -415,7 +415,7 @@ export default class IfBlockWrapper extends Wrapper {
${name}.c(); ${name}.c();
${name}.m(${updateMountNode}, ${anchor}); ${name}.m(${updateMountNode}, ${anchor});
} }
${has_transitions && `${name}.i();`} ${has_transitions && `${name}.i(1);`}
` `
: deindent` : deindent`
if (!${name}) { if (!${name}) {
@ -423,7 +423,7 @@ export default class IfBlockWrapper extends Wrapper {
${name}.c(); ${name}.c();
${name}.m(${updateMountNode}, ${anchor}); ${name}.m(${updateMountNode}, ${anchor});
} }
${has_transitions && `${name}.i();`} ${has_transitions && `${name}.i(1);`}
`; `;
// no `p()` here — we don't want to update outroing nodes, // no `p()` here — we don't want to update outroing nodes,
@ -436,7 +436,7 @@ export default class IfBlockWrapper extends Wrapper {
${name} = null; ${name} = null;
}); });
${name}.o(); ${name}.o(1);
@check_outros(); @check_outros();
` `
: deindent` : deindent`

@ -397,7 +397,7 @@ export default class InlineComponentWrapper extends Wrapper {
@on_outro(() => { @on_outro(() => {
old_component.$destroy(); old_component.$destroy();
}); });
old_component.$$.fragment.o(); old_component.$$.fragment.o(1);
@check_outros(); @check_outros();
} }
@ -409,7 +409,7 @@ export default class InlineComponentWrapper extends Wrapper {
${name}.$$.fragment.c(); ${name}.$$.fragment.c();
@mount_component(${name}, ${updateMountNode}, ${anchor}); @mount_component(${name}, ${updateMountNode}, ${anchor});
${name}.$$.fragment.i(); ${name}.$$.fragment.i(1);
} else { } else {
${name} = null; ${name} = null;
} }
@ -417,7 +417,7 @@ export default class InlineComponentWrapper extends Wrapper {
`); `);
block.builders.intro.addBlock(deindent` block.builders.intro.addBlock(deindent`
if (${name}) ${name}.$$.fragment.i(); if (${name}) ${name}.$$.fragment.i(#local);
`); `);
if (updates.length) { if (updates.length) {
@ -430,6 +430,10 @@ export default class InlineComponentWrapper extends Wrapper {
`); `);
} }
block.builders.outro.addLine(
`if (${name}) ${name}.$$.fragment.o(#local);`
);
block.builders.destroy.addLine(`if (${name}) ${name}.$destroy(${parentNode ? '' : 'detach'});`); block.builders.destroy.addLine(`if (${name}) ${name}.$destroy(${parentNode ? '' : 'detach'});`);
} else { } else {
const expression = this.node.name === 'svelte:self' const expression = this.node.name === 'svelte:self'
@ -459,7 +463,7 @@ export default class InlineComponentWrapper extends Wrapper {
); );
block.builders.intro.addBlock(deindent` block.builders.intro.addBlock(deindent`
${name}.$$.fragment.i(); ${name}.$$.fragment.i(#local);
`); `);
if (updates.length) { if (updates.length) {
@ -473,13 +477,13 @@ export default class InlineComponentWrapper extends Wrapper {
block.builders.destroy.addBlock(deindent` block.builders.destroy.addBlock(deindent`
${name}.$destroy(${parentNode ? '' : 'detach'}); ${name}.$destroy(${parentNode ? '' : 'detach'});
`); `);
}
block.builders.outro.addLine( block.builders.outro.addLine(
`if (${name}) ${name}.$$.fragment.o();` `${name}.$$.fragment.o(#local);`
); );
} }
} }
}
function isComputed(node: Node) { function isComputed(node: Node) {
while (node.type === 'MemberExpression') { while (node.type === 'MemberExpression') {

@ -22,7 +22,7 @@ export function handlePromise(promise, info) {
block.d(1); block.d(1);
info.blocks[i] = null; info.blocks[i] = null;
}); });
block.o(); block.o(1);
check_outros(); check_outros();
} }
}); });
@ -32,7 +32,7 @@ export function handlePromise(promise, info) {
block.c(); block.c();
block.m(info.mount(), info.anchor); block.m(info.mount(), info.anchor);
if (block.i) block.i(); if (block.i) block.i(1);
flush(); flush();
} }

@ -10,7 +10,7 @@ export function outroAndDestroyBlock(block, lookup) {
destroyBlock(block, lookup); destroyBlock(block, lookup);
}); });
block.o(); block.o(1);
} }
export function fixAndOutroAndDestroyBlock(block, lookup) { export function fixAndOutroAndDestroyBlock(block, lookup) {
@ -53,7 +53,7 @@ export function updateKeyedEach(old_blocks, changed, get_key, dynamic, ctx, list
function insert(block) { function insert(block) {
block.m(node, next); block.m(node, next);
if (block.i) block.i(); if (block.i) block.i(1);
lookup[block.key] = block; lookup[block.key] = block;
next = block.first; next = block.first;
n--; n--;

Loading…
Cancel
Save