lib/application.js
function loadHooks() {
  var events = this._events;
  var jsFile = /\.js$/i;
  var hooksPath = this.fullPath('hook');
  var loadedHooks = [];
  if (fs.existsSync(hooksPath)) {
    var files = protos.util.ls(hooksPath, jsFile);
    for (var cb,idx,evt,file,len=files.length,i=0; i < len; i++) {
      file = files[i];
      evt = file.replace(jsFile, '');
      loadedHooks.push(evt);
      cb = protos.require(hooksPath + '/' + file, true);
      if (cb instanceof Function) {
        if (RELOADING) {
          var origCb = this.hooks[evt];
          if (origCb instanceof Function) {
            // Hook was added previously
            if (events[evt] instanceof Array) {
              idx = events[evt].indexOf(origCb);
              if (idx >= 0) {
                // If old function is in events array, replace it
                events[evt][idx] = this.hooks[evt] = cb;
              } else {
                // Otherwise, append to events array (add a new event handler)
                events[evt].push(cb);
                this.hooks[evt] = cb;
              }
            } else if (events[evt] instanceof Function) {
              if (events[evt] === origCb) {
                // If evt has only one callback, replace it
                events[evt] = this.hooks[evt] = cb;
              } else {
                // Otherwise, create an array with the old and new events
                events[evt] = [origCb, cb];
              }
            } // No else clause is needed here, it's either Function or Array
          } else {
            // This is a new event handler
            this.hooks[evt] = cb;
            this.on(evt, cb);
          }
        } else {
          // Add the event handler normally
          this.hooks[evt] = cb;
          this.on(evt, cb);
        }
      }
    }
  }

  // Remove any inexisting hooks
  for (evt in this.hooks) {
    if (loadedHooks.indexOf(evt) === -1) {
      app.removeListener(evt, this.hooks[evt]);
      delete this.hooks[evt];
    }
  }

}
function loadHooks() {
  var events = this._events;
  var jsFile = /\.js$/i;
  var hooksPath = this.fullPath('hook');
  var loadedHooks = [];
  if (fs.existsSync(hooksPath)) {
    var files = protos.util.ls(hooksPath, jsFile);
    for (var cb,idx,evt,file,len=files.length,i=0; i < len; i++) {
      file = files[i];
      evt = file.replace(jsFile, '');
      loadedHooks.push(evt);
      cb = protos.require(hooksPath + '/' + file, true);
      if (cb instanceof Function) {
        if (RELOADING) {
          var origCb = this.hooks[evt];
          if (origCb instanceof Function) {
            // Hook was added previously
            if (events[evt] instanceof Array) {
              idx = events[evt].indexOf(origCb);
              if (idx >= 0) {
                // If old function is in events array, replace it
                events[evt][idx] = this.hooks[evt] = cb;
              } else {
                // Otherwise, append to events array (add a new event handler)
                events[evt].push(cb);
                this.hooks[evt] = cb;
              }
            } else if (events[evt] instanceof Function) {
              if (events[evt] === origCb) {
                // If evt has only one callback, replace it
                events[evt] = this.hooks[evt] = cb;
              } else {
                // Otherwise, create an array with the old and new events
                events[evt] = [origCb, cb];
              }
            } // No else clause is needed here, it's either Function or Array
          } else {
            // This is a new event handler
            this.hooks[evt] = cb;
            this.on(evt, cb);
          }
        } else {
          // Add the event handler normally
          this.hooks[evt] = cb;
          this.on(evt, cb);
        }
      }
    }
  }

  // Remove any inexisting hooks
  for (evt in this.hooks) {
    if (loadedHooks.indexOf(evt) === -1) {
      app.removeListener(evt, this.hooks[evt]);
      delete this.hooks[evt];
    }
  }

}
function loadHooks ( ) { var events = this . _events ; var jsFile = / \.js$ / i ; var hooksPath = this . fullPath ( 'hook' ) ; var loadedHooks = [ ] ; if ( fs . existsSync ( hooksPath ) ) { var files = protos . util . ls ( hooksPath , jsFile ) ; for ( var cb , idx , evt , file , len = files . length , i = 0 ; i < len ; i ++ ) { file = files [ i ] ; evt = file . replace ( jsFile , '' ) ; loadedHooks . push ( evt ) ; cb = protos . require ( hooksPath + '/' + file , true ) ; if ( cb instanceof Function ) { if ( RELOADING ) { var origCb = this . hooks [ evt ] ; if ( origCb instanceof Function ) { // Hook was added previously if ( events [ evt ] instanceof Array ) { idx = events [ evt ] . indexOf ( origCb ) ; if ( idx >= 0 ) { // If old function is in events array, replace it events [ evt ] [ idx ] = this . hooks [ evt ] = cb ; } else { // Otherwise, append to events array (add a new event handler) events [ evt ] . push ( cb ) ; this . hooks [ evt ] = cb ; } } else if ( events [ evt ] instanceof Function ) { if ( events [ evt ] === origCb ) { // If evt has only one callback, replace it events [ evt ] = this . hooks [ evt ] = cb ; } else { // Otherwise, create an array with the old and new events events [ evt ] = [ origCb , cb ] ; } } // No else clause is needed here, it's either Function or Array } else { // This is a new event handler this . hooks [ evt ] = cb ; this . on ( evt , cb ) ; } } else { // Add the event handler normally this . hooks [ evt ] = cb ; this . on ( evt , cb ) ; } } } } // Remove any inexisting hooks for ( evt in this . hooks ) { if ( loadedHooks . indexOf ( evt ) === - 1 ) { app . removeListener ( evt , this . hooks [ evt ] ) ; delete this . hooks [ evt ] ; } } }
Loads application hooks
Loads application hooks