SymphonyElectron/js/notify/AnimationQueue.js
Kiran Niranjan 85a21ec4e8 Electron-65 (Logging) (#121)
* Electron-65 - Added more logs

* Electron-65 - Removed some logs as per the review

* Electron-65 - Removed unused log variables
2017-06-02 09:08:55 -07:00

47 lines
1.2 KiB
JavaScript

'use strict';
const log = require('../log.js');
const logLevels = require('../enums/logLevels.js');
// One animation at a time
const AnimationQueue = function(options) {
this.options = options;
this.queue = [];
this.running = false;
}
AnimationQueue.prototype.push = function(object) {
if (this.running) {
this.queue.push(object);
} else {
this.running = true;
setTimeout(this.animate.bind(this, object), 0);
}
}
AnimationQueue.prototype.animate = function(object) {
object.func.apply(null, object.args)
.then(function() {
if (this.queue.length > 0) {
// Run next animation
this.animate.call(this, this.queue.shift());
} else {
this.running = false;
}
}.bind(this))
.catch(function(err) {
log.send(logLevels.ERROR, 'animationQueue: encountered an error: ' + err +
' with stack trace:' + err.stack);
/* eslint-disable no-console */
console.error('animation queue encountered an error: ' + err +
' with stack trace:' + err.stack);
/* eslint-enable no-console */
})
}
AnimationQueue.prototype.clear = function() {
this.queue = [];
}
module.exports = AnimationQueue;