mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
converted timer.js to timer.ts (#9656)
This commit is contained in:
parent
17d95dc848
commit
4b5929d577
@ -1,33 +0,0 @@
|
||||
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 = [];
|
||||
};
|
||||
});
|
||||
|
||||
});
|
32
public/app/core/services/timer.ts
Normal file
32
public/app/core/services/timer.ts
Normal file
@ -0,0 +1,32 @@
|
||||
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
|
Loading…
Reference in New Issue
Block a user