Upgrade's plugin support in base applications to allow plugins to be called any time after init.
Install with npm:
$ npm install base-plugins --saveWhat does this do?
This plugin augments the generic plugin functionality that ships with base.
- Without this plugin, any plugins that registered with the
usemethod and are only called once upon init. - With this plugin, other plugins that return a function will be pushed onto a
pluginsarray, and can be called again later with therunmethod.
var plugins = require('base-plugins');
var Base = require('base');
var base = new Base();
// register the `plugins` plugin
base.use(plugins());Once the use method is called:
- a
fnsarray is added to the instance for storing plugin functions - a
runmethod is added to the instance for running stored plugins - the
usemethod is modified so that anytime a function is returned by a plugin it will automatically be pushed onto thefnsarray. Besides that, you shouldn't see any behavioral changes in how theusemethod works.
The run method iterates over the fns array and calls each stored plugin function on the given object.
var collection = {};
base.use(function(app) {
app.x = 'y';
return function(obj) {
obj.a = 'b';
};
});
base.run(collection);
console.log(base.x);
//=> 'y'
console.log(collection.a);
//=> 'b'Define a plugin function to be called immediately upon init. The only parameter exposed to the plugin is the application instance.
Also, if a plugin returns a function, the function will be pushed
onto the fns array, allowing the plugin to be called at a
later point, elsewhere in the application.
Params
fn{Function}: plugin function to callreturns{Object}: Returns the item instance for chaining.
Example
// define a plugin
function foo(app) {
// do stuff
}
// register plugins
var app = new Base()
.use(foo)
.use(bar)
.use(baz)Run all plugins
Params
value{Object}: Object to be modified by plugins.returns{Object}: Returns the item instance for chaining.
Example
var config = {};
app.run(config);You might also be interested in these projects:
- base: base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… more | homepage
- base-cli: Plugin for base-methods that maps built-in methods to CLI args (also supports methods from a… more | homepage
- base-config: base-methods plugin that adds a
configmethod for mapping declarative configuration values to other 'base'… more | homepage - base-data: adds a
datamethod to base-methods. | homepage - base-fs: base-methods plugin that adds vinyl-fs methods to your 'base' application for working with the file… more | homepage
- base-options: Adds a few options methods to base-methods, like
option,enableanddisable. See the readme… more | homepage
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Generate readme and API documentation with verb:
$ npm install verb && npm run docsOr, if verb is installed globally:
$ verbInstall dev dependencies:
$ npm install -d && npm testJon Schlinkert
Copyright © 2016, Jon Schlinkert. Released under the MIT license.
This file was generated by verb, v, on March 25, 2016.