Adds compiler option "containedTransitions"

Makes transitions only run when the closest non-component block containing them has changed state.

Implements #1480.

### Details

Without the `containedTransitions` compiler option, all transitions are run whenever their element is added/remove from the dom. With `containedTransitions` the transitions are only run when the closest non-component block (e.g. an if-block or each-block) changes state. This means the transitions on the items of an each-block will not run when the each-block first appears on screen, or when it is removed, but they will run when items are added/removed from the each block. In addition, if a whole page fades in with a transition at the page level, the there will not be other transitions occuring inside the page.

The transition containers do not include components, since a component is a reusable container and not a state-driven block. Thus, a transition at the root of a component will run when that component is added to the DOM inside an if-block or each-block the same way an element with a transition inside either of those blocks is run.
pull/1692/head
Jacob Wright 7 years ago
parent 0f171a5f3e
commit 72cb842342

@ -241,7 +241,7 @@ export default class Block {
properties.addBlock(`m: @noop,`); properties.addBlock(`m: @noop,`);
} else { } else {
properties.addBlock(deindent` properties.addBlock(deindent`
${dev ? 'm: function mount' : 'm'}(#target, anchor) { ${dev ? 'm: function mount' : 'm'}(#target, anchor${this.compiler.options.containedTransitions ? ', skipIntro' : ''}) {
${this.builders.mount} ${this.builders.mount}
}, },
`); `);

