Skip to content
Olivier Wietrich edited this page Apr 1, 2014 · 7 revisions

plumby()

Create a plumby app.

var plumby = require('plumby');
var app = plumby();

It is a good practice to expose your app in order to reuse it somewhere else:

var plumby = require('plumby');
var app = module.exports = plumby();

.store

A maintainable and reusable app is an app that you can configure.

set:

app.store('name', 'olivier');

get:

app.store('name');

set multiple or update:

app.store({
  name: 'olivier',
  repo: 'plumby'
});

get entire config:

app.store();

store uses store which is an extendable and observable wrapper for data objects or arrays. The entire API of store is available under app.sandbox.

.use

Consistent and adaptive interface to use plugins or other apps.

.use(fn[, options])

A plugin is a function with the app scope as first argument with some optional options.

app.use(function(ctx, opts){
  //do something on app
}, options);

.use(name[, app, config]);

Plug an app into the event communication bus. An app which has been 'used' (or mounted) can receive or send message to an other app.

Mount an app on the same parent path:

var mail = plumby();
app.use(mail, config);

Mount an app with a name (all events will be prefixed with the app mount path).

var mail = plumby();
app.use('mail', mail, config);

config is an optional object which allows you to set/update the app config.

plumby(name)

Plumby expose an elegant dependency injector in order to extend or use the same features in different apps:

inject mixin

var plumby = require('plumby');
plumby.inject('foo', {
  isFoo : true,
  alert : function(){
    alert('hello world');
  }
});

var app = plumby('foo');
app.alert(); //alert hello world
app.isFoo; //true

inject plugins

var plumby = require('plumby');

//add http request and debug
plumby
  .inject('bar')
  .use(superagent())
  .use(debug());

var app = plumby('bar');
var other = plumby('bar');
Clone this wiki locally