Comparing version 0.6.3 to 0.6.4
61
index.js
@@ -26,14 +26,9 @@ 'use strict'; | ||
} | ||
this.initBase(config); | ||
} | ||
this.define('_callbacks', this._callbacks); | ||
this.options = this.options || {}; | ||
this.cache = this.cache || {}; | ||
/** | ||
* Prototype methods | ||
*/ | ||
if (name) this[name] = {}; | ||
if (typeof config === 'object') { | ||
this.visit('set', config); | ||
} | ||
utils.run(this, 'use', fns); | ||
} | ||
Base.prototype = Emitter({ | ||
@@ -43,2 +38,20 @@ constructor: Base, | ||
/** | ||
* Initialize `Base` defaults with the given `config` object | ||
*/ | ||
initBase: function(config) { | ||
this.define('_callbacks', this._callbacks); | ||
this.define('_isRegistered', {}); | ||
this.options = this.options || {}; | ||
this.cache = this.cache || {}; | ||
if (name) this[name] = {}; | ||
if (typeof config === 'object') { | ||
this.visit('set', config); | ||
} | ||
utils.run(this, 'use', fns); | ||
}, | ||
/** | ||
* Convenience method for assigning a `name` on the instance | ||
@@ -55,2 +68,30 @@ * for doing lookups in plugins. | ||
/** | ||
* Returns true if a plugin has already been registered on an instance. | ||
* This is optionally used by plugin implementors to prevent plugins | ||
* from being called on an instanced more than once. | ||
* | ||
* ```js | ||
* var base = new Base(); | ||
* base.use(function(app) { | ||
* if (app.isRegistered('myPlugin')) { | ||
* return; | ||
* } | ||
* // do stuff | ||
* }); | ||
* ``` | ||
* @name .isRegistered | ||
* @param {String} `name` The plugin name. | ||
* @return {Boolean} Returns true when a plugin is already registered. | ||
* @api public | ||
*/ | ||
isRegistered: function(name) { | ||
if (this._isRegistered.hasOwnProperty(name)) { | ||
return true; | ||
} | ||
this._isRegistered[name] = true; | ||
return false; | ||
}, | ||
/** | ||
* Define a plugin function to be called immediately upon init. | ||
@@ -57,0 +98,0 @@ * Plugins are chainable and the only parameter exposed to the |
{ | ||
"name": "base", | ||
"description": "base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting with a handful of common methods, like `set`, `get`, `del` and `use`.", | ||
"version": "0.6.3", | ||
"version": "0.6.4", | ||
"homepage": "https://github.com/node-base/base", | ||
@@ -6,0 +6,0 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
23247
408
0