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
fetch: ->
super(arguments...)
res = super(arguments...)
@loading = true
res
markToRevert: ->
@_revertAttributes = _.clone @attributes

View file

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