addimated
Version:
An always interruptable, declarative animation library for React
79 lines (71 loc) • 2.05 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import { AnimatedValue } from "./AnimatedValue";
var Manager =
/*#__PURE__*/
function () {
function Manager() {
_classCallCheck(this, Manager);
this.ticking = false;
this.animatedValues = new Set();
}
_createClass(Manager, [{
key: "attachValue",
value: function attachValue(value) {
this.animatedValues.add(value);
}
}, {
key: "detatchValue",
value: function detatchValue(value) {
this.animatedValues.delete(value);
}
}, {
key: "requestTick",
value: function requestTick() {
if (!this.ticking) {
window.requestAnimationFrame(this.__update.bind(this));
this.ticking = true;
}
}
}, {
key: "__update",
value: function __update(timestamp) {
this.ticking = false;
var valsToFlush = [];
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = this.animatedValues[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var animatedValue = _step.value;
var maybeVal = animatedValue.step(timestamp);
if (maybeVal) {
valsToFlush.push(maybeVal);
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
if (valsToFlush.length > 0) {
valsToFlush.forEach(function (anim) {
return anim.flush();
});
this.requestTick();
}
}
}]);
return Manager;
}();
export { Manager };
//# sourceMappingURL=Manager.js.map