Example #1
0
  if ('/' === url.charAt(0) && 0 !== url.indexOf(root)) {
    url = root + url;
  }

  this.canonicalUrl = url;
  this.client = client;
  this.url = url.substr(root.length) || '/';
  this.state = state || {};
}

/*!
 * Provide configuration (get/set/etc)
 */

facet(Context, 'state', true);

/*!
 * ### .emit (ev, key, value)
 *
 * A context is not an event emitter, but facet will
 * invoke this function on the change of a state by
 * the user. This allows us to hook into that change
 * and save the state (if possible).
 *
 * @param {String} event (`state`)
 * @api public
 */

Context.prototype.emit = function (ev) {
  if (ev !== 'state') return;
Example #2
0
 */

inherits(Base, EventEmitter);

/*!
 * Mount facet helpers
 */

facet(Base.prototype, function (key, value) {
  key = key.toLowerCase();

  // handle queue concurrency change
  if (key === 'concurrency') {
    if ('number' !== typeof value) {
      throw new Error('.set(\'concurrency\') fail: value must be a number');
    }

    if (value <= 0) {
      throw new Error('.set(\'concurrency\') fail: value must be greater than zero');
    }

    this.queue._concurrency = value;
  }
});

Object.defineProperty(Base.prototype, 'length', {
  get: function () {
    return this.queue.length;
  }
});

/**
Example #3
0
 * @api public
 */

function Definition (key, msg) {
  this._key = key;
  this._message = 'Undefined message for error: ' + key + '.';
  debug('(constructed) %s', this._key);
  if (msg) this.message(msg);
}

/*!
 * Getters/Setters provided by facet.
 */

facet(Definition.prototype, '_props', function (key, value) {
  debug('[%s] (property) %s: %j', this._key, key, value);
});

/**
 * ### .message ([msg])
 *
 * Set or get the default message for this
 * definition.
 *
 * @param {String} message
 * @returns {this|String} `this` if setting
 * @api public
 */

Definition.prototype.message = function (msg) {
  if (arguments.length) {
Example #4
0
/*!
 * Primary export
 */

module.exports = Remote;

function Remote() {
  if (!(this instanceof Remote)) return new Remote;
  this.hooks = {};
  this.disable('secure');
  this.set('host', 'localhost');
  this.set('port', 4243);
}

facet(Remote.prototype);

Remote.prototype.addHook = function(ns, fn) {
  ns = ns.toLowerCase().trim().replace(/\s/g, ':');
  debug('(hook:add) %s #%s', ns, fn.name || 'unnamed hook');
  this.hooks[ns] = fn;
  return this;
};

Remote.prototype.removeHook = function(ns) {
  ns = ns.toLowerCase().trim().replace(/\s/g, ':');
  debug('(hook:remove) -%s', ns);
  this.hooks[ns] = null;
  return this;
};