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

wall()

Create a wall app.

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

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

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

config/store

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

set(name, value)

Assigns setting name to value.

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

or

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

get(name)

Get setting name value.

app.get('name');

or

app.store('name');

enable(name)

Set setting name to true.

app.enable('admin');
app.get('admin'); // => true

disable(name)

Set setting name to false.

app.disable('admin');
app.get('admin'); // => false

enabled(name)

Check if setting name is enabled.

app.enabled('admin');
// => false

app.enable('admin');
app.enabled('admin');
// => true

disabled(name)

Check if setting name is disabled.

app.disabled('admin');
// => true

app.enable('admin');
app.disabled('admin');
// => false

configure([state], callback)

Conditionally invoke callback when app state matches app.get('env'). Really useful to configure your app according its state.

// all states
app.configure(function(){
  app.set('title', 'My Application');
})

// admin only
app.configure('admin', function(){
  app.set('rights', 'super');
})

.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 = wall();
app.use(mail, config);

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

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

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

wall(name)

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

inject mixin

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

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

inject plugins

var wall = require('wall');

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

var app = wall('bar');
var other = wall('bar');

Sandbox

A sandbox (app.sandbox) is an instance of datastore which is basically an event-based wrapper for JavaScript object/arrays. The methods set, get, store, enable, disable are a facade on top of features provided by the sandbox.

The entire API of the sandbox is not exposed which is particularly useful when working in teams. However, the app.sandbox has a lot to offer:

Listen for changes:

app.sandbox.on('change foo', function(value) {
  //do something when foo changed
});
app.set('foo', 'bar'); //app.sandbox.set('foo','bar');

Reset:

app.sandbox.reset({
  foo: 'bar',
  hello: 'world'
});

Computed properties:

app.sandbox.compute('name', function(){
  return this.firstName + ' Obama';
});
app.set('firstName', 'barack');
app.get('name'); 
// => barack Obama

You also can listen for changes on computed properties

use (plugin):

app.sandbox.use(redis('name')); //backend redis

datastore has a lot of plugins to set nested properties, backend with redis, realtime mapping on server side, etc.

See datastore to know more about what the sandbox is capable of and to see all the available plugins.