Skip to content

Instantly share code, notes, and snippets.

@tonylukasavage
Created August 13, 2012 19:46
Show Gist options
  • Save tonylukasavage/3343578 to your computer and use it in GitHub Desktop.
Save tonylukasavage/3343578 to your computer and use it in GitHub Desktop.
New controller syntax
// module.exports defines the class for this controller. Most importantly, we can define a base controller
// from which we can inherit. In most cases developers will just use the boilerplate 'BaseController',
// but advanced developer can create their own super and sub classes to enhance code reuse.
module.exports = Alloy.getController('baseController').extend({
// Lifecycle function that is executed before the UI is created or the view hierarchy is established.
// For this reason, the $ variable will not yet have access to the IDed elements from markup. This is
// a good place to make runtime checks and modifications to styles.
onInit: function(args){},
// The primary lifecycle function. 99% of developer code will likely be run through this. This is executed
// after the UI is created and the view hierarchy is established. All IDed elements can be accessed via
// the $ variable.
onReady: function(args){},
// Here you can also define the public interface to your controller. This can be functions and/or
// properties. They apply to any instances created with this controller class.
customFunction: function(){},
customProperty: 123
});
function onReady(args) {
$.someButton.on('click', function(e) {
$.someButton.title = 'clicked';
}
}
module.exports = Alloy.getController('BaseController').extend({
onReady: onReady
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment