import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
var ADFTraversor = /*#__PURE__*/function () {
  function ADFTraversor(doc) {
    _classCallCheck(this, ADFTraversor);
    _defineProperty(this, "subscribers", new Map());
    this.doc = doc;
  }
  _createClass(ADFTraversor, [{
    key: "subscribe",
    value: function subscribe(type, callback) {
      var callbacks = this.subscribers.get(type);
      if (!callbacks) {
        this.subscribers.set(type, [callback]);
      } else {
        callbacks.push(callback);
      }
    }
  }, {
    key: "exec",
    value: function exec() {
      if (!this.doc || !Array.isArray(this.doc.content)) {
        return;
      }
      var candidates = this.doc.content.slice(0);
      while (candidates.length) {
        var _node = candidates.shift();
        if (Array.isArray(_node.content)) {
          candidates = candidates.concat(_node.content);
        }
        var callbacks = this.subscribers.get(_node.type);
        if (!callbacks) {
          continue;
        }
        for (var i = 0; i < callbacks.length; i++) {
          callbacks[i](_node);
        }
      }
    }
  }]);
  return ADFTraversor;
}();
export default ADFTraversor;