@ -227,7 +227,7 @@ export default function dom(
this._fragment.c(); this._fragment.c();
this._fragment.${block.hasIntroMethod ? 'i' : 'm'}(this.shadowRoot, null); 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.containedTransitions && ', !options.intro'});
` : deindent` ` : deindent`
if (options.target) { if (options.target) {
${compiler.options.hydratable ${compiler.options.hydratable
@ -239,7 +239,7 @@ export default function dom(
${options.dev && ${options.dev &&
`if (options.hydrate) throw new Error("options.hydrate only works if the component was compiled with the \`hydratable: true\` option");`} `if (options.hydrate) throw new Error("options.hydrate only works if the component was compiled with the \`hydratable: true\` option");`}
this._fragment.c();`} this._fragment.c();`}
this._mount(options.target, options.anchor); this._mount(options.target, options.anchor${compiler.options.containedTransitions && ', !options.intro'});
${(compiler.hasComponents || target.hasComplexBindings || hasInitHooks || target.hasIntroTransitions) && ${(compiler.hasComponents || target.hasComplexBindings || hasInitHooks || target.hasIntroTransitions) &&
`@flush(this);`} `@flush(this);`}

@ -172,15 +172,19 @@ export default class AwaitBlock extends Node {
} }
if (this.pending.block.hasOutroMethod && this.compiler.options.nestedTransitions) { if (this.pending.block.hasOutroMethod && this.compiler.options.nestedTransitions) {
const countdown = block.getUniqueName('countdown'); if (this.compiler.options.containedTransitions) {
block.builders.outro.addBlock(deindent` block.builders.outro.addLine('#outrocallback();');
const ${countdown} = @callAfter(#outrocallback, 3); } else {
for (let #i = 0; #i < 3; #i += 1) { const countdown = block.getUniqueName('countdown');
const block = ${info}.blocks[#i]; block.builders.outro.addBlock(deindent`
if (block) block.o(${countdown}); const ${countdown} = @callAfter(#outrocallback, 3);
else ${countdown}(); for (let #i = 0; #i < 3; #i += 1) {
} const block = ${info}.blocks[#i];
`); if (block) block.o(${countdown});
else ${countdown}();
}
`);
}
} }
block.builders.destroy.addBlock(deindent` block.builders.destroy.addBlock(deindent`

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

@ -201,9 +201,13 @@ export default class EachBlock extends Node {
} }
`); `);
const mountCall = compiler.options.containedTransitions
? `m(${parentNode || '#target'}, null, true)`
: `${mountOrIntro}(${parentNode || '#target'}, null)`
block.builders.mount.addBlock(deindent` block.builders.mount.addBlock(deindent`
if (${each_block_else}) { if (${each_block_else}) {
${each_block_else}.${mountOrIntro}(${parentNode || '#target'}, null); ${each_block_else}.${mountCall};
} }
`); `);
@ -309,8 +313,12 @@ export default class EachBlock extends Node {
`); `);
} }
const mountCall = this.compiler.options.containedTransitions
? `m(${initialMountNode}, ${anchorNode}, true)`
: `${mountOrIntro}(${initialMountNode}, ${anchorNode})`;
block.builders.mount.addBlock(deindent` 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].${mountCall};
`); `);
const dynamic = this.block.hasUpdateMethod; const dynamic = this.block.hasUpdateMethod;
@ -332,11 +340,15 @@ export default class EachBlock extends Node {
`); `);
if (this.compiler.options.nestedTransitions) { if (this.compiler.options.nestedTransitions) {
const countdown = block.getUniqueName('countdown'); if (this.compiler.options.containedTransitions) {
block.builders.outro.addBlock(deindent` block.builders.outro.addLine('#outrocallback();');
const ${countdown} = @callAfter(#outrocallback, ${blocks}.length); } else {
for (#i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].o(${countdown}); 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});
`);
}
} }
block.builders.destroy.addBlock(deindent` block.builders.destroy.addBlock(deindent`
@ -383,9 +395,13 @@ export default class EachBlock extends Node {
`); `);
} }
const mountCall = this.compiler.options.containedTransitions
? `m(${initialMountNode}, ${anchorNode}, true)`
: `${mountOrIntro}(${initialMountNode}, ${anchorNode})`;
block.builders.mount.addBlock(deindent` block.builders.mount.addBlock(deindent`
for (var #i = 0; #i < ${iterations}.length; #i += 1) { for (var #i = 0; #i < ${iterations}.length; #i += 1) {
${iterations}[#i].${mountOrIntro}(${initialMountNode}, ${anchorNode}); ${iterations}[#i].${mountCall};
} }
`); `);
@ -478,11 +494,15 @@ export default class EachBlock extends Node {
} }
if (outroBlock && this.compiler.options.nestedTransitions) { if (outroBlock && this.compiler.options.nestedTransitions) {
const countdown = block.getUniqueName('countdown'); if (this.compiler.options.containedTransitions) {
block.builders.outro.addBlock(deindent` block.builders.outro.addLine('#outrocallback();');
const ${countdown} = @callAfter(#outrocallback, ${iterations}.length); } else {
for (let #i = 0; #i < ${iterations}.length; #i += 1) ${outroBlock}(#i, 0, ${countdown});` const countdown = block.getUniqueName('countdown');
); block.builders.outro.addBlock(deindent`
const ${countdown} = @callAfter(#outrocallback, ${iterations}.length);
for (let #i = 0; #i < ${iterations}.length; #i += 1) ${outroBlock}(#i, 0, ${countdown});`
);
}
} }
block.builders.destroy.addBlock(`@destroyEach(${iterations}, detach);`); block.builders.destroy.addBlock(`@destroyEach(${iterations}, detach);`);

@ -139,10 +139,14 @@ export default class IfBlock extends Node {
this.buildCompoundWithOutros(block, parentNode, parentNodes, branches, dynamic, vars); this.buildCompoundWithOutros(block, parentNode, parentNodes, branches, dynamic, vars);
if (this.compiler.options.nestedTransitions) { if (this.compiler.options.nestedTransitions) {
block.builders.outro.addBlock(deindent` if (this.compiler.options.containedTransitions) {
if (${name}) ${name}.o(#outrocallback); block.builders.outro.addLine('#outrocallback();');
else #outrocallback(); } else {
`); block.builders.outro.addBlock(deindent`
if (${name}) ${name}.o(#outrocallback);
else #outrocallback();
`);
}
} }
} else { } else {
this.buildCompound(block, parentNode, parentNodes, branches, dynamic, vars); this.buildCompound(block, parentNode, parentNodes, branches, dynamic, vars);
@ -151,10 +155,14 @@ export default class IfBlock extends Node {
this.buildSimple(block, parentNode, parentNodes, branches[0], dynamic, vars); this.buildSimple(block, parentNode, parentNodes, branches[0], dynamic, vars);
if (hasOutros && this.compiler.options.nestedTransitions) { if (hasOutros && this.compiler.options.nestedTransitions) {
block.builders.outro.addBlock(deindent` if (this.compiler.options.containedTransitions) {
if (${name}) ${name}.o(#outrocallback); block.builders.outro.addLine('#outrocallback();');
else #outrocallback(); } else {
`); block.builders.outro.addBlock(deindent`
if (${name}) ${name}.o(#outrocallback);
else #outrocallback();
`);
}
} }
} }
@ -205,8 +213,11 @@ export default class IfBlock extends Node {
const initialMountNode = parentNode || '#target'; const initialMountNode = parentNode || '#target';
const anchorNode = parentNode ? 'null' : 'anchor'; const anchorNode = parentNode ? 'null' : 'anchor';
const mountCall = this.compiler.options.containedTransitions
? `m(${initialMountNode}, ${anchorNode}, true)`
: `${mountOrIntro}(${initialMountNode}, ${anchorNode})`;
block.builders.mount.addLine( block.builders.mount.addLine(
`${if_name}${name}.${mountOrIntro}(${initialMountNode}, ${anchorNode});` `${if_name}${name}.${mountCall};`
); );
const updateMountNode = this.getUpdateMountNode(anchor); const updateMountNode = this.getUpdateMountNode(anchor);
@ -290,9 +301,12 @@ export default class IfBlock extends Node {
const mountOrIntro = branches[0].hasIntroMethod ? 'i' : 'm'; const mountOrIntro = branches[0].hasIntroMethod ? 'i' : 'm';
const initialMountNode = parentNode || '#target'; const initialMountNode = parentNode || '#target';
const anchorNode = parentNode ? 'null' : 'anchor'; const anchorNode = parentNode ? 'null' : 'anchor';
const mountCall = this.compiler.options.containedTransitions
? `m(${initialMountNode}, ${anchorNode}, true)`
: `${mountOrIntro}(${initialMountNode}, ${anchorNode})`;
block.builders.mount.addLine( 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}].${mountCall};`
); );
const updateMountNode = this.getUpdateMountNode(anchor); const updateMountNode = this.getUpdateMountNode(anchor);
@ -372,9 +386,12 @@ export default class IfBlock extends Node {
const mountOrIntro = branch.hasIntroMethod ? 'i' : 'm'; const mountOrIntro = branch.hasIntroMethod ? 'i' : 'm';
const initialMountNode = parentNode || '#target'; const initialMountNode = parentNode || '#target';
const anchorNode = parentNode ? 'null' : 'anchor'; const anchorNode = parentNode ? 'null' : 'anchor';
const mountCall = this.compiler.options.containedTransitions
? `m(${initialMountNode}, ${anchorNode}, true)`
: `${mountOrIntro}(${initialMountNode}, ${anchorNode})`;
block.builders.mount.addLine( block.builders.mount.addLine(
`if (${name}) ${name}.${mountOrIntro}(${initialMountNode}, ${anchorNode});` `if (${name}) ${name}.${mountCall};`
); );
const updateMountNode = this.getUpdateMountNode(anchor); const updateMountNode = this.getUpdateMountNode(anchor);

@ -65,6 +65,8 @@ export interface CompileOptions {
onerror?: (error: Error) => void; onerror?: (error: Error) => void;
onwarn?: (warning: Warning) => void; onwarn?: (warning: Warning) => void;
containedTransitions?: boolean;
// to remove in v3 // to remove in v3
skipIntroByDefault?: boolean; skipIntroByDefault?: boolean;
nestedTransitions: boolean; nestedTransitions: boolean;

@ -139,8 +139,8 @@ export function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
export function _mount(target, anchor) { export function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
export var PENDING = {}; export var PENDING = {};

@ -156,8 +156,8 @@ define("test", function() { "use strict";
} }
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
function _differs(a, b) { function _differs(a, b) {

@ -156,8 +156,8 @@ function _set(newState) {
} }
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
function _differs(a, b) { function _differs(a, b) {

@ -177,8 +177,8 @@ function _set(newState) {
} }
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
function _differs(a, b) { function _differs(a, b) {

@ -182,8 +182,8 @@ function _set(newState) {
} }
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
function _differs(a, b) { function _differs(a, b) {

@ -158,8 +158,8 @@ function _set(newState) {
} }
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
function _differs(a, b) { function _differs(a, b) {

@ -156,8 +156,8 @@ function _set(newState) {
} }
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
function _differs(a, b) { function _differs(a, b) {

@ -158,8 +158,8 @@ function _set(newState) {
} }
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
function _differs(a, b) { function _differs(a, b) {

@ -156,8 +156,8 @@ function _set(newState) {
} }
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
function _differs(a, b) { function _differs(a, b) {

@ -158,8 +158,8 @@ function _set(newState) {
} }
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
function _differs(a, b) { function _differs(a, b) {

@ -156,8 +156,8 @@ function _set(newState) {
} }
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
function _differs(a, b) { function _differs(a, b) {

@ -181,8 +181,8 @@ var Main = (function(answer) { "use strict";
} }
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
function _differs(a, b) { function _differs(a, b) {

@ -156,8 +156,8 @@ function _set(newState) {
} }
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
function _differs(a, b) { function _differs(a, b) {

@ -156,8 +156,8 @@ function _set(newState) {
} }
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
function _differs(a, b) { function _differs(a, b) {

@ -180,8 +180,8 @@ function _set(newState) {
} }
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
function _differs(a, b) { function _differs(a, b) {

@ -125,8 +125,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -157,8 +157,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -137,8 +137,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -113,8 +113,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -117,8 +117,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -117,8 +117,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -113,8 +113,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -113,8 +113,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -129,8 +129,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -125,8 +125,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -161,8 +161,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var protoDev = { var protoDev = {

@ -167,8 +167,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var protoDev = { var protoDev = {

@ -167,8 +167,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var protoDev = { var protoDev = {

@ -147,8 +147,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -118,8 +118,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -161,8 +161,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var protoDev = { var protoDev = {

@ -129,8 +129,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -133,8 +133,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -133,8 +133,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -149,8 +149,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -452,8 +452,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -232,8 +232,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -125,8 +125,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -125,8 +125,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -129,8 +129,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -129,8 +129,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -129,8 +129,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -129,8 +129,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -129,8 +129,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -129,8 +129,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -137,8 +137,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -141,8 +141,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -137,8 +137,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -131,8 +131,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -141,8 +141,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -127,8 +127,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -133,8 +133,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -113,8 +113,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -133,8 +133,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -113,8 +113,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -137,8 +137,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -137,8 +137,8 @@ function callAll(fns) {
while (fns && fns.length) fns.shift()(); while (fns && fns.length) fns.shift()();
} }
function _mount(target, anchor) { function _mount(target, anchor, skipIntro) {
this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); this._fragment[!skipIntro && this._fragment.i ? 'i' : 'm'](target, anchor || null, skipIntro);
} }
var proto = { var proto = {

@ -74,6 +74,7 @@ describe("runtime", () => {
compileOptions.immutable = config.immutable; compileOptions.immutable = config.immutable;
compileOptions.skipIntroByDefault = config.skipIntroByDefault; compileOptions.skipIntroByDefault = config.skipIntroByDefault;
compileOptions.nestedTransitions = config.nestedTransitions; compileOptions.nestedTransitions = config.nestedTransitions;
compileOptions.containedTransitions = config.containedTransitions;
Object.keys(require.cache) Object.keys(require.cache)
.filter(x => x.endsWith(".html")) .filter(x => x.endsWith(".html"))

@ -0,0 +1,34 @@
let fulfil;
const promise = new Promise(f => {
fulfil = f;
});
export default {
containedTransitions: true,
nestedTransitions: true,
data: {
x: false,
promise
},
test(assert, component, target, window, raf) {
component.set({ x: true });
fulfil();
return promise.then(() => {
const div = target.querySelector('div');
assert.equal(div.foo, 0);
raf.tick(100);
assert.equal(div.foo, 1);
component.set({ x: false });
assert.htmlEqual(target.innerHTML, '');
raf.tick(150);
assert.equal(div.foo, 1);
});
}
};

@ -0,0 +1,20 @@
{#if x}
{#await promise then value}
<div transition:foo></div>
{/await}
{/if}
<script>
export default {
transitions: {
foo(node, params) {
return {
duration: 100,
tick: t => {
node.foo = t;
}
};
}
}
};
</script>

@ -0,0 +1,16 @@
<div transition:foo></div>
<script>
export default {
transitions: {
foo(node, params) {
return {
duration: 100,
tick: t => {
node.foo = t;
}
};
}
}
};
</script>

@ -0,0 +1,27 @@
export default {
containedTransitions: true,
nestedTransitions: true,
data: {
x: false
},
test(assert, component, target, window, raf) {
component.set({ x: true });
const div = target.querySelector('div');
assert.equal(div.foo, 0);
raf.tick(100);
assert.equal(div.foo, 1);
component.set({ x: false });
assert.htmlEqual(target.innerHTML, '<div></div>');
raf.tick(150);
assert.equal(div.foo, 0.5);
raf.tick(200);
assert.htmlEqual(target.innerHTML, '');
}
};

@ -0,0 +1,13 @@
{#if x}
<Widget/>
{/if}
<script>
import Widget from './Widget.html';
export default {
components: {
Widget: './Widget.html'
}
};
</script>

@ -0,0 +1,33 @@
export default {
containedTransitions: true,
nestedTransitions: true,
data: {
x: false,
things: ['a']
},
test(assert, component, target, window, raf) {
component.set({ x: true });
const div1 = target.querySelector('div');
assert.equal(div1.foo, undefined);
raf.tick(100);
assert.equal(div1.foo, undefined);
component.set({ things: ['a', 'b'] });
assert.htmlEqual(target.innerHTML, '<div></div><div></div>');
const div2 = target.querySelector('div:last-child');
assert.equal(div1.foo, undefined);
assert.equal(div2.foo, 0);
raf.tick(200);
assert.equal(div1.foo, undefined);
assert.equal(div2.foo, 1);
component.set({ x: false });
assert.htmlEqual(target.innerHTML, '');
},
};

@ -0,0 +1,20 @@
{#if x}
{#each things as thing (thing)}
<div transition:foo></div>
{/each}
{/if}
<script>
export default {
transitions: {
foo(node, params) {
return {
duration: 100,
tick: t => {
node.foo = t;
}
};
}
}
};
</script>

@ -0,0 +1,33 @@
export default {
containedTransitions: true,
nestedTransitions: true,
data: {
x: false,
things: ['a']
},
test(assert, component, target, window, raf) {
component.set({ x: true });
const div1 = target.querySelector('div');
assert.equal(div1.foo, undefined);
raf.tick(100);
assert.equal(div1.foo, undefined);
component.set({ things: ['a', 'b'] });
assert.htmlEqual(target.innerHTML, '<div></div><div></div>');
const div2 = target.querySelector('div:last-child');
assert.equal(div1.foo, undefined);
assert.equal(div2.foo, 0);
raf.tick(200);
assert.equal(div1.foo, undefined);
assert.equal(div2.foo, 1);
component.set({ x: false });
assert.htmlEqual(target.innerHTML, '');
},
};

@ -0,0 +1,20 @@
{#if x}
{#each things as thing}
<div transition:foo></div>
{/each}
{/if}
<script>
export default {
transitions: {
foo(node, params) {
return {
duration: 100,
tick: t => {
node.foo = t;
}
};
}
}
};
</script>

@ -0,0 +1,45 @@
export default {
containedTransitions: true,
nestedTransitions: true,
data: {
x: false,
y: true
},
test(assert, component, target, window, raf) {
component.set({ x: true });
let div = target.querySelector('div');
assert.equal(div.foo, undefined);
raf.tick(100);
assert.equal(div.foo, undefined);
assert.htmlEqual(target.innerHTML, '<div></div>');
component.set({ y: false });
assert.htmlEqual(target.innerHTML, '<div></div>');
raf.tick(150);
assert.equal(div.foo, 0.5);
raf.tick(200);
assert.htmlEqual(target.innerHTML, '');
component.set({ x: false, y: true });
assert.htmlEqual(target.innerHTML, '');
component.set({ x: true });
assert.htmlEqual(target.innerHTML, '<div></div>');
div = target.querySelector('div');
component.set({ y: false });
assert.htmlEqual(target.innerHTML, '<div></div>');
raf.tick(250);
assert.equal(div.foo, 0.5);
raf.tick(300);
assert.htmlEqual(target.innerHTML, '');
},
};

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