local proxy for EventEmitter
330851
function _emitChange(propname/*, arg1, ..., argX*/) {
        var args = arguments
        var kp = $normalize($join(_rootPath(), propname))
        args[0] = CHANGE_EVENT + ':' + kp
        _emitter.emit(CHANGE_EVENT, kp)
        emitter.emit.apply(emitter, args)

        args = $util.copyArray(args)
        args[0] = kp
        args.unshift('*')
        emitter.emit.apply(emitter, args)
    }
577570
function eventEmitter(ctor) {
  for (var prop in EventEmitter.prototype) {
    if (EventEmitter.prototype.hasOwnProperty(prop)) {
      ctor.prototype[prop] = EventEmitter.prototype[prop];
    }
  }
}
411644
function Channel(bus, name, local, remote) {
  events.EventEmitter.call(this);
  this.bus = bus;
  this.name = name;
  this.type = 'channel';
  this.id = 'bus:channel:' + name;
  this.logger = bus.logger.withTag(name);
  this.local = local || 'local';
  this.remote = remote || 'remote';

  this.handlers = {
    '1': this._onRemoteConnect,
    '2': this._onMessage,
    '3': this._onRemoteDisconnect,
    '4': this._onEnd
  }
}
406745
function proxy() {
    // cannot re-use cmd, modifiying breaks subsequent
    // method invocations must use a local variable
    var name = cmd
      , args = [].slice.call(arguments)
      , cb;

    if(typeof args[args.length - 1] === 'function') {
      cb = args.pop();
    }
    this.execute(cmd, args, cb);
    return this;
  }
1309440
function emit(name, args, thisArg, delay) {
        var list = eventHandlers[name];
        if ( list ) {
            thisArg || (thisArg = this);
            if ( args ) {
                args = args.slice(); // make a copy
                args.unshift(name);
            }
            else {
                args = [name];
            }
            _.each(list, function (hdl, idx) {
                // var _args = args.slice();
                delay > -1
                    ? setTimeout(function () {
                        hdl.apply(thisArg, args);
                      }, delay)
                    : hdl.apply(thisArg, args)
                ;
            });
        }
        return this;
    }
283770
function Channel(url, protocol) {
  events.EventEmitter.call(this)

  this._url      = url
  this._protocol = protocol
}
1038910
function BaseLauncher (id, emitter) {
  if (this.start) {
    return
  }

  // TODO(vojta): figure out how to do inheritance with DI
  Object.keys(EventEmitter.prototype).forEach(function (method) {
    this[method] = EventEmitter.prototype[method]
  }, this)

  this.bind = KarmaEventEmitter.prototype.bind.bind(this)
  this.emitAsync = KarmaEventEmitter.prototype.emitAsync.bind(this)

  this.id = id
  this._state = null
  Object.defineProperty(this, 'state', {
    get: () => {
      return this._state
    },
    set: (toState) => {
      log.debug(`${this._state} -> ${toState}`)
      this._state = toState
    }
  })

  this.error = null

  let killingPromise
  let previousUrl

  this.start = function (url) {
    previousUrl = url

    this.error = null
    this.state = BEING_CAPTURED
    this.emit('start', url + '?id=' + this.id + (helper.isDefined(this.displayName) ? '&displayName=' + encodeURIComponent(this.displayName) : ''))
  }

  this.kill = function () {
    // Already killed, or being killed.
    if (killingPromise) {
      return killingPromise
    }

    killingPromise = this.emitAsync('kill').then(() => {
      this.state = FINISHED
    })

    this.state = BEING_KILLED

    return killingPromise
  }

  this.forceKill = function () {
    this.kill()
    this.state = BEING_FORCE_KILLED

    return killingPromise
  }

  this.restart = function () {
    if (this.state === BEING_FORCE_KILLED) {
      return
    }

    if (!killingPromise) {
      killingPromise = this.emitAsync('kill')
    }

    killingPromise.then(() => {
      if (this.state === BEING_FORCE_KILLED) {
        this.state = FINISHED
      } else {
        killingPromise = null
        log.debug(`Restarting ${this.name}`)
        this.start(previousUrl)
      }
    })

    this.state = RESTARTING
  }

  this.markCaptured = function () {
    if (this.state === BEING_CAPTURED) {
      this.state = CAPTURED
    }
  }

  this.isCaptured = function () {
    return this.state === CAPTURED
  }

  this.toString = function () {
    return this.name
  }

  this._done = function (error) {
    killingPromise = killingPromise || Promise.resolve()

    this.error = this.error || error
    this.emit('done')

    if (this.error && this.state !== BEING_FORCE_KILLED && this.state !== RESTARTING) {
      emitter.emit('browser_process_failure', this)
    }

    this.state = FINISHED
  }

  this.STATE_BEING_CAPTURED = BEING_CAPTURED
  this.STATE_CAPTURED = CAPTURED
  this.STATE_BEING_KILLED = BEING_KILLED
  this.STATE_FINISHED = FINISHED
  this.STATE_RESTARTING = RESTARTING
  this.STATE_BEING_FORCE_KILLED = BEING_FORCE_KILLED
}
805769
function emit(eventName, data, parent) {
    if (!this.__listeners || !this.__listeners[eventName]) {
        return;
    }

    let self = this,
        event = new Event(eventName, data, this, parent);

    this
        .getListeners(eventName)
        .forEach((config) => {
            if (config.once === true) {
                self.off(eventName, config.fn, config.context, config.args, config.once);
            }
            execute(event, config);
        });
}
133761
function(event) {
            var args = Array.prototype.slice.call(arguments);
            (this.emitter || (this.emitter = new emitter())).emit.apply(this, args);
        }
