All files / src SubscribeResult.js

100% Statements 14/14
100% Branches 4/4
100% Functions 4/4
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42          9x 9x 9x             1x 7x 1x     6x     7x                 1x 1x 1x   1x 3x       1x  
/**
 * Sugar-code handling the result of a Room.renew call
 * @constructor
 */
function SubscribeResult() {
  this.cbs = [];
  this.error = null;
  this.room = null;
}
 
/**
 * Registers a callback to be called with a subscription result
 * @param {Function} cb
 */
SubscribeResult.prototype.onDone = function (cb) {
  if (this.error || this.room) {
    cb(this.error, this.room);
  }
  else {
    this.cbs.push(cb);
  }
 
  return this;
};
 
/**
 * Calls all registered callbacks
 *
 * @param {Object} error object
 * @param {Room} room
 */
SubscribeResult.prototype.done = function (error, room) {
  this.error = error;
  this.room = room;
 
  this.cbs.forEach(function (cb) {
    cb(error, room);
  });
};
 
module.exports = SubscribeResult;