From 84d501b5fb1e5a9740d1fa59c812c8ce87d6e9d7 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Tue, 1 Jan 2019 02:16:55 -0500 Subject: [PATCH] minor tidy up --- src/motion/spring.js | 8 +++----- src/motion/tweened.js | 7 +++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/motion/spring.js b/src/motion/spring.js index 7d68377bd0..1b5413db63 100644 --- a/src/motion/spring.js +++ b/src/motion/spring.js @@ -117,20 +117,18 @@ export function spring(value, opts = {}) { last_time = window.performance.now(); settled = false; - task = loop(() => { - const time = window.performance.now(); - + task = loop(now=> { ({ value, settled } = tick_spring( velocity, value, target_value, spring.stiffness, spring.damping, - (time - last_time) * 60 / 1000, + (now - last_time) * 60 / 1000, threshold )); - last_time = time; + last_time = now; if (settled) { value = target_value; diff --git a/src/motion/tweened.js b/src/motion/tweened.js index 21ff8f70c7..49f1217a4e 100644 --- a/src/motion/tweened.js +++ b/src/motion/tweened.js @@ -76,9 +76,8 @@ export function tweened(value, defaults = {}) { const start = window.performance.now() + delay; let fn; - task = loop(() => { - const time = window.performance.now(); - if (time < start) return true; + task = loop(now => { + if (now < start) return true; if (!started) { fn = interpolate(value, new_value); @@ -91,7 +90,7 @@ export function tweened(value, defaults = {}) { previous_task = null; } - const elapsed = time - start; + const elapsed = now - start; if (elapsed > duration) { store.set(value = new_value);