Merge pull request #1572 from sveltejs/gh-1561

abort transition on detach
pull/1570/merge
Rich Harris 7 years ago committed by GitHub
commit faa07e8d57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -712,6 +712,8 @@ export default class Element extends Node {
${name} = null;
});
`);
block.builders.destroy.addConditional('detach', `if (${name}) ${name}.abort();`);
} else {
const introName = intro && block.getUniqueName(`${this.var}_intro`);
const outroName = outro && block.getUniqueName(`${this.var}_outro`);
@ -726,8 +728,8 @@ export default class Element extends Node {
if (outro) {
block.builders.intro.addBlock(deindent`
if (${introName}) ${introName}.abort();
if (${outroName}) ${outroName}.abort();
if (${introName}) ${introName}.abort(1);
if (${outroName}) ${outroName}.abort(1);
`);
}
@ -748,7 +750,7 @@ export default class Element extends Node {
const fn = `%transitions-${outro.name}`;
block.builders.intro.addBlock(deindent`
if (${outroName}) ${outroName}.abort();
if (${outroName}) ${outroName}.abort(1);
`);
// TODO hide elements that have outro'd (unless they belong to a still-outroing
@ -757,6 +759,8 @@ export default class Element extends Node {
${outroName} = @wrapTransition(#component, ${this.var}, ${fn}, ${snippet}, false);
${outroName}.run(0, #outrocallback);
`);
block.builders.destroy.addConditional('detach', `if (${outroName}) ${outroName}.abort();`);
}
}
}

@ -148,9 +148,9 @@ export function wrapTransition(component, node, fn, params, intro) {
this.running = !!this.pending;
},
abort() {
abort(reset) {
if (this.program) {
if (obj.tick) obj.tick(1, 0);
if (reset && obj.tick) obj.tick(1, 0);
if (obj.css) transitionManager.deleteRule(node, this.program.name);
this.program = this.pending = null;
this.running = false;

@ -0,0 +1,19 @@
export default {
skipIntroByDefault: true,
data: {
visible: true
},
test(assert, component, target, window, raf) {
component.set({ visible: false });
const div = target.querySelector('div');
raf.tick(50);
assert.equal(div.foo, 0.5);
component.destroy();
raf.tick(100);
},
};

@ -0,0 +1,18 @@
{#if visible}
<div transition:foo>destroy me</div>
{/if}
<script>
export default {
transitions: {
foo(node, params) {
return {
duration: 100,
tick: t => {
node.foo = t;
}
};
}
}
};
</script>
Loading…
Cancel
Save