Skip to content

Instantly share code, notes, and snippets.

@designeng
Created November 6, 2013 14:28
Show Gist options
  • Save designeng/7336899 to your computer and use it in GitHub Desktop.
Save designeng/7336899 to your computer and use it in GitHub Desktop.
Loading and resolving controller and component declaration with when.js "all" method
# 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