733407
function EventEmitter() {
    var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

    _classCallCheck(this, EventEmitter);

    this._events = {};
    if (opts.async) this.emit = emitAsync;
  }
974498
function EventReactor(options, proto) {
    // allow initialization without a new prefix
    if (!(this instanceof EventReactor)) return new EventReactor(options, proto);

    options = options || {};
    this.restore = {};

    // don't attach the extra event reactor methods, we are going to apply them
    // manually to the prototypes
    if (options.manual) return this;

    var methods = EventReactor.generation
      , method;

    for (method in methods) {
      if (methods.hasOwnProperty(method)) {
        this[method](proto);
      }
    }

    // such as aliases and emit overrides
    this.aliases(proto);
    this.emit(proto);
  }
736086
function(port, host, opts) {
  if (!(this instanceof Connector)) {
    return new Connector(port, host, opts);
  }

  EventEmitter.call(this);
  this.port = port;
  this.host = host;
  this.opts = opts || {};

  this.adaptor = new Adaptor(this.opts);
}
89158
function emitter(event, payload)
{
  // get proper name
  var normalized = normalize(event);

  // notify listeners
  this.emit(normalized, payload);

  // notify listeners of the specific type
  if (payload['template_type'])
  {
    this.emit([normalized, payload['template_type']].join('.'), payload);
  }
  else if (payload.type)
  {
    this.emit([normalized, normalize(payload.type)].join('.'), payload);
  }
}
809914
function Proxy(host, port, user, pass) {
  if (!(this instanceof Proxy))
    return new Proxy(host, port, user, pass);

  EventEmitter.call(this);

  assert(typeof host === 'string');
  assert(typeof port === 'number');

  this.socket = null;
  this.host = host;
  this.port = port;
  this.username = user || null;
  this.password = pass || null;
  this.bytesWritten = 0;
  this.bytesRead = 0;
  this.remoteAddress = null;
  this.remotePort = 0;
  this.ops = [];
}
1223468
function ElementsEventHandler(socket) {
  var _this = this;
  //Call EventEmmiter _contructor_
  events.EventEmitter.call(this);
  this.socket = socket;

  // On every message event received by socket we get
  // an message event object like {event:, data:} 
  // we emit  a local event through an EventEmitter interface
  // with .event as event type and .data as
  // event data;
  this.socket.on('message', function(message, callback) {
    debug("Forwarding frontend message '%s', with data %j", message.event, message.data);
    if (message.event !== undefined) {
      _this.emit(message.event, message.data);
      if (typeof callback === 'function') {
        callback();
      }
    }
    if (message.event === "userinput" && message.scope !== undefined) {
      debug("userinput received: %s", JSON.stringify(message));
      _this.emit(message.scope, message.data);
    }
  });
  this.socket.on("disconnect", function() {
    delete(this.socket);
    _this.emit("disconnect");
  });
}
856215
function emitAndFire(widget, eventName, eventArg) {
    const originalEmit = widget.emit;
    let event;
    if ('CustomEvent' in window && typeof window.CustomEvent === 'function') {
        event = new CustomEvent(eventName, { detail: eventArg });
    } else {
        event = document.createEvent('CustomEvent');
        event.initCustomEvent(eventName, true, true, eventArg);
    }
    widget.el.dispatchEvent(event);
    originalEmit.call(widget, eventName, eventArg);
}
901585
function loggerEmitter(opts) {

  if (!(this instanceof loggerEmitter)) return new loggerEmitter(opts); // new is optional
  events.EventEmitter.call(this);
  opts = opts || {};
  var logger = this;

  logger.noConsole   = opts.noConsole || false;
  logger.noErrors    = opts.noErrors  || false;
  logger.log         = log;
  logger.log.logger  = logger;
  logger.log.inspect = inspect;

  function log(x) {
    var msg;
    if (util.isError(x)) {
      msg = x.stack || x.message;
      if (!logger.noErrors) {
        logger.emit('error', x); // throws if no listener
      }
      else {
        logger.emit('log', msg);
      }
    }
    else {
      msg = util.format.apply(logger, arguments);
      logger.emit('log', msg);
    }

    if (!logger.noConsole) {
      console.log(msg);
    }

    return msg;
  }

  function inspect() { return 'logger-emitter'; }
}