broadway
Lightweight application extensibility and composition with a twist of feature
reflection.
Example
app.js
var broadway = require("broadway");
var app = new broadway.App();
app.use(require("./plugins/helloworld"), { "delimiter": "!" } );
app.init(function (err) {
if (err) {
console.log(err);
}
});
app.hello("world");
plugins/helloworld.js
exports.attach = function (options) {
this.hello = function (world) {
console.log("Hello "+ world + options.delimiter || ".");
}
};
exports.init = function (done) {
return done();
};
run it!
josh@onix:~/dev/broadway/examples$ node simple/app.js
Hello world!
josh@onix:~/dev/broadway/examples$
Installation
Installing npm (node package manager)
$ curl http://npmjs.org/install.sh | sh
Installing broadway
$ [sudo] npm install broadway
API
App#init(callback)
Initialize application and it's plugins, callback
will be called with null or
initialization error as first argument.
App#use(plugin, options)
Attach plugin to application. plugin
should conform to following interface:
var plugin = {
"name": "example-plugin",
"attach": function attach(options) {
},
"detach": function detach() {
}
"init": function init(callback) {
}
};
App#on(event, callback) and App#emit(event, data)
App inherits from EventEmitter2, and many plugins build on this
functionality.
Built-In Events:
error:init
: Broadway emits this event when it throws an error while attempting to initialize.
Read the EventEmitter2 documentation for more information.
Tests
All tests are written with vows and should be run with npm:
$ npm test
License: MIT