From 2d8d27afb5c52e117812dc670cef0067e24dce1c Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 5 May 2018 20:30:31 -0400 Subject: [PATCH] simpler code for case where there is only one outro in a block --- src/compile/dom/Block.ts | 2 +- src/compile/nodes/Element.ts | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/compile/dom/Block.ts b/src/compile/dom/Block.ts index 7c1bcc857361..25b324a14092 100644 --- a/src/compile/dom/Block.ts +++ b/src/compile/dom/Block.ts @@ -262,7 +262,7 @@ export default class Block { ${outroing} = true; ${hasIntros && `${introing} = false;`} - var #outros = ${this.outros}; + ${this.outros > 1 && `var #outros = ${this.outros};`} ${this.builders.outro} }, diff --git a/src/compile/nodes/Element.ts b/src/compile/nodes/Element.ts index dc1e5a271a2e..2518a55829b6 100644 --- a/src/compile/nodes/Element.ts +++ b/src/compile/nodes/Element.ts @@ -701,18 +701,18 @@ export default class Element extends Node { const fn = `%transitions-${intro.name}`; block.builders.intro.addBlock(deindent` - #component.root._aftercreate.push(function() { + #component.root._aftercreate.push(() => { if (!${name}) ${name} = @wrapTransition(#component, ${this.var}, ${fn}, ${snippet}, true, null); - ${name}.run(true, function() { + ${name}.run(true, () => { #component.fire("intro.end", { node: ${this.var} }); }); }); `); block.builders.outro.addBlock(deindent` - ${name}.run(false, function() { + ${name}.run(false, () => { #component.fire("outro.end", { node: ${this.var} }); - if (--#outros === 0) #outrocallback(); + ${block.outros > 1 ? `if (--#outros === 0) #outrocallback();` : `#outrocallback();`} ${name} = null; }); `); @@ -736,9 +736,9 @@ export default class Element extends Node { } block.builders.intro.addBlock(deindent` - #component.root._aftercreate.push(function() { + #component.root._aftercreate.push(() => { ${introName} = @wrapTransition(#component, ${this.var}, ${fn}, ${snippet}, true, null); - ${introName}.run(true, function() { + ${introName}.run(true, () => { #component.fire("intro.end", { node: ${this.var} }); }); }); @@ -757,9 +757,9 @@ export default class Element extends Node { // group) prior to their removal from the DOM block.builders.outro.addBlock(deindent` ${outroName} = @wrapTransition(#component, ${this.var}, ${fn}, ${snippet}, false, null); - ${outroName}.run(false, function() { + ${outroName}.run(false, () => { #component.fire("outro.end", { node: ${this.var} }); - if (--#outros === 0) #outrocallback(); + ${block.outros > 1 ? `if (--#outros === 0) #outrocallback();` : `#outrocallback();`} }); `); }