Created
November 6, 2013 14:28
-
-
Save designeng/7336899 to your computer and use it in GitHub Desktop.
Loading and resolving controller and component declaration with when.js "all" method
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
# blank method | |
callback = (resultClass) -> | |
# loading controllers directly instead of modules | |
require ["modules/" + name + "/" + name + "Controller", "modules/" + name + "/declaration"], (ControllerClass, declaration) => | |
types = findNested(declaration.componentItems, "itemType") | |
console.log types | |
promises = [] | |
for type in types | |
promises.push(resolver.resolveControl type, callback) | |
When.all(promises).then((res) => | |
@controller = new ControllerClass( | |
region: new Backbone.Marionette.Region({el: @$el}) | |
moduleContext: @ | |
activityRegistrator: activityRegistrator | |
declaration: declaration | |
) | |
# if show method provided by controller, it will be invoked | |
if @controller["show"] | |
@controller.show() | |
, (err) -> | |
console.log "ERROR", err | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment