Emits to this Spark.

@param {String} ev The event
@param {Mixed} [data] The data to broadcast
@param {Function} [fn] The callback function
@return {Primus|Spark} this
@api public
488493
function send(ev, data, fn) {
            /* jshint validthis: true */
            // ignore newListener event to avoid this error in node 0.8
            // https://github.com/cayasso/primus-emitter/issues/3
            if (/^(newListener|removeListener)/.test(ev)) return this;
            this.emitter.send.apply(this.emitter, arguments);
            return this;
          }
1030531
function fireEvent (element, type, data) {
  const evt = document.createEvent('Event')
  evt.data = data
  for (const k in data) {
    if (data.hasOwnProperty(k)) {
      evt[k] = data[k]
    }
  }
  // need bubble.
  evt.initEvent(type, true, true)

  element.dispatchEvent(evt)
}
819016
function parse(primus, raw, res) {
  var called = 0
    , data
    , err;

  try {
    data = JSON.parse(raw);
  } catch (e) {
    err = e;
  }

  if (
       err                              // No error..
    || 'object' !== typeof data         // Should be an object.
    || Array.isArray(data)              // A real object, not array.
    || !data.msg                        // The data we send should be defined.
  ) {
    res.statusCode = 500;
    res.setHeader('Content-Type', 'application/json');
    return res.end('{ "ok": false, "reason": "invalid data structure" }');
  }

  //
  // Process the incoming messages in three different modes:
  //
  // Sparks: The data.sparks is an array with spark id's which we should write
  //         the data to.
  // Spark:  The data.sparks is the id of one single individual spark which
  //         should receive the data.
  // All:    Broadcast the message to every single connected spark if no
  //         `data.sparks` has been provided.
  //
  if (Array.isArray(data.sparks)) {
    data.sparks.forEach(function each(id) {
      var spark = primus.spark(id);

      if (spark) {
        spark.write(data.msg);
        called++;
      }
    });
  } else if ('string' === typeof data.sparks && data.sparks) {
    var spark = primus.spark(data.sparks);

    if (spark) {
      spark.write(data.msg);
      called++;
    }
  } else {
    primus.forEach(function each(spark) {
      spark.write(data.msg);
      called++;
    });
  }

  res.statusCode = 200;
  res.setHeader('Content-Type', 'application/json');
  res.end('{ "ok": true, "send":'+ called +' }');
}
1361970
function(ev) {
		if (!ev) { ev = w.event; }
		if (!ev) { ev = { name: "load" }; }
		if(impl.onloadfired) {
			return this;
		}
		impl.fireEvent("page_ready", ev);
		impl.onloadfired = true;
		return this;
	}
43869
function(ev) {
    if (fireHoldCount > 0) {
      heldEvents.push(ev);
      if (eventDebug) {
        console.log('Held fire: ' + name, ev);
      }
      return;
    }

    if (eventDebug) {
      console.group('Fire: ' + name + ' to ' + handlers.length + ' listeners', ev);
    }

    // Use for rather than forEach because it step debugs better, which is
    // important for debugging events
    for (var i = 0; i < handlers.length; i++) {
      var handler = handlers[i];
      if (eventDebug) {
        console.log(nameFunction(handler));
      }
      handler.func.call(handler.scope, ev);
    }

    if (eventDebug) {
      console.groupEnd();
    }
  }
857680
function listen(event, spark) {
    if ('end' === event) return function end() {
      if (!spark.streams) return;

      for (var stream in spark.streams) {
        stream = spark.streams[stream];
        if (stream.end) stream.end();
      }
    };

    if ('readyStateChange' === event) return function change(reason) {
      if (!spark.streams) return;

      for (var stream in spark.streams) {
        stream = spark.streams[stream];
        stream.readyState = spark.readyState;
        if (stream.emit) emit.call(stream, event, reason);
      }
    };

    return function proxy() {
      if (!spark.streams) return;

      var args = Array.prototype.slice.call(arguments, 0);

      for (var stream in spark.streams) {
        if (stream.emit) emit.call(stream, [event].concat(args));
      }
    };
  }
