Skip to content

Latest commit

 

History

History
51 lines (36 loc) · 1.29 KB

.verb.md

File metadata and controls

51 lines (36 loc) · 1.29 KB

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 the run method.

Usage

var plugins = require('{%= name %}');
var Base = require('base');
var base = new Base();

// register the `plugins` plugin
base.use(plugins());

Examples

.use example

Once the use method is called:

  1. a fns array is added to the instance for storing plugin functions
  2. a run method is added to the instance for running stored plugins
  3. the use method is modified so that anytime a function is returned by a plugin, the function will be pushed onto the fns array. Aside from that, you shouldn't see any difference in how the use method works.

.run example

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'

API

{%= apidocs('index.js') %}