Added a way to remove SuperModel resources to fix ladder tab refreshing.

This commit is contained in:
Nick Winter 2014-05-21 15:33:28 -07:00
parent 037dbe97c6
commit 4fc1341a64
2 changed files with 17 additions and 3 deletions

View file

@ -16,13 +16,13 @@ module.exports = class SuperModel extends Backbone.Model
# retries, progress, and filling the cache. Note that the resource it passes back will not
# necessarily have the same model or collection that was passed in, if it was fetched from
# the cache.
report: ->
# Useful for debugging why a SuperModel never finishes loading.
console.info "SuperModel report ------------------------"
console.info "#{_.values(@resources).length} resources."
unfinished = []
for resource in _.values(@resources)
for resource in _.values(@resources) when resource
console.info '\t', resource.name, "loaded", resource.isLoaded
unfinished.push resource unless resource.isLoaded
unfinished
@ -128,6 +128,9 @@ module.exports = class SuperModel extends Backbone.Model
@storeResource(res, value)
return res
removeModelResource: (modelOrCollection) ->
@removeResource _.find(@resources, (resource) -> resource?.model is modelOrCollection)
addRequestResource: (name, jqxhrOptions, value=1) ->
@checkName(name)
res = new RequestResource(name, jqxhrOptions, value)
@ -153,11 +156,20 @@ module.exports = class SuperModel extends Backbone.Model
@denom += value
_.defer @updateProgress if @denom
removeResource: (resource) ->
return unless @resources[resource.rid]
@resources[resource.rid] = null
--@num if resource.isLoaded
--@denom
_.defer @updateProgress
onResourceLoaded: (r) ->
return unless @resources[r.rid]
@num += r.value
_.defer @updateProgress
onResourceFailed: (source) ->
return unless @resources[r.rid]
@trigger('failed', source)
updateProgress: =>

View file

@ -153,7 +153,9 @@ module.exports = class LadderTabView extends CocoView
@supermodel.resetProgress()
@ladderLimit ?= parseInt @getQueryVariable('top_players', 20)
for team in @teams
@leaderboards[team.id]?.destroy()
if oldLeaderboard = @leaderboards[team.id]
@supermodel.removeModelResource oldLeaderboard
oldLeaderboard.destroy()
teamSession = _.find @sessions.models, (session) -> session.get('team') is team.id
@leaderboards[team.id] = new LeaderboardData(@level, team.id, teamSession, @ladderLimit)
@leaderboardRes = @supermodel.addModelResource(@leaderboards[team.id], 'leaderboard', 3)