avoid double intro

pull/1529/head
Rich Harris 7 years ago
parent 52032bef8f
commit 1cd55d1f2b

@ -166,18 +166,11 @@ export default class Block {
toString() { toString() {
const { dev } = this.compiler.options; const { dev } = this.compiler.options;
let introing; let current;
const hasIntros = !this.builders.intro.isEmpty(); if (this.hasIntroMethod || this.hasOutroMethod) {
if (hasIntros) { current = this.getUniqueName('current');
introing = this.getUniqueName('introing'); this.addVariable(current);
this.addVariable(introing); this.builders.mount.addLine(`${current} = true;`);
}
let outroing;
const hasOutros = !this.builders.outro.isEmpty();
if (hasOutros) {
outroing = this.alias('outroing');
this.addVariable(outroing);
} }
if (this.autofocus) { if (this.autofocus) {
@ -275,46 +268,30 @@ export default class Block {
} }
if (this.hasIntroMethod || this.hasOutroMethod) { if (this.hasIntroMethod || this.hasOutroMethod) {
if (hasIntros) { if (this.builders.mount.isEmpty() && this.builders.outro.isEmpty()) {
properties.addBlock(deindent`
${dev ? 'i: function intro' : 'i'}(#target, anchor) {
if (${introing}) return;
${introing} = true;
${hasOutros && `${outroing} = false;`}
${this.builders.intro}
this.m(#target, anchor);
},
`);
} else {
if (this.builders.mount.isEmpty()) {
properties.addBlock(`i: @noop,`); properties.addBlock(`i: @noop,`);
properties.addBlock(`o: @run,`);
} else { } else {
properties.addBlock(deindent` properties.addBlock(deindent`
${dev ? 'i: function intro' : 'i'}(#target, anchor) { ${dev ? 'i: function intro' : 'i'}(#target, anchor) {
console.trace("intro", #component.constructor.name, ${current});
if (${current}) return;
${this.builders.intro}
this.m(#target, anchor); this.m(#target, anchor);
}, },
`); `);
}
}
if (hasOutros) {
properties.addBlock(deindent` properties.addBlock(deindent`
${dev ? 'o: function outro' : 'o'}(#outrocallback) { ${dev ? 'o: function outro' : 'o'}(#outrocallback) {
if (${outroing}) return; console.trace("outro", #component.constructor.name, ${current});
${outroing} = true; if (!${current}) return;
${hasIntros && `${introing} = false;`} ${current} = false;
${this.outros > 1 && `#outrocallback = @callAfter(#outrocallback, ${this.outros});`} ${this.outros > 1 && `#outrocallback = @callAfter(#outrocallback, ${this.outros});`}
${this.builders.outro} ${this.builders.outro}
}, },
`); `);
} else {
properties.addBlock(deindent`
o: @run,
`);
} }
} }

Loading…
Cancel
Save