Skip to content

Commit

Permalink
Remove object.assign dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyckahn committed Aug 5, 2018
1 parent 2984c45 commit 7e1ad8f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 51 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,5 @@
}
],
"license": "MIT",
"dependencies": {
"object-assign": "^4.1.1"
}
"dependencies": {}
}
17 changes: 8 additions & 9 deletions src/bezier.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Tweenable } from './tweenable';
import assign from 'object-assign';

/**
* The Bezier magic in this file is adapted/copied almost wholesale from
Expand Down Expand Up @@ -166,14 +165,14 @@ const getCubicBezierTransition = (x1, y1, x2, y2) => pos =>
* @return {shifty.easingFunction} The {@link shifty.easingFunction} that was
* attached to {@link shifty.Tweenable.formulas}.
*/
export const setBezierFunction = (name, x1, y1, x2, y2) =>
(Tweenable.formulas[name] = assign(getCubicBezierTransition(x1, y1, x2, y2), {
displayName: name,
x1,
y1,
x2,
y2,
}));
export const setBezierFunction = (name, x1, y1, x2, y2) => ({
...(Tweenable.formulas[name] = getCubicBezierTransition(x1, y1, x2, y2)),
displayName: name,
x1,
y1,
x2,
y2,
});

/**
* `delete` an easing function from {@link shifty.Tweenable.formulas}. Be
Expand Down
70 changes: 31 additions & 39 deletions src/tweenable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as easingFunctions from './easing-functions';
import assign from 'object-assign';
import * as token from './token';

// CONSTANTS
Expand Down Expand Up @@ -256,37 +255,32 @@ export class Tweenable {
this._attachment = config.attachment;

// Init the internal state
assign(this, {
_pausedAtTime: null,
_scheduleId: null,
_delay: config.delay || 0,
_start: config.start || noop,
_step: config.step || noop,
_duration: config.duration || DEFAULT_DURATION,
_currentState: { ...(config.from || this.get()) },
});

// Separate Object.assign here; it depends on _currentState being set above
assign(this, {
_originalState: this.get(),
_targetState: { ...(config.to || this.get()) },
});

let currentState = this._currentState;
this._pausedAtTime = null;
this._scheduleId = null;
this._delay = config.delay || 0;
this._start = config.start || noop;
this._step = config.step || noop;
this._duration = config.duration || DEFAULT_DURATION;
this._currentState = { ...(config.from || this.get()) };
this._originalState = this.get();
this._targetState = { ...(config.to || this.get()) };

const { _currentState } = this;
// Ensure that there is always something to tween to.
this._targetState = assign({}, currentState, this._targetState);
this._targetState = { ..._currentState, ...this._targetState };

this._easing = composeEasingObject(_currentState, config.easing);

this._easing = composeEasingObject(currentState, config.easing);
this._filterArgs = [
currentState,
_currentState,
this._originalState,
this._targetState,
this._easing,
];

this._applyFilter('tweenCreated');

const Promised = config.promise || Promise;
this._promise = new Promised((resolve, reject) => {
this._promise = new (config.promise || Promise)((resolve, reject) => {
this._resolve = resolve;
this._reject = reject;
});
Expand Down Expand Up @@ -458,24 +452,22 @@ export class Tweenable {
}
}

assign(Tweenable, {
formulas,
Tweenable.formulas = formulas;

/**
* The {@link shifty.filter}s available for use. These filters are
* automatically applied at tween-time by Shifty.
* @member shifty.Tweenable.filters
* @type {Object.<shifty.filter>}
*/
filters: { token },
/**
* The {@link shifty.filter}s available for use. These filters are
* automatically applied at tween-time by Shifty.
* @member shifty.Tweenable.filters
* @type {Object.<shifty.filter>}
*/
Tweenable.filters = { token };

/**
* @method shifty.Tweenable.now
* @static
* @returns {number} The current timestamp.
*/
now: Date.now || (() => +new Date()),
});
/**
* @method shifty.Tweenable.now
* @static
* @returns {number} The current timestamp.
*/
Tweenable.now = Date.now || (() => +new Date());

/**
* @method shifty.tween
Expand Down

0 comments on commit 7e1ad8f

Please sign in to comment.