UNPKG

mobile-cli-lib

Version:
70 lines (69 loc) 2.42 kB
"use strict"; var fiberBootstrap = require("../../fiber-bootstrap"); exports.SYNC_WAIT_THRESHOLD = 250; var SyncBatch = (function () { function SyncBatch($logger, $projectFilesManager, done) { this.$logger = $logger; this.$projectFilesManager = $projectFilesManager; this.done = done; this.timer = null; this.syncQueue = []; this.syncInProgress = false; } Object.defineProperty(SyncBatch.prototype, "filesToSync", { get: function () { var _this = this; var filteredFiles = _.remove(this.syncQueue, function (syncFile) { return _this.$projectFilesManager.isFileExcluded(syncFile); }); this.$logger.trace("Removed files from syncQueue: ", filteredFiles); return this.syncQueue; }, enumerable: true, configurable: true }); Object.defineProperty(SyncBatch.prototype, "syncPending", { get: function () { return this.syncQueue.length > 0; }, enumerable: true, configurable: true }); SyncBatch.prototype.syncFiles = function (syncAction) { var _this = this; return (function () { if (_this.filesToSync.length > 0) { syncAction(_this.filesToSync).wait(); _this.reset(); } }).future()(); }; SyncBatch.prototype.addFile = function (file) { var _this = this; if (this.timer) { clearTimeout(this.timer); this.timer = null; } this.syncQueue.push(file); if (!this.syncInProgress) { this.timer = setTimeout(function () { if (_this.syncQueue.length > 0) { _this.$logger.trace("Syncing %s", _this.syncQueue.join(", ")); fiberBootstrap.run(function () { try { _this.syncInProgress = true; _this.done().wait(); } finally { _this.syncInProgress = false; } }); } _this.timer = null; }, exports.SYNC_WAIT_THRESHOLD); } }; SyncBatch.prototype.reset = function () { this.syncQueue = []; }; return SyncBatch; }()); exports.SyncBatch = SyncBatch;