plugin.js
This file
Path
lib/express/plugin.js
61 lines · 1.2 KiB · JavaScript
Last changed by
Merge branch 'class'visionmediabefore adoption2aa858b
History of this fileTake it
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
// Express - Plugin - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
/** * Module dependencies. */
var utils = require('express/utils');
/** * Push _plugin_ with _options_ to the plugin stack. * If _plugin_ has already been pushed, then it's options * will override any previously set. * * @param {Plugin} plugin * @param {hash} options * @api public */
exports.use = function(plugin, options) { if (Express.environment === 'test' && 'init' in plugin) plugin.init(options) Express.plugins.each(function(other, i){ if (other.klass === plugin) delete Express.plugins[i] }) Express.plugins.push({ klass: plugin, options: options })}
// --- Plugin
exports.Plugin = new Class({ /** * Initialize with _options_. * * @param {hash} options * @api private */ constructor: function(options) { if (options) utils.mixin(this, options) }, /** * Trigger handler for the given _event_. * * @param {Event} event * @api private */ trigger: function(event, callback) { if ('on' in this) if (event.name in this.on) return this.on[event.name].call(this, event, callback) }})