Skip to content

Allow transitions to skip intro/outro #1700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/compile/dom/Block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export default class Block {
properties.addBlock(`m: @noop,`);
} else {
properties.addBlock(deindent`
${dev ? 'm: function mount' : 'm'}(#target, anchor) {
${dev ? 'm: function mount' : 'm'}(#target, anchor${this.compiler.options.nestedTransitions && ', introing'}) {
${this.builders.mount}
},
`);
Expand Down Expand Up @@ -281,10 +281,10 @@ export default class Block {
properties.addBlock(`i: @noop,`);
} else {
properties.addBlock(deindent`
${dev ? 'i: function intro' : 'i'}(#target, anchor) {
${dev ? 'i: function intro' : 'i'}(#target, anchor${this.compiler.options.nestedTransitions && ', introing'}) {
if (#current) return;
${this.builders.intro}
this.m(#target, anchor);
this.m(#target, anchor${this.compiler.options.nestedTransitions && ', introing'});
},
`);
}
Expand All @@ -293,7 +293,7 @@ export default class Block {
properties.addBlock(`o: @run,`);
} else {
properties.addBlock(deindent`
${dev ? 'o: function outro' : 'o'}(#outrocallback) {
${dev ? 'o: function outro' : 'o'}(#outrocallback${this.compiler.options.nestedTransitions && ', outroing'}) {
if (!#current) return;

${this.outros > 1 && `#outrocallback = @callAfter(#outrocallback, ${this.outros});`}
Expand Down
4 changes: 2 additions & 2 deletions src/compile/dom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export default function dom(
this._fragment.c();
this._fragment.${block.hasIntroMethod ? 'i' : 'm'}(this.shadowRoot, null);

if (options.target) this._mount(options.target, options.anchor);
if (options.target) this._mount(options.target, options.anchor${compiler.options.nestedTransitions && ', 1'});
` : deindent`
if (options.target) {
${compiler.options.hydratable
Expand All @@ -239,7 +239,7 @@ export default function dom(
${options.dev &&
`if (options.hydrate) throw new Error("options.hydrate only works if the component was compiled with the \`hydratable: true\` option");`}
this._fragment.c();`}
this._mount(options.target, options.anchor);
this._mount(options.target, options.anchor${compiler.options.nestedTransitions && ', 1'});

${(compiler.hasComponents || target.hasComplexBindings || hasInitHooks || target.hasIntroTransitions) &&
`@flush(this);`}
Expand Down
2 changes: 1 addition & 1 deletion src/compile/nodes/AwaitBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export default class AwaitBlock extends Node {
const ${countdown} = @callAfter(#outrocallback, 3);
for (let #i = 0; #i < 3; #i += 1) {
const block = ${info}.blocks[#i];
if (block) block.o(${countdown});
if (block) block.o(${countdown}, 1);
else ${countdown}();
}
`);
Expand Down
6 changes: 3 additions & 3 deletions src/compile/nodes/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ export default class Component extends Node {

block.builders.mount.addBlock(deindent`
if (${name}) {
${name}._mount(${parentNode || '#target'}, ${parentNode ? 'null' : 'anchor'});
${name}._mount(${parentNode || '#target'}, ${parentNode ? 'null' : 'anchor'}${compiler.options.nestedTransitions && ', introing'});
${this.ref && `#component.refs.${this.ref} = ${name};`}
}
`);
Expand Down Expand Up @@ -486,7 +486,7 @@ export default class Component extends Node {
}

block.builders.mount.addLine(
`${name}._mount(${parentNode || '#target'}, ${parentNode ? 'null' : 'anchor'});`
`${name}._mount(${parentNode || '#target'}, ${parentNode ? 'null' : 'anchor'}${compiler.options.nestedTransitions ? ', introing' : ''});`
);

if (updates.length) {
Expand All @@ -505,7 +505,7 @@ export default class Component extends Node {

if (this.compiler.options.nestedTransitions) {
block.builders.outro.addLine(
`if (${name}) ${name}._fragment.o(#outrocallback);`
`if (${name}) ${name}._fragment.o(#outrocallback, outroing);`
);
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/compile/nodes/EachBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export default class EachBlock extends Node {

block.builders.mount.addBlock(deindent`
if (${each_block_else}) {
${each_block_else}.${mountOrIntro}(${parentNode || '#target'}, null);
${each_block_else}.${mountOrIntro}(${parentNode || '#target'}, null${this.compiler.options.nestedTransitions && ', 1'});
}
`);

Expand Down Expand Up @@ -310,12 +310,11 @@ export default class EachBlock extends Node {
}

block.builders.mount.addBlock(deindent`
for (#i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].${mountOrIntro}(${initialMountNode}, ${anchorNode});
for (#i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].${mountOrIntro}(${initialMountNode}, ${anchorNode}${this.compiler.options.nestedTransitions ? ', 1' : ''});
`);

const dynamic = this.block.hasUpdateMethod;

const rects = block.getUniqueName('rects');
const destroy = this.block.hasAnimation
? `@fixAndOutroAndDestroyBlock`
: this.block.hasOutros
Expand All @@ -335,7 +334,7 @@ export default class EachBlock extends Node {
const countdown = block.getUniqueName('countdown');
block.builders.outro.addBlock(deindent`
const ${countdown} = @callAfter(#outrocallback, ${blocks}.length);
for (#i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].o(${countdown});
for (#i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].o(${countdown}, 1);
`);
}

Expand Down Expand Up @@ -385,7 +384,7 @@ export default class EachBlock extends Node {

block.builders.mount.addBlock(deindent`
for (var #i = 0; #i < ${iterations}.length; #i += 1) {
${iterations}[#i].${mountOrIntro}(${initialMountNode}, ${anchorNode});
${iterations}[#i].${mountOrIntro}(${initialMountNode}, ${anchorNode}${this.compiler.options.nestedTransitions && ', 1'});
}
`);

Expand All @@ -397,16 +396,17 @@ export default class EachBlock extends Node {

const outroBlock = this.block.hasOutros && block.getUniqueName('outroBlock')
if (outroBlock) {
const outroArg = this.compiler.options.nestedTransitions ? ', outroing' : '';
block.builders.init.addBlock(deindent`
function ${outroBlock}(i, detach, fn) {
function ${outroBlock}(i, detach, fn${outroArg}) {
if (${iterations}[i]) {
${iterations}[i].o(() => {
if (detach) {
${iterations}[i].d(detach);
${iterations}[i] = null;
}
if (fn) fn();
});
}${outroArg});
}
}
`);
Expand Down Expand Up @@ -451,7 +451,7 @@ export default class EachBlock extends Node {
if (this.block.hasOutros) {
destroy = deindent`
@groupOutros();
for (; #i < ${iterations}.length; #i += 1) ${outroBlock}(#i, 1);
for (; #i < ${iterations}.length; #i += 1) ${outroBlock}(#i, 1${this.compiler.options.nestedTransitions && ', null, 1'});
`;
} else {
destroy = deindent`
Expand Down Expand Up @@ -482,7 +482,7 @@ export default class EachBlock extends Node {
block.builders.outro.addBlock(deindent`
${iterations} = ${iterations}.filter(Boolean);
const ${countdown} = @callAfter(#outrocallback, ${iterations}.length);
for (let #i = 0; #i < ${iterations}.length; #i += 1) ${outroBlock}(#i, 0, ${countdown});`
for (let #i = 0; #i < ${iterations}.length; #i += 1) ${outroBlock}(#i, 0, ${countdown}${this.compiler.options.nestedTransitions && ', 1'});`
);
}

Expand Down
8 changes: 4 additions & 4 deletions src/compile/nodes/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ export default class Element extends Node {

#component.root._aftercreate.push(() => {
if (!${name}) ${name} = @wrapTransition(#component, ${this.var}, ${fn}, ${snippet}, true);
${name}.run(1);
${name}.run(1${this.compiler.options.nestedTransitions && ', null, introing'});
});
`);

Expand All @@ -770,7 +770,7 @@ export default class Element extends Node {
${name}.run(0, () => {
#outrocallback();
${name} = null;
});
}${this.compiler.options.nestedTransitions && ', outroing'});
`);

block.builders.destroy.addConditional('detach', `if (${name}) ${name}.abort();`);
Expand All @@ -796,7 +796,7 @@ export default class Element extends Node {
block.builders.intro.addConditional(`#component.root._intro`, deindent`
#component.root._aftercreate.push(() => {
${introName} = @wrapTransition(#component, ${this.var}, ${fn}, ${snippet}, true);
${introName}.run(1);
${introName}.run(1${this.compiler.options.nestedTransitions && ', null, introing'});
});
`);
}
Expand All @@ -817,7 +817,7 @@ 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);
${outroName}.run(0, #outrocallback);
${outroName}.run(0, #outrocallback${this.compiler.options.nestedTransitions && ', outroing'});
`);

block.builders.destroy.addConditional('detach', `if (${outroName}) ${outroName}.abort();`);
Expand Down
10 changes: 5 additions & 5 deletions src/compile/nodes/IfBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export default class IfBlock extends Node {

if (this.compiler.options.nestedTransitions) {
block.builders.outro.addBlock(deindent`
if (${name}) ${name}.o(#outrocallback);
if (${name}) ${name}.o(#outrocallback, 1);
else #outrocallback();
`);
}
Expand All @@ -152,7 +152,7 @@ export default class IfBlock extends Node {

if (hasOutros && this.compiler.options.nestedTransitions) {
block.builders.outro.addBlock(deindent`
if (${name}) ${name}.o(#outrocallback);
if (${name}) ${name}.o(#outrocallback, 1);
else #outrocallback();
`);
}
Expand Down Expand Up @@ -206,7 +206,7 @@ export default class IfBlock extends Node {
const initialMountNode = parentNode || '#target';
const anchorNode = parentNode ? 'null' : 'anchor';
block.builders.mount.addLine(
`${if_name}${name}.${mountOrIntro}(${initialMountNode}, ${anchorNode});`
`${if_name}${name}.${mountOrIntro}(${initialMountNode}, ${anchorNode}${this.compiler.options.nestedTransitions ? ', 1' : ''});`
);

const updateMountNode = this.getUpdateMountNode(anchor);
Expand Down Expand Up @@ -292,7 +292,7 @@ export default class IfBlock extends Node {
const anchorNode = parentNode ? 'null' : 'anchor';

block.builders.mount.addLine(
`${if_current_block_type_index}${if_blocks}[${current_block_type_index}].${mountOrIntro}(${initialMountNode}, ${anchorNode});`
`${if_current_block_type_index}${if_blocks}[${current_block_type_index}].${mountOrIntro}(${initialMountNode}, ${anchorNode}${this.compiler.options.nestedTransitions ? ', 1' : ''});`
);

const updateMountNode = this.getUpdateMountNode(anchor);
Expand Down Expand Up @@ -374,7 +374,7 @@ export default class IfBlock extends Node {
const anchorNode = parentNode ? 'null' : 'anchor';

block.builders.mount.addLine(
`if (${name}) ${name}.${mountOrIntro}(${initialMountNode}, ${anchorNode});`
`if (${name}) ${name}.${mountOrIntro}(${initialMountNode}, ${anchorNode}${this.compiler.options.nestedTransitions ? ', 1' : ''});`
);

const updateMountNode = this.getUpdateMountNode(anchor);
Expand Down
4 changes: 2 additions & 2 deletions src/shared/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ export function callAll(fns) {
while (fns && fns.length) fns.shift()();
}

export function _mount(target, anchor) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
export function _mount(target, anchor, introing) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null, introing);
}

export var PENDING = {};
Expand Down
20 changes: 14 additions & 6 deletions src/shared/transitions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createElement } from './dom.js';
import { noop, run } from './utils.js';
import { noop, run, assign } from './utils.js';

export function linear(t) {
return t;
Expand Down Expand Up @@ -28,6 +28,7 @@ export function hash(str) {

export function wrapTransition(component, node, fn, params, intro) {
let obj = fn.call(component, node, params);
if (typeof obj !== 'function') obj = assign(assign({}, component.root.options.transitions), obj);
let duration;
let ease;
let cssText;
Expand All @@ -40,28 +41,35 @@ export function wrapTransition(component, node, fn, params, intro) {
program: null,
pending: null,

run(b, callback) {
run(b, callback, introOutro) {
if (typeof obj === 'function') {
transitionManager.wait().then(() => {
obj = obj();
this._run(b, callback);
obj = assign(assign({}, component.root.options.transitions), obj);
this._run(b, callback, introOutro);
});
} else {
this._run(b, callback);
this._run(b, callback, introOutro);
}
},

_run(b, callback) {
_run(b, callback, introOutro) {
duration = obj.duration || 300;
ease = obj.easing || linear;

if (introOutro && ((b && obj.intro === false) || (!b && obj.outro === false))) {
this.t = b;
if (callback) callback();
return;
}

const program = {
start: window.performance.now() + (obj.delay || 0),
b,
callback: callback || noop
};

if (intro && !initialised) {
if (b && !initialised) {
if (obj.css && obj.delay) {
cssText = node.style.cssText;
node.style.cssText += obj.css(0, 1);
Expand Down
4 changes: 2 additions & 2 deletions test/cli/samples/amd/expected/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ define("test", function() { "use strict";
assign(this._staged, newState);
}

function _mount(target, anchor) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
function _mount(target, anchor, introing) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null, introing);
}

function _differs(a, b) {
Expand Down
4 changes: 2 additions & 2 deletions test/cli/samples/basic/expected/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ function _stage(newState) {
assign(this._staged, newState);
}

function _mount(target, anchor) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
function _mount(target, anchor, introing) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null, introing);
}

function _differs(a, b) {
Expand Down
4 changes: 2 additions & 2 deletions test/cli/samples/custom-element/expected/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ function _stage(newState) {
assign(this._staged, newState);
}

function _mount(target, anchor) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
function _mount(target, anchor, introing) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null, introing);
}

function _differs(a, b) {
Expand Down
4 changes: 2 additions & 2 deletions test/cli/samples/dev/expected/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ function _stage(newState) {
assign(this._staged, newState);
}

function _mount(target, anchor) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
function _mount(target, anchor, introing) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null, introing);
}

function _differs(a, b) {
Expand Down
4 changes: 2 additions & 2 deletions test/cli/samples/dir-sourcemap/expected/Main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/cli/samples/dir-sourcemap/expected/Widget.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/cli/samples/dir-subdir/expected/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ function _stage(newState) {
assign(this._staged, newState);
}

function _mount(target, anchor) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
function _mount(target, anchor, introing) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null, introing);
}

function _differs(a, b) {
Expand Down
4 changes: 2 additions & 2 deletions test/cli/samples/dir-subdir/expected/widget/Widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ function _stage(newState) {
assign(this._staged, newState);
}

function _mount(target, anchor) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null);
function _mount(target, anchor, introing) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null, introing);
}

function _differs(a, b) {
Expand Down
Loading