var _layersByHostId = {};
var _defaultHostSelector;
function registerLayer(hostId, callback) {
  if (!_layersByHostId[hostId]) {
    _layersByHostId[hostId] = [];
  }
  _layersByHostId[hostId].push(callback);
}
function unregisterLayer(hostId, callback) {
  if (_layersByHostId[hostId]) {
    var idx = _layersByHostId[hostId].indexOf(callback);
    if (idx >= 0) {
      _layersByHostId[hostId].splice(idx, 1);
      if (_layersByHostId[hostId].length === 0) {
        delete _layersByHostId[hostId];
      }
    }
  }
}
function notifyHostChanged(id) {
  if (_layersByHostId[id]) {
    _layersByHostId[id].forEach(function(callback) {
      return callback();
    });
  }
}
function getDefaultTarget() {
  return _defaultHostSelector;
}

export { getDefaultTarget, notifyHostChanged, registerLayer, unregisterLayer };
