What does this do?
This plugin augments the generic plugin functionality that ships with [base][].
- Without this plugin, any plugins that registered with the
use
method and are only called once upon init. - With this plugin, other plugins that return a function will be pushed onto a
plugins
array, and can be called again later with therun
method.
var plugins = require('{%= name %}');
var Base = require('base');
var base = new Base();
// register the `plugins` plugin
base.use(plugins());
Once the use
method is called:
- a
fns
array is added to the instance for storing plugin functions - a
run
method is added to the instance for running stored plugins - the
use
method is modified so that anytime a function is returned by a plugin, the function will be pushed onto thefns
array. Aside from that, you shouldn't see any difference in how theuse
method 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'
{%= apidocs('index.js') %}