Set up better teardown for the ladder view.

This commit is contained in:
Scott Erickson 2014-03-07 12:15:16 -08:00
parent cf2a0a999e
commit d8d917ecf9
4 changed files with 14 additions and 2 deletions

View file

@ -20,6 +20,7 @@ module.exports = class CocoClass
destroy: ->
# teardown subscriptions, prevent new ones
@stopListening?()
@off()
@unsubscribeAll()
@stopListeningToShortcuts()
@[key] = undefined for key of @

View file

@ -11,6 +11,11 @@ module.exports = class Simulator
@retryDelayInSeconds = 10
@taskURL = '/queue/scoring'
destroy: ->
@off()
@cleanupSimulation()
# TODO: More teardown?
fetchAndSimulateTask: =>
@trigger 'statusUpdate', 'Fetching simulation data!'
$.ajax
@ -99,7 +104,7 @@ module.exports = class Simulator
@fetchAndSimulateTask()
cleanupSimulation: ->
@god.destroy()
@god?.destroy()
@god = null
@world = null
@level = null

View file

@ -37,6 +37,7 @@ module.exports = class CocoView extends Backbone.View
destroy: ->
@stopListening()
@off()
@stopListeningToShortcuts()
@undelegateEvents() # removes both events and subs
view.destroy() for id, view of @subviews

View file

@ -65,7 +65,7 @@ module.exports = class LadderView extends RootView
return if @startsLoading
@insertSubView(@ladderTab = new LadderTabView({}, @level, @sessions))
@insertSubView(@myMatchesTab = new MyMatchesTabView({}, @level, @sessions))
setInterval(@fetchSessionsAndRefreshViews.bind(@), 10000)
@refreshInterval = setInterval(@fetchSessionsAndRefreshViews.bind(@), 10000)
@showPlayModal(document.location.hash[1..]) if document.location.hash and @sessions.loaded
fetchSessionsAndRefreshViews: ->
@ -119,3 +119,8 @@ module.exports = class LadderView extends RootView
session = (s for s in @sessions.models when s.get('team') is teamID)[0]
modal = new LadderPlayModal({}, @level, session, teamID)
@openModalView modal
destroy: ->
clearInterval @refreshInterval
@simulator.destroy()
super()