Skip to content

Commit 3b928b3

Browse files
committed
fix the bugs
1 parent 1cd55d1 commit 3b928b3

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

src/compile/dom/Block.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ export default class Block {
142142
}
143143

144144
addVariable(name: string, init?: string) {
145+
if (name[0] === '#') {
146+
name = this.alias(name.slice(1));
147+
}
148+
145149
if (this.variables.has(name) && this.variables.get(name) !== init) {
146150
throw new Error(
147151
`Variable '${name}' already initialised with a different value`
@@ -166,11 +170,16 @@ export default class Block {
166170
toString() {
167171
const { dev } = this.compiler.options;
168172

169-
let current;
170173
if (this.hasIntroMethod || this.hasOutroMethod) {
171-
current = this.getUniqueName('current');
172-
this.addVariable(current);
173-
this.builders.mount.addLine(`${current} = true;`);
174+
this.addVariable('#current');
175+
176+
if (!this.builders.mount.isEmpty()) {
177+
this.builders.mount.addLine(`#current = true;`);
178+
}
179+
180+
if (!this.builders.outro.isEmpty()) {
181+
this.builders.outro.addLine(`#current = false;`);
182+
}
174183
}
175184

176185
if (this.autofocus) {
@@ -268,24 +277,24 @@ export default class Block {
268277
}
269278

270279
if (this.hasIntroMethod || this.hasOutroMethod) {
271-
if (this.builders.mount.isEmpty() && this.builders.outro.isEmpty()) {
280+
if (this.builders.mount.isEmpty()) {
272281
properties.addBlock(`i: @noop,`);
273-
properties.addBlock(`o: @run,`);
274282
} else {
275283
properties.addBlock(deindent`
276284
${dev ? 'i: function intro' : 'i'}(#target, anchor) {
277-
console.trace("intro", #component.constructor.name, ${current});
278-
if (${current}) return;
285+
if (#current) return;
279286
${this.builders.intro}
280287
this.m(#target, anchor);
281288
},
282289
`);
290+
}
283291

292+
if (this.builders.outro.isEmpty()) {
293+
properties.addBlock(`o: @run,`);
294+
} else {
284295
properties.addBlock(deindent`
285296
${dev ? 'o: function outro' : 'o'}(#outrocallback) {
286-
console.trace("outro", #component.constructor.name, ${current});
287-
if (!${current}) return;
288-
${current} = false;
297+
if (!#current) return;
289298
290299
${this.outros > 1 && `#outrocallback = @callAfter(#outrocallback, ${this.outros});`}
291300

src/compile/nodes/Attribute.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ export default class Attribute extends Node {
232232
if (this.dependencies.size || isSelectValueAttribute) {
233233
const dependencies = Array.from(this.dependencies);
234234
const changedCheck = (
235-
( block.hasOutros ? `#outroing || ` : '' ) +
235+
(block.hasOutros ? `!#current || ` : '') +
236236
dependencies.map(dependency => `changed.${dependency}`).join(' || ')
237237
);
238238

@@ -308,7 +308,7 @@ export default class Attribute extends Node {
308308
if (propDependencies.size) {
309309
const dependencies = Array.from(propDependencies);
310310
const condition = (
311-
(block.hasOutros ? `#outroing || ` : '') +
311+
(block.hasOutros ? `!#current || ` : '') +
312312
dependencies.map(dependency => `changed.${dependency}`).join(' || ')
313313
);
314314

src/compile/nodes/Title.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default class Title extends Node {
8181
if (allDependencies.size) {
8282
const dependencies = Array.from(allDependencies);
8383
const changedCheck = (
84-
( block.hasOutros ? `#outroing || ` : '' ) +
84+
( block.hasOutros ? `!#current || ` : '' ) +
8585
dependencies.map(dependency => `changed.${dependency}`).join(' || ')
8686
);
8787

src/compile/nodes/shared/Tag.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default class Tag extends Node {
3535

3636
if (dependencies.size) {
3737
const changedCheck = (
38-
(block.hasOutros ? `#outroing || ` : '') +
38+
(block.hasOutros ? `!#current || ` : '') +
3939
[...dependencies].map((dependency: string) => `changed.${dependency}`).join(' || ')
4040
);
4141

0 commit comments

Comments
 (0)