Skip to content

Instantly share code, notes, and snippets.

@jstrimpel
Created November 11, 2014 01:53
Show Gist options
  • Save jstrimpel/973e6f2a9d6babf4d1b2 to your computer and use it in GitHub Desktop.
Save jstrimpel/973e6f2a9d6babf4d1b2 to your computer and use it in GitHub Desktop.
lazo base controller that loads children
define(['lazoCtl', 'underscore'], function (LazoCtl, _) {
return LazoCtl.extend({
view: 'index',
components: [],
index: function (options) {
if (this.components.length) {
return this.loadChildren(options);
}
options.success(this.view);
},
loadChildren: function (options) {
var counter = 0;
var self = this;
var components = this.components;
var expected = components.length;
function error(err) {
options.error(err);
}
function success(child) {
counter++;
if (counter === expected) {
options.success(self.view);
}
}
for (var i = 0; i < expected; i++) {
this.addChild(components[i].target, components[i].name, {
error: error,
success: success,
ctx: _.extend({
params: this.ctx.params
}, options.ctx)
});
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment