lib/demux.js
function Demux(refs, limit) {

  if (!(this instanceof Fireproof.Demux)) {
    return new Fireproof.Demux(refs);
  } else if (arguments.length > 1 && !Array.isArray(refs)) {
    refs = Array.prototype.slice.call(arguments, 0);
  }

  this._limit = (limit !== undefined ? limit : true);
  this._refs = refs;
  this._positions = refs.reduce(function(positions, ref) {

    positions[ref.ref().toString()] = {
      name: undefined,
      priority: undefined
    };

    return positions;

  }, {});

  // we always want there to be a "previous" promise to hang operations from
  this._previousPromise = Fireproof.Promise.resolve([]);

  this._buffer = [];

}
function Demux(refs, limit) {

  if (!(this instanceof Fireproof.Demux)) {
    return new Fireproof.Demux(refs);
  } else if (arguments.length > 1 && !Array.isArray(refs)) {
    refs = Array.prototype.slice.call(arguments, 0);
  }

  this._limit = (limit !== undefined ? limit : true);
  this._refs = refs;
  this._positions = refs.reduce(function(positions, ref) {

    positions[ref.ref().toString()] = {
      name: undefined,
      priority: undefined
    };

    return positions;

  }, {});

  // we always want there to be a "previous" promise to hang operations from
  this._previousPromise = Fireproof.Promise.resolve([]);

  this._buffer = [];

}
function Demux ( refs , limit ) { if ( ! ( this instanceof Fireproof . Demux ) ) { return new Fireproof . Demux ( refs ) ; } else if ( arguments . length > 1 && ! Array . isArray ( refs ) ) { refs = Array . prototype . slice . call ( arguments , 0 ) ; } this . _limit = ( limit !== undefined ? limit : true ) ; this . _refs = refs ; this . _positions = refs . reduce ( function ( positions , ref ) { positions [ ref . ref ( ) . toString ( ) ] = { name : undefined , priority : undefined } ; return positions ; } , { } ) ; // we always want there to be a "previous" promise to hang operations from this . _previousPromise = Fireproof . Promise . resolve ( [ ] ) ; this . _buffer = [ ] ; }
A helper object for retrieving sorted Firebase objects from multiple
locations.
@constructor Fireproof.Demux
@static
@param {Array} refs a list of Fireproof object references to draw from.
@param {boolean} [limitToFirst] Whether to use "limitToFirst" to restrict the length
of queries to Firebase. True by default. Set this to false if you want to
control the query more directly by setting it on the objects you pass to refs.
A helper object for retrieving sorted Firebase objects from multiple locations .