Skip to content

Mixdown app and base plugin implementation for mixdown.js 3.x and above.

License

Notifications You must be signed in to change notification settings

mixdown/mixdown-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mixdown-app

Mixdown app and base plugin implementation.

Create a Plugin

Plugins use the Resig Class extend pattern for injecting plugin interfaces.

var BasePlugin = require('../../index.js').Plugin;

var HelloPlugin = BasePlugin.extend({
  hello: function() {
    this.count++;
    return 'Hello ' + this._options.name;
  },
  count: -100,
  _setup: function(done) {
    this.count = 0;
    done();
  }
});

module.exports = HelloPlugin;
  • _setup: run plugin initialization

IMPORTANT: All values are converted to getter/setter functions. The extend pattern provides a much smaller and simpler interface for creating plugins, but the internals of BasePlugin and Class.extend() require that they are wrapped in order to persist the correct values.

The wrapped getter/setter looks like this for the above example. If val is passed, then the value is set. If not passed, then the value is simply returned.

count: function(val);

Create an App

var App = require('mixdown-app').App;
var HelloPlugin = require('path-to-above-plugin');

var app = new App();
app.use(new HelloPlugin('foo', { name: 'Bill Murray' }));

console.log(app.foo.count());
//==> 0

console.log(app.foo.hello());
//==> 'Hello Bill Murray'

console.log(app.foo.count());
//==> 1

console.log(app.foo.hello());
//==> 'Hello Bill Murray'

console.log(app.foo.count());
//==> 2

About

Mixdown app and base plugin implementation for mixdown.js 3.x and above.

Resources

License

Stars

Watchers

Forks

Packages

No packages published