Skip to content

Commit 1cd55d1

Browse files
committed
avoid double intro
1 parent 52032be commit 1cd55d1

File tree

1 file changed

+14
-37
lines changed

1 file changed

+14
-37
lines changed

src/compile/dom/Block.ts

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,11 @@ export default class Block {
166166
toString() {
167167
const { dev } = this.compiler.options;
168168

169-
let introing;
170-
const hasIntros = !this.builders.intro.isEmpty();
171-
if (hasIntros) {
172-
introing = this.getUniqueName('introing');
173-
this.addVariable(introing);
174-
}
175-
176-
let outroing;
177-
const hasOutros = !this.builders.outro.isEmpty();
178-
if (hasOutros) {
179-
outroing = this.alias('outroing');
180-
this.addVariable(outroing);
169+
let current;
170+
if (this.hasIntroMethod || this.hasOutroMethod) {
171+
current = this.getUniqueName('current');
172+
this.addVariable(current);
173+
this.builders.mount.addLine(`${current} = true;`);
181174
}
182175

183176
if (this.autofocus) {
@@ -275,46 +268,30 @@ export default class Block {
275268
}
276269

277270
if (this.hasIntroMethod || this.hasOutroMethod) {
278-
if (hasIntros) {
271+
if (this.builders.mount.isEmpty() && this.builders.outro.isEmpty()) {
272+
properties.addBlock(`i: @noop,`);
273+
properties.addBlock(`o: @run,`);
274+
} else {
279275
properties.addBlock(deindent`
280276
${dev ? 'i: function intro' : 'i'}(#target, anchor) {
281-
if (${introing}) return;
282-
${introing} = true;
283-
${hasOutros && `${outroing} = false;`}
284-
277+
console.trace("intro", #component.constructor.name, ${current});
278+
if (${current}) return;
285279
${this.builders.intro}
286-
287280
this.m(#target, anchor);
288281
},
289282
`);
290-
} else {
291-
if (this.builders.mount.isEmpty()) {
292-
properties.addBlock(`i: @noop,`);
293-
} else {
294-
properties.addBlock(deindent`
295-
${dev ? 'i: function intro' : 'i'}(#target, anchor) {
296-
this.m(#target, anchor);
297-
},
298-
`);
299-
}
300-
}
301283

302-
if (hasOutros) {
303284
properties.addBlock(deindent`
304285
${dev ? 'o: function outro' : 'o'}(#outrocallback) {
305-
if (${outroing}) return;
306-
${outroing} = true;
307-
${hasIntros && `${introing} = false;`}
286+
console.trace("outro", #component.constructor.name, ${current});
287+
if (!${current}) return;
288+
${current} = false;
308289
309290
${this.outros > 1 && `#outrocallback = @callAfter(#outrocallback, ${this.outros});`}
310291
311292
${this.builders.outro}
312293
},
313294
`);
314-
} else {
315-
properties.addBlock(deindent`
316-
o: @run,
317-
`);
318295
}
319296
}
320297

0 commit comments

Comments
 (0)