Created
November 11, 2014 01:53
-
-
Save jstrimpel/973e6f2a9d6babf4d1b2 to your computer and use it in GitHub Desktop.
lazo base controller that loads children
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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