Skip to content

Instantly share code, notes, and snippets.

@monzou monzou/application.coffee
Last active Dec 27, 2015

Embed
What would you like to do?
asyncInitialization with Backbone.Marionette
class Application extends Marionette.Application
constructor: (options) ->
super options
@_asyncInitCallbacks = []
addAsyncInitializer: (initializer) ->
@_asyncInitCallbacks.push initializer
start: (options) ->
@triggerMethod "initialize:before", options
@_initCallbacks.run options, @
asyncCallbackPromises = _.map @_asyncInitCallbacks, (callback) -> callback()
$.when(asyncCallbackPromises...).done =>
@triggerMethod "initialize:after", options
@triggerMethod "start", options
App = window.App = new Application()
loadResources = ->
dfd = $.Deferred()
_.delay dfd.resolve, 3000
dfd.promise()
App.addAsyncInitializer loadResources
App.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.