yahoo/mojito — pull request #459 by caridy (2012-08-31 01:35:45+00:00)
Title: support for route events in controllers

This is the preliminar work to support events in the controller.

Traditionally, you define a controller like this:

Y.namespace('mojito.controllers')[NAME] = {
init: function(config) {
this.config = config;
},
index: function(ac) {
ac.done('');
}
};

we want to also support:

Y.namespace('mojito.controllers')[NAME] = {
init: function(config) {
this.config = config;
this.on('index', this.onIndex, this);
},
onIndex: function(e) {
e.ac.done(''); // this API is subject to change
}
};

or even something more advanced like this (prototypal definition):

Y.namespace('mojito.controllers')[NAME] = function (config) {
this.config = config;
this.on('index', this.onIndex, this);
};
Y.namespace('mojito.controllers')[NAME].prototype = {
onIndex: function (e) {
e.ac.done(''); // this API is subject to change
}
};

or even something super advanced like this:

Y.namespace('mojito.controllers')[NAME] = Y.Base.create(NAME, Y.BaseCore, [], {
initializer: function (config) {
this.config = config;
this.on('index', this.onIndex, this);
},
onIndex: function (e) {
e.ac.done(''); // this API is subject to change
}
}, {
ATTRS: {
photos: {} // potentially a global model instance
}
});

obviously, we can do Y.App instead of Y.BaseCore on this last example, and it should provide a fully functional App fragment in a form of a mojit.

/cc @ericf @drewfish