737976
function (fn) {
    var self = this;

    var evtCount = 0;
    var eventQueue = [];
    var eventQueueHandling = false;

    var errs = [];
    var doneCalled = false;
    var doneClb = null;

    var revisionMap = {};
    var collections = {};

    var lastEvent;

    var seenEvents = {};

    var replay = function (evt) {
      var evtId = dotty.get(evt, self.definition.id);
      lastEvent = evt;
      var concatenatedId;
      if (!!self.definition.revision && dotty.exists(evt, self.definition.revision) &&
        !!self.definition.aggregateId && dotty.exists(evt, self.definition.aggregateId)) {
        concatenatedId = self.getConcatenatedId(evt);
        revisionMap[concatenatedId] = dotty.get(evt, self.definition.revision);
      }

      var concatenatedWithEventId = evtId;
      if (concatenatedId) concatenatedWithEventId = concatenatedId + ':' + evtId;
      if (seenEvents[concatenatedWithEventId]) return;
      seenEvents[concatenatedWithEventId] = true;

      var target = self.dispatcher.getTargetInformation(evt);

      var viewBuilders = [], foundPrioSet = false;

      _.each(self.dispatcher.tree.getViewBuilders(target), function (vb) {
        if (!vb.collection.noReplay) {
          viewBuilders.push(vb);

          if (!foundPrioSet && vb.priority < Infinity) {
            foundPrioSet = true;
          }

          if (!collections[vb.collection.workerId]) {
            vb.collection.isReplaying = true;
            collections[vb.collection.workerId] = vb.collection;
          }
        }
      });

      if (foundPrioSet) {
        _.each(viewBuilders, function (vb) {
          eventQueue.push({event: evt, viewBuilders: [vb]});
          evtCount++;
        });
      } else {
        eventQueue.push({event: evt, viewBuilders: viewBuilders});
        evtCount += viewBuilders.length;
      }

      function handleNext () {
        if (evtCount <= 0 && doneCalled) {
          doneLater();
          return;
        }

        if (eventQueue.length > 0) {
          var task = eventQueue.shift();
          var e = task.event, vbs = task.viewBuilders;

          async.series([
            function (clb) {
              var preEventExtender = self.dispatcher.tree.getPreEventExtender(self.dispatcher.getTargetInformation(e));
              if (!preEventExtender) return clb(null);
              preEventExtender.extend(e, function (err, extEvt) {
                if (err) return clb(err);
                e = extEvt || e;
                clb(null);
              });
            },
            function (clb) {
              async.each(vbs, function (vb, callback) {
                vb.denormalize(e, function (err) {
                  --evtCount;
                  if (err) {
                    debug(err);
                    errs.push(err);
                  }

                  callback();
                });
              }, clb);
            }
          ], function () {
            handleNext();
          });
        } else if (eventQueueHandling) {
          eventQueueHandling = false;
        }
      }

      if (!eventQueueHandling) {
        eventQueueHandling = true;
        process.nextTick(handleNext);
      }
    };

    function doneLater() {
      if (doneCalled) {
        done(doneClb);
      }
    }

    var done = function (callback) {
      if (evtCount > 0) {
        doneCalled = true;
        doneClb = callback;
        return;
      }

      async.parallel([
        function (callback) {
          async.each(_.values(collections), function (col, callback) {
            col.saveReplayingVms(callback);
          }, callback);
        },
        function (callback) {
          self.updateRevision(revisionMap, callback);
        },
        function (callback) {
          self.store.saveLastEvent(lastEvent, callback);
        }
      ], function (err) {
        seenEvents = {};

        if (err) {
          debug(err);
          errs.push(err);
        }

        if (errs.length === 0) {
          if (callback) {
            callback(null);
          }
          return;
        }

        if (callback) {
          callback(errs);
        }
      });
    };

    fn(replay, done);
  }
206874
function broadcast(event, data, destination) {
        if (!crosstab.supported) {
            notSupported();
        }

        var message = {
            id: util.generateId(),
            event: event,
            data: data,
            destination: destination,
            origin: crosstab.id,
            timestamp: util.now()
        };

        // If the destination differs from the origin send it out, otherwise
        // handle it locally
        if (message.destination !== message.origin) {
            setLocalStorageItem(util.keys.MESSAGE_KEY, message);
        }

        if (!message.destination || message.destination === message.origin) {
            eventHandler.emit(event, message);
        }
    }
358038
function emitEvent(payload, eventNameBase, debugParams) {

        // create a copy of the payload so that nothing modifies the original object
        try {
            payload = JSON.parse(JSON.stringify(payload));
        }
        catch (err) {
            /* eslint no-console:0 */
            console.log('issue parsing during emit ' + JSON.stringify(eventNameBase));
        }

        // we don't want to emit the potentially huge resource file
        if (payload && payload.resource) {
            delete payload.resource;
        }

        // create the event data and emit the event
        var name = _.extend({}, eventNameBase, debugParams);
        var eventData = {
            name: name,
            payload: payload
        };
        var eventName = name.resource + '.' + name.adapter + '.' + name.method;
        eventName += debugParams ? '.' + name.type + '.' + name.timing : '';
        eventBus.emit(eventName, eventData);
    }
562299
function(evname, callback, context) {
    if (!evname && !callback && !context) {
      this._events = {};
      return this;
    } else if (!evname) {
      for (var _evname in this._events) {
        this.off(_evname, callback, context);
      }
      return this;
    } else {
      var fns = this._events[evname], l = fns.length;
      while (l--) {
        if ((callback ? fns[l].cb === callback : true) && (context ? fns[l].ctxt === context : true)) {
          fns.splice(l, 1);
        }
      }
      return this;
    }
  }
295153
public EventBus emitSync(String event, Object... args) {
        return _emitWithOnceBus(eventContextSync(event, args));
    }
547004
function emitElement(element, name, onLeave) {
  if (Array.isArray(element)) {
    var i;
    for (i = 0; i < element.length - 1; i++) {
      emitOneElement.call(this, element[i], name);
    }
    emitOneElement.call(this, element[i], name, onLeave);
  } else {
    emitOneElement.call(this, element, name, onLeave);
  }
}
59184
function(proto) {
        function F() {}
        this.merge(F.prototype, proto || {}, (function() {
            var Events = function() {};
            Events.prototype = EventEmitter.prototype;
            return new Events();
        })());
        return new F();
    }
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");
  });
}
302836
function(ev, callback, context) {
      var calls = this._callbacks || (this._callbacks = {});
      var list  = calls[ev] || (calls[ev] = []);
      list.push([callback, context]);
      return this;
    }
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'; }
}
1097988
def emit(event, *data)
      sync_exclusive do
        [event.type].each do |hook_type|
          any_state_or_event = HookEvent.any_state_or_event(hook_type)
          [any_state_or_event, event.name].each do |event_name|
            hooks[hook_type][event_name].each do |hook|
              handle_callback(hook, event, *data)
              off(hook_type, event_name, &hook) if hook.is_a?(Once)
            end
          end
        end
      end
    end