29. Provide an API
(function (app) {
'use strict';
var namespace = 'hello',
api;
function hello() {
return 'hello, world';
}
api = {
hello: hello
};
app.register(namespace, api);
}(applitude));
30. Register
(function (app) {
'use strict';
var namespace = 'hello',
api;
function hello() {
return 'hello, world';
}
api = {
hello: hello
};
app.register(namespace, api);
}(applitude));
37. Use Events
(function (app) {
var namespace = 'sendMessage',
api;
api = function sendMessage(message) {
app.events.trigger('send_message.' +
namespace, message);
};
app.register(namespace, api);
}(applitude));
Modules should NOT call
each other directly.
38. Listen
(function (app) {
var namespace = 'messageLogger',
api;
function subscribe() {
app.events.on('send_message.*',
function (payload) {
app.log(payload);
});
}
// public interface
api = {
load: subscribe
};
// this never has to change
app.register(namespace, api);
}(applitude));