UNPKG

react-application-core

Version:

A react-based application core for the business applications.

90 lines 2.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DelayedTask = void 0; var di_services_1 = require("../di/di.services"); var type_1 = require("./type"); var DelayedTask = /** @class */ (function () { /** * @stable [26.09.2020] * @param task * @param period * @param repeat */ function DelayedTask(task, period, repeat) { if (period === void 0) { period = 0; } if (repeat === void 0) { repeat = false; } this.task = task; this.period = period; this.repeat = repeat; } Object.defineProperty(DelayedTask.prototype, "progress", { /** * @stable [26.09.2020] */ get: function () { return type_1.TypeUtils.isNumber(this.taskId); }, enumerable: false, configurable: true }); /** * @stable [26.09.2020] * @param context */ DelayedTask.prototype.start = function (context) { this.context = context; this.launchTask(); }; /** * @stable [26.09.2020] * @param context */ DelayedTask.prototype.startImmediately = function (context) { this.context = context; this.launchTask(true); }; /** * @stable [26.09.2020] */ DelayedTask.prototype.stop = function () { if (!type_1.TypeUtils.isNumber(this.taskId)) { return; } clearTimeout(this.taskId); this.taskId = null; }; /** * @stable [26.09.2020] */ DelayedTask.prototype.launchTask = function (startImmediately) { var _this = this; if (startImmediately === void 0) { startImmediately = false; } this.stop(); this.taskId = di_services_1.DiServices.environment().window.setTimeout(function () { return _this.onTaskDone(); }, this.period); if (startImmediately) { this.callTask(); } }; /** * @stable [26.09.2020] */ DelayedTask.prototype.onTaskDone = function () { this.callTask(); if (this.repeat) { this.launchTask(); } else { this.taskId = null; this.context = null; } }; /** * @stable [26.09.2020] */ DelayedTask.prototype.callTask = function () { this.task.call(null, this.context); }; return DelayedTask; }()); exports.DelayedTask = DelayedTask; //# sourceMappingURL=task.js.map