Skip to content

Instantly share code, notes, and snippets.

@monzou monzou/
Last active Dec 27, 2015

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 options, @
asyncCallbackPromises = @_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
App.addAsyncInitializer loadResources
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.