Lint and format src/runtime/motion/spring.js

pull/8569/head
S. Elliott Johnson 3 years ago
parent 5f020f7638
commit 739141f2a2

@ -19,18 +19,17 @@ function tick_spring(ctx, last_value, current_value, target_value) {
const d = (velocity + acceleration) * ctx.dt; const d = (velocity + acceleration) * ctx.dt;
if (Math.abs(d) < ctx.opts.precision && Math.abs(delta) < ctx.opts.precision) { if (Math.abs(d) < ctx.opts.precision && Math.abs(delta) < ctx.opts.precision) {
return target_value; // settled return target_value; // settled
} } else {
else {
ctx.settled = false; // signal loop to keep ticking ctx.settled = false; // signal loop to keep ticking
// @ts-ignore // @ts-ignore
return is_date(current_value) ? new Date(current_value.getTime() + d) : current_value + d; return is_date(current_value) ? new Date(current_value.getTime() + d) : current_value + d;
} }
} } else if (Array.isArray(current_value)) {
else if (Array.isArray(current_value)) {
// @ts-ignore // @ts-ignore
return current_value.map((_, i) => tick_spring(ctx, last_value[i], current_value[i], target_value[i])); return current_value.map((_, i) =>
} tick_spring(ctx, last_value[i], current_value[i], target_value[i])
else if (typeof current_value === 'object') { );
} else if (typeof current_value === 'object') {
const next_value = {}; const next_value = {};
for (const k in current_value) { for (const k in current_value) {
// @ts-ignore // @ts-ignore
@ -38,8 +37,7 @@ function tick_spring(ctx, last_value, current_value, target_value) {
} }
// @ts-ignore // @ts-ignore
return next_value; return next_value;
} } else {
else {
throw new Error(`Cannot spring ${typeof current_value} values`); throw new Error(`Cannot spring ${typeof current_value} values`);
} }
} }
@ -76,8 +74,7 @@ export function spring(value, opts = {}) {
last_value = new_value; last_value = new_value;
store.set((value = target_value)); store.set((value = target_value));
return Promise.resolve(); return Promise.resolve();
} } else if (opts.soft) {
else if (opts.soft) {
const rate = opts.soft === true ? 0.5 : +opts.soft; const rate = opts.soft === true ? 0.5 : +opts.soft;
inv_mass_recovery_rate = 1 / (rate * 60); inv_mass_recovery_rate = 1 / (rate * 60);
inv_mass = 0; // infinite mass, unaffected by spring forces inv_mass = 0; // infinite mass, unaffected by spring forces
@ -110,8 +107,7 @@ export function spring(value, opts = {}) {
} }
return new Promise((fulfil) => { return new Promise((fulfil) => {
task.promise.then(() => { task.promise.then(() => {
if (token === current_token) if (token === current_token) fulfil();
fulfil();
}); });
}); });
} }
@ -127,7 +123,6 @@ export function spring(value, opts = {}) {
return spring; return spring;
} }
/** /**
* @typedef {(target_value: T, value: T) => T} Updater * @typedef {(target_value: T, value: T) => T} Updater
* @template T * @template T

Loading…
Cancel
Save