hunk.code_window:  *
    * If called with no arguments, `first` emits the first value of the source
    * Observable, then completes. If called with a `predicate` function, `first`
    * emits the first value of the source that matches the specified condition. It
    * may also take a `resultSelector` function to produce the output value from
    * the input value, and a `defaultValue` to emit in case the source completes
    * before it is able to emit a valid value. Throws an error if `defaultValue`
    * was not provided and a matching element is not found.
    *
    * ## Examples
    * Emit only the first click that happens on the DOM
    * ```javascript
    * const clicks = fromEvent(document, 'click');
  
hunk.labels: keep keep keep keep replace replace replace replace keep keep keep keep keep
hunk.after_edit:  * may also take a deprecated `resultSelector` function to produce the output
    * value from the input value, and a `defaultValue` to emit in case the source
    * completes before it is able to emit a valid value. Throws an error if
    * `defaultValue` was not provided and a matching element is not found.
  
hunk.file_path: src/internal/operators/first.ts
hunk.type: replace
file: module.exports = function targetEnvironments() {
    var _targets = Object.create(null);
    var _activeCount = 0;
  
    var checkAllowed = function(target) {
      if (!(target in _targets)) {
        throw new Error(
            'Error accessing target "' + target + '". It is not in the list of allowed targets: ' +
            Object.keys(_targets));
      }
    };
  
    var updateActiveCount = function() {
      _activeCount = 0;
      for (let target in _targets) {
        if (_targets[target]) _activeCount++;
      }
    };
  
    return {
      addAllowed: function(target, isActive) {
        _targets[target] = !!isActive;
        updateActiveCount();
      },
      removeAllowed: function(target) {
        delete _targets[target];
        updateActiveCount();
      },
      activate: function(target) {
        checkAllowed(target);
        _targets[target] = true;
        updateActiveCount();
      },
      deactivate: function(target) {
        checkAllowed(target);
        _targets[target] = false;
        updateActiveCount();
      },
      isActive: function(target) {
        checkAllowed(target);
        return _targets[target];
      },
      hasActive: function() { return _activeCount > 0; },
      someActive: function(targets) {
        for (var i = 0, ii = targets.length; i < ii; i++) {
          if (this.isActive(targets[i])) return true;
        }
        return false;
      }
    };
  };
  