"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _mobx = require("mobx");

var _debounce = _interopRequireDefault(require("lodash/debounce"));

var _utils = require("../data-set/utils");

var BatchRunner = /*#__PURE__*/function () {
  function BatchRunner() {
    var batchInterval = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100;
    (0, _classCallCheck2["default"])(this, BatchRunner);
    this.run = (0, _debounce["default"])((0, _mobx.action)(function (tasks) {
      tasks.forEach(function (task) {
        return task();
      });
      tasks.clear();
    }), batchInterval);
  }

  (0, _createClass2["default"])(BatchRunner, [{
    key: "addTask",
    value: function addTask(key, callback) {
      this.run((0, _utils.getIf)(this, 'task', function () {
        return new Map();
      }).set(key, callback));
    }
  }]);
  return BatchRunner;
}();

exports["default"] = BatchRunner;
//# sourceMappingURL=BatchRunner.js.map
