| CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 0
API Reference
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();A maintainable and reusable app is an app that you can configure.
Assigns setting name to value.
app.set('name', 'olivier');or
app.store('name', 'olivier');Get setting name value.
app.get('name');or
app.store('name');Set setting name to true.
app.enable('admin');
app.get('admin'); // => trueSet setting name to false.
app.disable('admin');
app.get('admin'); // => falseCheck if setting name is enabled.
app.enabled('admin');
// => false
app.enable('admin');
app.enabled('admin');
// => trueCheck if setting name is disabled.
app.disabled('admin');
// => true
app.enable('admin');
app.disabled('admin');
// => falseConditionally 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');
})Consistent and adaptive interface to use plugins or other apps.
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);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 expose an elegant dependency injector in order to extend or use the same features in different apps:
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; //truevar wall = require('wall');
//add http request and debug
wall
.inject('bar')
.use(superagent())
.use(debug());
var app = wall('bar');
var other = wall('bar');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 ObamaYou also can listen for changes on computed properties
use (plugin):
app.sandbox.use(redis('name')); //backend redisdatastore 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.