Przeglądaj źródła

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

Patrick O'Carroll 8 lat temu
rodzic
commit
4b5929d577

+ 0 - 33
public/app/core/services/timer.js

@@ -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 - 0
public/app/core/services/timer.ts

@@ -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