mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-01 15:50:11 -04:00
All ace editors must die. I found that certain editor modes will leave a mess in memory, so when editors are destroyed, I also set their modes to '' which seems to take care of most of the issue. They still leave memory behind just a little bit, though.
This commit is contained in:
parent
3f6c9c4f02
commit
21e0889a86
17 changed files with 69 additions and 7 deletions
app/views
account
common
editor
component
level
components
scripts
settings
systems
thangs
thang
kinds
modal
play/level/tome
user
|
@ -234,3 +234,7 @@ module.exports = class AccountSettingsView extends RootView
|
|||
$(@).data 'saved-value', $(@).val()
|
||||
$('#settings-panes input:checkbox').each ->
|
||||
$(@).data 'saved-value', JSON.stringify $(@)[0].checked
|
||||
|
||||
destroy: ->
|
||||
@pictureTreema?.destroy()
|
||||
super()
|
File diff suppressed because one or more lines are too long
|
@ -26,13 +26,16 @@ module.exports = class LevelSessionCodeView extends CocoView
|
|||
|
||||
afterRender: ->
|
||||
super()
|
||||
editors = []
|
||||
@$el.find('.code').each (index, codeEl) ->
|
||||
height = parseInt($(codeEl).data('height'))
|
||||
$(codeEl).height(height)
|
||||
editor = ace.edit codeEl
|
||||
editor.setReadOnly true
|
||||
editors.push editor
|
||||
aceSession = editor.getSession()
|
||||
aceSession.setMode 'ace/mode/javascript'
|
||||
@editors = editors
|
||||
|
||||
organizeCode: ->
|
||||
team = @session.get('team') or 'humans'
|
||||
|
@ -47,4 +50,8 @@ module.exports = class LevelSessionCodeView extends CocoView
|
|||
name: spell
|
||||
height: height
|
||||
}
|
||||
filteredSpells
|
||||
filteredSpells
|
||||
|
||||
destroy: ->
|
||||
for editor in @editors
|
||||
@editors
|
|
@ -92,6 +92,10 @@ module.exports = class ThangComponentConfigView extends CocoView
|
|||
@trigger 'changed', { component: @component, config: @config }
|
||||
|
||||
data: -> @editThangTreema.data
|
||||
|
||||
destroy: ->
|
||||
@editThangTreema?.destroy()
|
||||
super()
|
||||
|
||||
class ComponentConfigNode extends TreemaObjectNode
|
||||
nodeDescription: 'Component Property'
|
||||
|
|
|
@ -342,7 +342,10 @@ module.exports = class ThangComponentsEditView extends CocoView
|
|||
@loadComponents(sparseComponents)
|
||||
@components = @components.concat(sparseComponents)
|
||||
@onComponentsChanged()
|
||||
|
||||
|
||||
destroy: ->
|
||||
@componentsTreema?.destroy()
|
||||
super()
|
||||
|
||||
class ThangComponentsObjectNode extends TreemaObjectNode
|
||||
addNewChild: -> @addNewChildForKey('') # HACK to get the object adding to act more like adding to an array
|
||||
|
|
|
@ -81,6 +81,10 @@ module.exports = class ComponentsTabView extends CocoView
|
|||
onLevelComponentEditingEnded: (e) ->
|
||||
@removeSubView @levelComponentEditView
|
||||
@levelComponentEditView = null
|
||||
|
||||
destroy: ->
|
||||
@componentsTreema?.destroy()
|
||||
super()
|
||||
|
||||
class LevelComponentNode extends TreemaObjectNode
|
||||
valueClass: 'treema-level-component'
|
||||
|
|
|
@ -84,7 +84,7 @@ module.exports = class LevelComponentEditView extends CocoView
|
|||
@levelComponent.set 'configSchema', @configSchemaTreema.data
|
||||
|
||||
buildCodeEditor: ->
|
||||
@editor?.destroy()
|
||||
@destroyAceEditor(@editor)
|
||||
editorEl = $('<div></div>').text(@levelComponent.get('code')).addClass('inner-editor')
|
||||
@$el.find('#component-code-editor').empty().append(editorEl)
|
||||
@editor = ace.edit(editorEl[0])
|
||||
|
@ -120,5 +120,7 @@ module.exports = class LevelComponentEditView extends CocoView
|
|||
button.find('> span').toggleClass('secret')
|
||||
|
||||
destroy: ->
|
||||
@editor?.destroy()
|
||||
@destroyAceEditor(@editor)
|
||||
@componentSettingsTreema?.destroy()
|
||||
@configSchemaTreema?.destroy()
|
||||
super()
|
||||
|
|
|
@ -83,6 +83,7 @@ module.exports = class ScriptsTabView extends CocoView
|
|||
|
||||
newPath = selected.getPath()
|
||||
return if newPath is @selectedScriptPath
|
||||
@scriptTreema?.destroy()
|
||||
@scriptTreema = @$el.find('#script-treema').treema treemaOptions
|
||||
@scriptTreema.build()
|
||||
@scriptTreema.childrenTreemas?.noteChain?.open()
|
||||
|
@ -114,7 +115,11 @@ module.exports = class ScriptsTabView extends CocoView
|
|||
onThangsEdited: (e) ->
|
||||
# Update in-place so existing Treema nodes refer to the same array.
|
||||
@thangIDs?.splice(0, @thangIDs.length, @getThangIDs()...)
|
||||
|
||||
|
||||
destroy: ->
|
||||
@scriptTreema?.destroy()
|
||||
@scriptTreemas?.destroy()
|
||||
super()
|
||||
|
||||
class ScriptsNode extends TreemaArrayNode
|
||||
nodeDescription: 'Script'
|
||||
|
|
|
@ -60,6 +60,10 @@ module.exports = class SettingsTabView extends CocoView
|
|||
onThangsEdited: (e) ->
|
||||
# Update in-place so existing Treema nodes refer to the same array.
|
||||
@thangIDs?.splice(0, @thangIDs.length, @getThangIDs()...)
|
||||
|
||||
destroy: ->
|
||||
@settingsTreema?.destroy()
|
||||
super()
|
||||
|
||||
|
||||
class SettingsNode extends TreemaObjectNode
|
||||
|
|
|
@ -78,7 +78,7 @@ module.exports = class LevelSystemEditView extends CocoView
|
|||
@levelSystem.set 'configSchema', @configSchemaTreema.data
|
||||
|
||||
buildCodeEditor: ->
|
||||
@editor?.destroy()
|
||||
@destroyAceEditor(@editor)
|
||||
editorEl = $('<div></div>').text(@levelSystem.get('code')).addClass('inner-editor')
|
||||
@$el.find('#system-code-editor').empty().append(editorEl)
|
||||
@editor = ace.edit(editorEl[0])
|
||||
|
@ -114,5 +114,7 @@ module.exports = class LevelSystemEditView extends CocoView
|
|||
button.find('> span').toggleClass('secret')
|
||||
|
||||
destroy: ->
|
||||
@editor?.destroy()
|
||||
@destroyAceEditor(@editor)
|
||||
@systemSettingsTreema?.destroy()
|
||||
@configSchemaTreema?.destroy()
|
||||
super()
|
||||
|
|
|
@ -121,6 +121,10 @@ module.exports = class SystemsTabView extends CocoView
|
|||
{original: '528114e60268d018e300001a', majorVersion: 0} # UI
|
||||
{original: '528114040268d018e3000011', majorVersion: 0} # Physics
|
||||
]
|
||||
|
||||
destroy: ->
|
||||
@systemsTreema?.destroy()
|
||||
super()
|
||||
|
||||
class LevelSystemNode extends TreemaObjectNode
|
||||
valueClass: 'treema-level-system'
|
||||
|
|
|
@ -183,6 +183,7 @@ module.exports = class ThangsTabView extends CocoView
|
|||
@selectAddThangType null
|
||||
@surface.destroy()
|
||||
$(document).unbind 'contextmenu', @preventDefaultContextMenu
|
||||
@thangsTreema?.destroy()
|
||||
super()
|
||||
|
||||
onViewSwitched: (e) ->
|
||||
|
|
|
@ -21,6 +21,7 @@ module.exports = class ThangTypeColorsTabView extends CocoView
|
|||
@interval = setInterval f, 1000
|
||||
|
||||
destroy: ->
|
||||
@colorGroups?.destroy()
|
||||
clearInterval @interval
|
||||
super()
|
||||
|
||||
|
|
|
@ -65,6 +65,13 @@ module.exports = class CocoView extends Backbone.View
|
|||
@destroy = doNothing
|
||||
$.noty.closeAll()
|
||||
|
||||
destroyAceEditor: (editor) ->
|
||||
# convenience method to make sure the ace editor is as destroyed as can be
|
||||
return unless editor
|
||||
session = editor.getSession()
|
||||
session.setMode ''
|
||||
editor.destroy()
|
||||
|
||||
afterInsert: ->
|
||||
|
||||
willDisappear: ->
|
||||
|
|
|
@ -69,3 +69,7 @@ module.exports = class ModelModal extends ModalView
|
|||
res.success (model, response, options) =>
|
||||
return if @destroyed
|
||||
@hide()
|
||||
|
||||
destroy: ->
|
||||
@modelTreemas[model].destroy() for model of @modelTreemas
|
||||
super()
|
|
@ -80,6 +80,7 @@ module.exports = class SpellView extends CocoView
|
|||
createACE: ->
|
||||
# Test themes and settings here: http://ace.ajax.org/build/kitchen-sink.html
|
||||
aceConfig = me.get('aceConfig') ? {}
|
||||
@destroyAceEditor(@ace)
|
||||
@ace = ace.edit @$el.find('.ace')[0]
|
||||
@aceSession = @ace.getSession()
|
||||
@aceDoc = @aceSession.getDocument()
|
||||
|
@ -710,5 +711,6 @@ module.exports = class SpellView extends CocoView
|
|||
@ace?.destroy()
|
||||
@aceDoc?.off 'change', @onCodeChangeMetaHandler
|
||||
@aceSession?.selection.off 'changeCursor', @onCursorActivity
|
||||
@destroyAceEditor(@ace)
|
||||
@debugView?.destroy()
|
||||
super()
|
||||
|
|
|
@ -586,3 +586,7 @@ module.exports = class JobProfileView extends UserView
|
|||
session = _.find @sessions.models, (session) -> session.id is sessionID
|
||||
modal = new JobProfileCodeModal({session:session})
|
||||
@openModalView modal
|
||||
|
||||
destroy: ->
|
||||
@remarkTreema?.destroy()
|
||||
super()
|
Loading…
Add table
Reference in a new issue