'use strict';
'use babel';

Object.defineProperty(exports, "__esModule", {
  value: true
});
class CompositeDisposable {

  constructor() {
    this.disposed = false;
    this.disposables = new Set(arguments);
  }
  add() {
    if (!this.disposed) {
      var length = arguments.length;
      for (var i = 0; i < length; ++i) {
        this.disposables.add(arguments[i]);
      }
    }
  }
  remove() {
    if (!this.disposed) {
      var length = arguments.length;
      for (var i = 0; i < length; ++i) {
        this.disposables.delete(arguments[i]);
      }
    }
  }
  clear() {
    if (!this.disposed) {
      this.disposables.clear();
    }
  }
  isDisposed() {
    return this.disposed;
  }
  dispose() {
    if (!this.disposed) {
      var _iteratorNormalCompletion = true;
      var _didIteratorError = false;
      var _iteratorError = undefined;

      try {
        for (var _iterator = this.disposables[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
          var item = _step.value;

          item.dispose();
        }
      } catch (err) {
        _didIteratorError = true;
        _iteratorError = err;
      } finally {
        try {
          if (!_iteratorNormalCompletion && _iterator.return) {
            _iterator.return();
          }
        } finally {
          if (_didIteratorError) {
            throw _iteratorError;
          }
        }
      }

      this.disposed = true;
      this.disposables.clear();
    }
  }
}
exports.CompositeDisposable = CompositeDisposable;