Skip to content

Commit

Permalink
Simplify animation constructor by using resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Feb 4, 2020
1 parent 5f222e2 commit e24853f
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions src/core/core.animation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

import helpers from '../helpers';
import {effects} from '../helpers/helpers.easing';
import {resolve} from '../helpers/helpers.options';

const transparent = 'transparent';
const interpolators = {
Expand All @@ -22,28 +24,14 @@ const interpolators = {
class Animation {
constructor(cfg, target, prop, to) {
const me = this;
let from = cfg.from;
const currentValue = target[prop];

if (from === undefined) {
from = target[prop];
}
if (to === undefined) {
to = target[prop];
}

if (from === undefined) {
from = to;
} else if (to === undefined) {
to = from;
}

if (cfg.to !== undefined) {
to = cfg.to;
}
to = resolve([cfg.to, to, currentValue, cfg.from]);
let from = resolve([cfg.from, currentValue, to]);

me._active = true;
me._fn = cfg.fn || interpolators[cfg.type || typeof from];
me._easing = helpers.easing.effects[cfg.easing || 'linear'];
me._easing = effects[cfg.easing || 'linear'];
me._start = Math.floor(Date.now() + (cfg.delay || 0));
me._duration = Math.floor(cfg.duration);
me._loop = !!cfg.loop;
Expand Down

0 comments on commit e24853f

Please sign in to comment.