fix the bugs

pull/1529/head
Rich Harris 7 years ago
parent 1cd55d1f2b
commit 3b928b36a9

@ -142,6 +142,10 @@ export default class Block {
} }
addVariable(name: string, init?: string) { addVariable(name: string, init?: string) {
if (name[0] === '#') {
name = this.alias(name.slice(1));
}
if (this.variables.has(name) && this.variables.get(name) !== init) { if (this.variables.has(name) && this.variables.get(name) !== init) {
throw new Error( throw new Error(
`Variable '${name}' already initialised with a different value` `Variable '${name}' already initialised with a different value`
@ -166,11 +170,16 @@ export default class Block {
toString() { toString() {
const { dev } = this.compiler.options; const { dev } = this.compiler.options;
let current;
if (this.hasIntroMethod || this.hasOutroMethod) { if (this.hasIntroMethod || this.hasOutroMethod) {
current = this.getUniqueName('current'); this.addVariable('#current');
this.addVariable(current);
this.builders.mount.addLine(`${current} = true;`); if (!this.builders.mount.isEmpty()) {
this.builders.mount.addLine(`#current = true;`);
}
if (!this.builders.outro.isEmpty()) {
this.builders.outro.addLine(`#current = false;`);
}
} }
if (this.autofocus) { if (this.autofocus) {
@ -268,24 +277,24 @@ export default class Block {
} }
if (this.hasIntroMethod || this.hasOutroMethod) { if (this.hasIntroMethod || this.hasOutroMethod) {
if (this.builders.mount.isEmpty() && this.builders.outro.isEmpty()) { 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;
if (${current}) return;
${this.builders.intro} ${this.builders.intro}
this.m(#target, anchor); this.m(#target, anchor);
}, },
`); `);
}
if (this.builders.outro.isEmpty()) {
properties.addBlock(`o: @run,`);
} else {
properties.addBlock(deindent` properties.addBlock(deindent`
${dev ? 'o: function outro' : 'o'}(#outrocallback) { ${dev ? 'o: function outro' : 'o'}(#outrocallback) {
console.trace("outro", #component.constructor.name, ${current}); if (!#current) return;
if (!${current}) return;
${current} = false;
${this.outros > 1 && `#outrocallback = @callAfter(#outrocallback, ${this.outros});`} ${this.outros > 1 && `#outrocallback = @callAfter(#outrocallback, ${this.outros});`}

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

@ -81,7 +81,7 @@ export default class Title extends Node {
if (allDependencies.size) { if (allDependencies.size) {
const dependencies = Array.from(allDependencies); const dependencies = Array.from(allDependencies);
const changedCheck = ( const changedCheck = (
( block.hasOutros ? `#outroing || ` : '' ) + ( block.hasOutros ? `!#current || ` : '' ) +
dependencies.map(dependency => `changed.${dependency}`).join(' || ') dependencies.map(dependency => `changed.${dependency}`).join(' || ')
); );

@ -35,7 +35,7 @@ export default class Tag extends Node {
if (dependencies.size) { if (dependencies.size) {
const changedCheck = ( const changedCheck = (
(block.hasOutros ? `#outroing || ` : '') + (block.hasOutros ? `!#current || ` : '') +
[...dependencies].map((dependency: string) => `changed.${dependency}`).join(' || ') [...dependencies].map((dependency: string) => `changed.${dependency}`).join(' || ')
); );

Loading…
Cancel
Save