Trying out promises to simplify view loading.

This commit is contained in:
Scott Erickson 2014-03-11 22:01:38 -07:00
parent eeff462051
commit 8ddbb49845
2 changed files with 6 additions and 10 deletions

View file

@ -81,8 +81,9 @@ class CocoModel extends Backbone.Model
return super attrs, options return super attrs, options
fetch: -> fetch: ->
super(arguments...) res = super(arguments...)
@loading = true @loading = true
res
markToRevert: -> markToRevert: ->
@_revertAttributes = _.clone @attributes @_revertAttributes = _.clone @attributes

View file

@ -33,20 +33,15 @@ module.exports = class LadderView extends RootView
constructor: (options, @levelID) -> constructor: (options, @levelID) ->
super(options) super(options)
@level = new Level(_id:@levelID) @level = new Level(_id:@levelID)
@level.fetch() p1 = @level.fetch()
@level.once 'sync', @onLevelLoaded, @
@sessions = new LevelSessionsCollection(levelID) @sessions = new LevelSessionsCollection(levelID)
@sessions.fetch({}) p2 = @sessions.fetch({})
@sessions.once 'sync', @onMySessionsLoaded, @
@simulator = new Simulator() @simulator = new Simulator()
@simulator.on 'statusUpdate', @updateSimulationStatus, @ @simulator.on 'statusUpdate', @updateSimulationStatus, @
@teams = [] @teams = []
$.when(p1, p2).then @onLoaded
onLevelLoaded: -> @renderMaybe() onLoaded: =>
onMySessionsLoaded: -> @renderMaybe()
renderMaybe: ->
return unless @level.loaded and @sessions.loaded
@teams = teamDataFromLevel @level @teams = teamDataFromLevel @level
@startsLoading = false @startsLoading = false
@render() @render()