never abort transitions, they are either bidi or non-abortable

pull/525/head
Rich-Harris 8 years ago
parent 806b09840a
commit d63f80fc48

@ -31,23 +31,18 @@ export default function addTransitions ( generator, block, state, node, intro, o
} }
else { else {
const introName = intro && block.getUniqueName( `${state.name}_intro` );
const outroName = outro && block.getUniqueName( `${state.name}_outro` );
if ( intro ) { if ( intro ) {
block.addVariable( introName ); const name = block.getUniqueName( `${state.name}_intro` );
const snippet = intro.expression ? block.contextualise( intro.expression ).snippet : '{}'; const snippet = intro.expression ? block.contextualise( intro.expression ).snippet : '{}';
const fn = `${generator.alias( 'template' )}.transitions.${intro.name}`; // TODO add built-in transitions? block.addVariable( name );
if ( outro ) { const fn = `${generator.alias( 'template' )}.transitions.${intro.name}`; // TODO add built-in transitions?
block.builders.intro.addBlock( `if ( ${outroName} ) ${outroName}.abort();` );
}
block.builders.intro.addBlock( deindent` block.builders.intro.addBlock( deindent`
${block.component}._renderHooks.push( function () { ${block.component}._renderHooks.push( function () {
${introName} = ${wrapTransition}( ${state.name}, ${fn}, ${snippet}, true, null ); ${name} = ${wrapTransition}( ${state.name}, ${fn}, ${snippet}, true, null );
${introName}.run( 0, 1, function () { ${name}.run( 0, 1, function () {
${block.component}.fire( 'intro.end', { node: ${state.name} }); ${block.component}.fire( 'intro.end', { node: ${state.name} });
}); });
}); });
@ -55,18 +50,16 @@ export default function addTransitions ( generator, block, state, node, intro, o
} }
if ( outro ) { if ( outro ) {
block.addVariable( outroName ); const name = block.getUniqueName( `${state.name}_intro` );
const snippet = outro.expression ? block.contextualise( outro.expression ).snippet : '{}'; const snippet = outro.expression ? block.contextualise( outro.expression ).snippet : '{}';
const fn = `${generator.alias( 'template' )}.transitions.${outro.name}`; block.addVariable( name );
if ( intro ) { const fn = `${generator.alias( 'template' )}.transitions.${outro.name}`;
block.builders.outro.addBlock( `${introName}.abort();` );
}
block.builders.outro.addBlock( deindent` block.builders.outro.addBlock( deindent`
${outroName} = ${wrapTransition}( ${state.name}, ${fn}, ${snippet}, false, null ); ${name} = ${wrapTransition}( ${state.name}, ${fn}, ${snippet}, false, null );
${outroName}.run( 1, 0, function () { ${name}.run( 1, 0, function () {
detachNode( ${state.name} ); detachNode( ${state.name} );
${block.component}.fire( 'outro.end', { node: ${state.name} }); ${block.component}.fire( 'outro.end', { node: ${state.name} });
if ( --${block.alias( 'outros' )} === 0 ) ${block.alias( 'outrocallback' )}(); if ( --${block.alias( 'outros' )} === 0 ) ${block.alias( 'outrocallback' )}();

@ -60,13 +60,13 @@ export function wrapTransition ( node, fn, params, intro, outgroup ) {
} }
// CSS transition // CSS transition
var started = false;
var id = null; var id = null;
var style = document.createElement( 'style' ); var style = document.createElement( 'style' );
var cleanup = function () { var cleanup = function () {
if ( !transition.running ) return;
document.head.removeChild( style ); document.head.removeChild( style );
transition.running = started = false; transition.running = false;
}; };
return assign( transition, { return assign( transition, {
@ -82,14 +82,10 @@ export function wrapTransition ( node, fn, params, intro, outgroup ) {
keyframes += '100% {' + obj.styles( this.b ) + '}\n}'; keyframes += '100% {' + obj.styles( this.b ) + '}\n}';
style.textContent = keyframes; style.textContent += keyframes;
document.head.appendChild( style ); document.head.appendChild( style );
node.style.animationName = id; node.style.animation += ( node.style.animation ? ', ' : '' ) + id + ' ' + this.duration + 'ms linear 1 forwards';
node.style.animationDuration = ( this.duration / 1e3 ) + 's';
node.style.animationTimingFunction = 'linear';
node.style.animationIterationCount = 1;
node.style.animationFillMode = 'forwards';
}, },
update: function ( now ) { update: function ( now ) {
const p = now - this.start; const p = now - this.start;

Loading…
Cancel
Save