simplr-gulp
Version:
Fully functional gulpfile.js implementation. Tailored for Single Page Application. Written in TypeScript.
43 lines (42 loc) • 1.46 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const live_reload_actions_1 = require("./live-reload-actions");
const actions_emitter_1 = require("../../utils/actions-emitter");
class LiveReloadActionsCreatorsClass {
constructor() {
this.reloadFiles = [];
this.emitOnDebounced = () => {
if (this.reloadFiles !== undefined) {
actions_emitter_1.Emitter.emit(new live_reload_actions_1.ReloadFiles(this.reloadFiles));
}
else {
actions_emitter_1.Emitter.emit(new live_reload_actions_1.ReloadPage());
}
this.reloadFiles = [];
this.tryToClearTimer();
};
}
tryToClearTimer() {
let result = false;
if (this.timer !== undefined) {
result = true;
clearTimeout(this.timer);
this.timer = undefined;
}
return result;
}
setTimer(func) {
this.timer = setTimeout(func, 300);
}
ReloadPage() {
this.tryToClearTimer();
this.setTimer(this.emitOnDebounced);
}
ReloadFiles(...filesNames) {
this.tryToClearTimer();
if (this.reloadFiles !== undefined) {
this.reloadFiles = this.reloadFiles.concat(filesNames);
}
this.setTimer(this.emitOnDebounced);
}
}
exports.LiveReloadActionsCreators = new LiveReloadActionsCreatorsClass();