mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-28 01:55:38 -05:00
Trying out promises to simplify view loading.
This commit is contained in:
parent
eeff462051
commit
8ddbb49845
2 changed files with 6 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue