Set up better teardown for the ladder view.
This commit is contained in:
parent
cf2a0a999e
commit
d8d917ecf9
4 changed files with 14 additions and 2 deletions
app
|
@ -20,6 +20,7 @@ module.exports = class CocoClass
|
||||||
destroy: ->
|
destroy: ->
|
||||||
# teardown subscriptions, prevent new ones
|
# teardown subscriptions, prevent new ones
|
||||||
@stopListening?()
|
@stopListening?()
|
||||||
|
@off()
|
||||||
@unsubscribeAll()
|
@unsubscribeAll()
|
||||||
@stopListeningToShortcuts()
|
@stopListeningToShortcuts()
|
||||||
@[key] = undefined for key of @
|
@[key] = undefined for key of @
|
||||||
|
|
|
@ -10,6 +10,11 @@ module.exports = class Simulator
|
||||||
@trigger 'statusUpdate', 'Starting simulation!'
|
@trigger 'statusUpdate', 'Starting simulation!'
|
||||||
@retryDelayInSeconds = 10
|
@retryDelayInSeconds = 10
|
||||||
@taskURL = '/queue/scoring'
|
@taskURL = '/queue/scoring'
|
||||||
|
|
||||||
|
destroy: ->
|
||||||
|
@off()
|
||||||
|
@cleanupSimulation()
|
||||||
|
# TODO: More teardown?
|
||||||
|
|
||||||
fetchAndSimulateTask: =>
|
fetchAndSimulateTask: =>
|
||||||
@trigger 'statusUpdate', 'Fetching simulation data!'
|
@trigger 'statusUpdate', 'Fetching simulation data!'
|
||||||
|
@ -99,7 +104,7 @@ module.exports = class Simulator
|
||||||
@fetchAndSimulateTask()
|
@fetchAndSimulateTask()
|
||||||
|
|
||||||
cleanupSimulation: ->
|
cleanupSimulation: ->
|
||||||
@god.destroy()
|
@god?.destroy()
|
||||||
@god = null
|
@god = null
|
||||||
@world = null
|
@world = null
|
||||||
@level = null
|
@level = null
|
||||||
|
|
|
@ -37,6 +37,7 @@ module.exports = class CocoView extends Backbone.View
|
||||||
|
|
||||||
destroy: ->
|
destroy: ->
|
||||||
@stopListening()
|
@stopListening()
|
||||||
|
@off()
|
||||||
@stopListeningToShortcuts()
|
@stopListeningToShortcuts()
|
||||||
@undelegateEvents() # removes both events and subs
|
@undelegateEvents() # removes both events and subs
|
||||||
view.destroy() for id, view of @subviews
|
view.destroy() for id, view of @subviews
|
||||||
|
|
|
@ -65,7 +65,7 @@ module.exports = class LadderView extends RootView
|
||||||
return if @startsLoading
|
return if @startsLoading
|
||||||
@insertSubView(@ladderTab = new LadderTabView({}, @level, @sessions))
|
@insertSubView(@ladderTab = new LadderTabView({}, @level, @sessions))
|
||||||
@insertSubView(@myMatchesTab = new MyMatchesTabView({}, @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
|
@showPlayModal(document.location.hash[1..]) if document.location.hash and @sessions.loaded
|
||||||
|
|
||||||
fetchSessionsAndRefreshViews: ->
|
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]
|
session = (s for s in @sessions.models when s.get('team') is teamID)[0]
|
||||||
modal = new LadderPlayModal({}, @level, session, teamID)
|
modal = new LadderPlayModal({}, @level, session, teamID)
|
||||||
@openModalView modal
|
@openModalView modal
|
||||||
|
|
||||||
|
destroy: ->
|
||||||
|
clearInterval @refreshInterval
|
||||||
|
@simulator.destroy()
|
||||||
|
super()
|
||||||
|
|
Reference in a new issue