Commit 4b5929d5 by Patrick O'Carroll Committed by Torkel Ödegaard

converted timer.js to timer.ts (#9656)

parent 17d95dc8
define([
'angular',
'lodash',
'../core_module',
],
function (angular, _, coreModule) {
'use strict';
coreModule.default.service('timer', function($timeout) {
// This service really just tracks a list of $timeout promises to give us a
// method for cancelling them all when we need to
var timers = [];
this.register = function(promise) {
timers.push(promise);
return promise;
};
this.cancel = function(promise) {
timers = _.without(timers,promise);
$timeout.cancel(promise);
};
this.cancelAll = function() {
_.each(timers, function(t) {
$timeout.cancel(t);
});
timers = [];
};
});
});
import _ from 'lodash';
import coreModule from 'app/core/core_module';
export class Timer {
timers = [];
/** @ngInject */
constructor(private $timeout) {
}
register(promise) {
this.timers.push(promise);
return promise;
}
cancel(promise) {
console.log(promise);
this.timers = _.without(this.timers, promise);
this.$timeout.cancel(promise);
}
cancelAll() {
_.each(this.timers, function (t) {
this.$timeout.cancel(t);
});
this.timers = [];
}
}
coreModule.service('timer', Timer);
// This service really just tracks a list of $timeout promises to give us a
// method for cancelling them all when we need to
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment