feat(animations): support :increment and :decrement transition aliases

This commit is contained in:
Matias Niemelä
2017-07-07 09:10:10 -07:00
committed by Alex Rickabaugh
parent 65c9e13105
commit 6f45519d6f
3 changed files with 182 additions and 4 deletions

View File

@ -24,8 +24,14 @@ export function parseTransitionExpr(
function parseInnerTransitionStr(
eventStr: string, expressions: TransitionMatcherFn[], errors: string[]) {
if (eventStr[0] == ':') {
eventStr = parseAnimationAlias(eventStr, errors);
const result = parseAnimationAlias(eventStr, errors);
if (typeof result == 'function') {
expressions.push(result);
return;
}
eventStr = result as string;
}
const match = eventStr.match(/^(\*|[-\w]+)\s*(<?[=-]>)\s*(\*|[-\w]+)$/);
if (match == null || match.length < 4) {
errors.push(`The provided transition expression "${eventStr}" is not supported`);
@ -43,12 +49,16 @@ function parseInnerTransitionStr(
}
}
function parseAnimationAlias(alias: string, errors: string[]): string {
function parseAnimationAlias(alias: string, errors: string[]): string|TransitionMatcherFn {
switch (alias) {
case ':enter':
return 'void => *';
case ':leave':
return '* => void';
case ':increment':
return (fromState: any, toState: any): boolean => parseFloat(toState) > parseFloat(fromState);
case ':decrement':
return (fromState: any, toState: any): boolean => parseFloat(toState) < parseFloat(fromState);
default:
errors.push(`The transition alias value "${alias}" is not supported`);
return '* => *';