UNPKG

alm

Version:

The best IDE for TypeScript

37 lines (36 loc) 1.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * When sending edits to the server we *batch them by filePath*. */ /** imports */ var socketClient_1 = require("../../../socket/socketClient"); var utils = require("../../../common/utils"); /** * The queue of edits by filePath that we still have to send */ var pendingQueue = Object.create(null); function addToQueue(filePath, edit) { // Batch by by filePath and setup for sending later if (!pendingQueue[filePath]) pendingQueue[filePath] = []; pendingQueue[filePath].push(edit); // Mark for sending exports.delayedFlushQueue(); } exports.addToQueue = addToQueue; function flushQueue() { Object.keys(pendingQueue).forEach(function (filePath) { var edits = pendingQueue[filePath]; socketClient_1.server.editFile({ filePath: filePath, edits: edits }); /** Clear for future */ delete pendingQueue[filePath]; }); } exports.flushQueue = flushQueue; /** * Note: this delay must be less than any other delays * (e.g. autocomplete throttling should be more than this). * WARNING: making it big breaks `formattingEditsAfterKeystroke` */ exports.delayedFlushQueue = utils.throttle(flushQueue, 1);