mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-12-02 20:07:25 -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
|
return super attrs, options
|
||||||
|
|
||||||
fetch: ->
|
fetch: ->
|
||||||
super(arguments...)
|
res = super(arguments...)
|
||||||
@loading = true
|
@loading = true
|
||||||
|
res
|
||||||
|
|
||||||
markToRevert: ->
|
markToRevert: ->
|
||||||
@_revertAttributes = _.clone @attributes
|
@_revertAttributes = _.clone @attributes
|
||||||
|
|
|
@ -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()
|
||||||
|
|
Loading…
Reference in a new issue