From f399b5476ffc5fd02d64155302adce78097d39c1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gabriel=20Loi=C3=A1cono?= <32134586+loiacon@users.noreply.github.com> Date: Sat, 23 Nov 2019 02:02:39 -0300 Subject: [PATCH] refactor(transition): avoid repeated code (#483) --- .../src/components/CSSTransition.ts | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/packages/runtime-dom/src/components/CSSTransition.ts b/packages/runtime-dom/src/components/CSSTransition.ts index 082cc48a4b..58f9e71c20 100644 --- a/packages/runtime-dom/src/components/CSSTransition.ts +++ b/packages/runtime-dom/src/components/CSSTransition.ts @@ -251,13 +251,12 @@ function getTransitionInfo( ): CSSTransitionInfo { const styles: any = window.getComputedStyle(el) // JSDOM may return undefined for transition properties - const transitionDelays = (styles[TRANSITION + 'Delay'] || '').split(', ') - const transitionDurations = (styles[TRANSITION + 'Duration'] || '').split( - ', ' - ) + const getStyleProperties = (key: string) => (styles[key] || '').split(', ') + const transitionDelays = getStyleProperties(TRANSITION + 'Delay') + const transitionDurations = getStyleProperties(TRANSITION + 'Duration') const transitionTimeout = getTimeout(transitionDelays, transitionDurations) - const animationDelays = (styles[ANIMATION + 'Delay'] || '').split(', ') - const animationDurations = (styles[ANIMATION + 'Duration'] || '').split(', ') + const animationDelays = getStyleProperties(ANIMATION + 'Delay') + const animationDurations = getStyleProperties(ANIMATION + 'Duration') const animationTimeout = getTimeout(animationDelays, animationDurations) let type: CSSTransitionInfo['type'] = null @@ -301,12 +300,7 @@ function getTimeout(delays: string[], durations: string[]): number { while (delays.length < durations.length) { delays = delays.concat(delays) } - return Math.max.apply( - null, - durations.map((d, i) => { - return toMs(d) + toMs(delays[i]) - }) - ) + return Math.max(...durations.map((d, i) => toMs(d) + toMs(delays[i]))) } // Old versions of Chromium (below 61.0.3163.100) formats floating pointer -- 2.47.3