There are a few code patterns exposed by the framework that you will probably use:
Callbacks are a common pattern in JavaScript because of its asynchronous nature, both on the client and on the server side with Node.js
A lot of methods of the framework take a callback as a parameter. We follow the Node.js convention so the first
argument of each callback method is always an error
object, and it is undefined/null if the method was successful.
var callback = function(error, data) {
if (error) {
console.error("Your method failed");
return;
}
console.log("Your method returned data :", data);
};
// Signature is tree.fetch(path, query, callback)
app.data.fetch("/news/", {"category":"sports"}, callback);
A few base classes of the framework (App, UIElement, Tree) have a pubsub mixin so that they can publish and subscribe to events. This is very helpful for loose coupling between components.
// Listen to the "ready" event on this app instance
app.subscribe("ready",function(event,data) {
console.log("App is ready.");
// Simulate a "left" keystroke on the /news UI Element
// publish() takes an event ID and a data arguments.
app.ui.element("/news").publish("input",["left"]);
}):
The framework code follows the Google JavaScript Style Guide. It might also be a good idea to do the same in your app code.
Most important things: