mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-24 08:08:15 -05:00
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
|
@ -20,6 +20,7 @@ module.exports = class CocoClass
|
|||
destroy: ->
|
||||
# teardown subscriptions, prevent new ones
|
||||
@stopListening?()
|
||||
@off()
|
||||
@unsubscribeAll()
|
||||
@stopListeningToShortcuts()
|
||||
@[key] = undefined for key of @
|
||||
|
|
|
@ -10,6 +10,11 @@ module.exports = class Simulator
|
|||
@trigger 'statusUpdate', 'Starting simulation!'
|
||||
@retryDelayInSeconds = 10
|
||||
@taskURL = '/queue/scoring'
|
||||
|
||||
destroy: ->
|
||||
@off()
|
||||
@cleanupSimulation()
|
||||
# TODO: More teardown?
|
||||
|
||||
fetchAndSimulateTask: =>
|
||||
@trigger 'statusUpdate', 'Fetching simulation data!'
|
||||
|
@ -99,7 +104,7 @@ module.exports = class Simulator
|
|||
@fetchAndSimulateTask()
|
||||
|
||||
cleanupSimulation: ->
|
||||
@god.destroy()
|
||||
@god?.destroy()
|
||||
@god = null
|
||||
@world = null
|
||||
@level = null
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue