lib/spike/index.js
function (bin, data, statsRequest) {
    var id = bin.id,
        delayTrigger = 500;

    if (!pending[id]) {
      pending[id] = {};
    }

    pending[id].bin = bin;
    pending[id][data.panelId] = utils.process(data, bin.settings);

    // Clear the previous ping
    clearTimeout(pending[id].timer);

    // NOTE: this will only fire once per jsbin session -
    // not for every panel sent - because we clear the timer
    pending[id].timer = setTimeout(function () {
      var session = utils.sessionForBin(bin),
          data = null,
          ping = pending[id];


      if (!ping) { return; }

      // Javascript and HTML cause reloads. CSS is injected.
      data = ping.javascript || ping.html || ping.css || (statsRequest ? {} : false);

      // Forget this ping, it's done with now
      delete pending[id];

      if (!data) { return; }
      if (!session) { return; }

      // Send the update to all connected sessions in original and raw flavours
      session.res.forEach(function (res) {
        var raw = data.raw || data.content;
        if (!res.req.stats) {
          res.write(utils.makeEvent(data.panelId, raw));
          res.write(utils.makeEvent(data.panelId + ':processed', data.content));
        }
        res.write(utils.makeEvent('stats', { connections: session.res.filter(function (res) {
          return !res.req.stats;
        }).length }));
        if (res.ajax && !statsRequest) {
          res.end(); // lets older browsers finish their xhr request
          res.req.emit('close');
        }
      });

    }, delayTrigger);
  }
function (bin, data, statsRequest) {
    var id = bin.id,
        delayTrigger = 500;

    if (!pending[id]) {
      pending[id] = {};
    }

    pending[id].bin = bin;
    pending[id][data.panelId] = utils.process(data, bin.settings);

    // Clear the previous ping
    clearTimeout(pending[id].timer);

    // NOTE: this will only fire once per jsbin session -
    // not for every panel sent - because we clear the timer
    pending[id].timer = setTimeout(function () {
      var session = utils.sessionForBin(bin),
          data = null,
          ping = pending[id];


      if (!ping) { return; }

      // Javascript and HTML cause reloads. CSS is injected.
      data = ping.javascript || ping.html || ping.css || (statsRequest ? {} : false);

      // Forget this ping, it's done with now
      delete pending[id];

      if (!data) { return; }
      if (!session) { return; }

      // Send the update to all connected sessions in original and raw flavours
      session.res.forEach(function (res) {
        var raw = data.raw || data.content;
        if (!res.req.stats) {
          res.write(utils.makeEvent(data.panelId, raw));
          res.write(utils.makeEvent(data.panelId + ':processed', data.content));
        }
        res.write(utils.makeEvent('stats', { connections: session.res.filter(function (res) {
          return !res.req.stats;
        }).length }));
        if (res.ajax && !statsRequest) {
          res.end(); // lets older browsers finish their xhr request
          res.req.emit('close');
        }
      });

    }, delayTrigger);
  }
function ( bin , data , statsRequest ) { var id = bin . id , delayTrigger = 500 ; if ( ! pending [ id ] ) { pending [ id ] = { } ; } pending [ id ] . bin = bin ; pending [ id ] [ data . panelId ] = utils . process ( data , bin . settings ) ; // Clear the previous ping clearTimeout ( pending [ id ] . timer ) ; // NOTE: this will only fire once per jsbin session - // not for every panel sent - because we clear the timer pending [ id ] . timer = setTimeout ( function ( ) { var session = utils . sessionForBin ( bin ) , data = null , ping = pending [ id ] ; if ( ! ping ) { return ; } // Javascript and HTML cause reloads. CSS is injected. data = ping . javascript || ping . html || ping . css || ( statsRequest ? { } : false ) ; // Forget this ping, it's done with now delete pending [ id ] ; if ( ! data ) { return ; } if ( ! session ) { return ; } // Send the update to all connected sessions in original and raw flavours session . res . forEach ( function ( res ) { var raw = data . raw || data . content ; if ( ! res . req . stats ) { res . write ( utils . makeEvent ( data . panelId , raw ) ) ; res . write ( utils . makeEvent ( data . panelId + ':processed' , data . content ) ) ; } res . write ( utils . makeEvent ( 'stats' , { connections : session . res . filter ( function ( res ) { return ! res . req . stats ; } ) . length } ) ) ; if ( res . ajax && ! statsRequest ) { res . end ( ) ; // lets older browsers finish their xhr request res . req . emit ( 'close' ) ; } } ) ; } , delayTrigger ) ; }
Notify connected clients of an update to a bin
Notify connected clients of an update to a bin