mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-30 19:06:59 -05:00
Added a whole bunch of view teardown.
This commit is contained in:
parent
7ad6faa0c0
commit
aa4cc8d9c4
7 changed files with 32 additions and 3 deletions
|
@ -56,3 +56,6 @@ module.exports = class ThangAvatarView extends View
|
|||
|
||||
onNewWorld: (e) ->
|
||||
@options.thang = @thang = e.world.thangMap[@thang.id] if @thang
|
||||
|
||||
destroy: ->
|
||||
super()
|
|
@ -11,6 +11,7 @@ module.exports = class SpellListEntryThangsView extends View
|
|||
@thangs = options.thangs
|
||||
@thang = options.thang
|
||||
@spell = options.spell
|
||||
@avatars = []
|
||||
|
||||
getRenderData: (context={}) =>
|
||||
context = super context
|
||||
|
@ -20,13 +21,19 @@ module.exports = class SpellListEntryThangsView extends View
|
|||
|
||||
afterRender: ->
|
||||
super()
|
||||
avatar.destroy() for avatar in @avatars if @avatars
|
||||
@avatars = []
|
||||
spellName = @spell.name
|
||||
for thang in @thangs
|
||||
avatar = new ThangAvatarView thang: thang, includeName: true, supermodel: @supermodel
|
||||
avatar = new ThangAvatarView thang: thang, includeName: true, supermodel: @supermodel, creator: @
|
||||
@$el.append avatar.el
|
||||
avatar.render()
|
||||
avatar.setSelected thang is @thang
|
||||
avatar.$el.data('thang-id', thang.id).click (e) ->
|
||||
Backbone.Mediator.publish "level-select-sprite", thangID: $(@).data('thang-id'), spellName: spellName
|
||||
avatar.onProblemsUpdated spell: @spell
|
||||
@avatars.push avatar
|
||||
|
||||
destroy: ->
|
||||
avatar.destroy() for avatar in @avatars
|
||||
super()
|
||||
|
|
|
@ -46,6 +46,7 @@ module.exports = class SpellListEntryView extends View
|
|||
super()
|
||||
return unless @options.showTopDivider # Don't repeat Thang avatars when not changed from previous entry
|
||||
return unless spellThang = @getPrimarySpellThang()
|
||||
@avatar?.destroy()
|
||||
@avatar = new ThangAvatarView thang: spellThang.thang, includeName: false, supermodel: @supermodel
|
||||
@$el.prepend @avatar.el # Before rendering, so render can use parent for popover
|
||||
@avatar.render()
|
||||
|
@ -100,3 +101,7 @@ module.exports = class SpellListEntryView extends View
|
|||
|
||||
onNewWorld: (e) ->
|
||||
@lastSelectedThang = e.world.thangMap[@lastSelectedThang.id] if @lastSelectedThang
|
||||
|
||||
destroy: ->
|
||||
super()
|
||||
@avatar?.destroy()
|
||||
|
|
|
@ -87,3 +87,7 @@ module.exports = class SpellListTabEntryView extends SpellListEntryView
|
|||
return if enabled is @controlsEnabled
|
||||
@controlsEnabled = enabled
|
||||
@$el.toggleClass 'read-only', not enabled
|
||||
|
||||
destroy: ->
|
||||
@avatar?.destroy()
|
||||
super()
|
|
@ -19,6 +19,7 @@ module.exports = class SpellListView extends View
|
|||
|
||||
constructor: (options) ->
|
||||
super options
|
||||
@entries = []
|
||||
@sortSpells()
|
||||
|
||||
sortSpells: ->
|
||||
|
@ -53,7 +54,6 @@ module.exports = class SpellListView extends View
|
|||
@addSpellListEntries()
|
||||
|
||||
addSpellListEntries: ->
|
||||
@entries ?= []
|
||||
newEntries = []
|
||||
lastThangs = null
|
||||
for spell, index in @spells
|
||||
|
@ -87,3 +87,7 @@ module.exports = class SpellListView extends View
|
|||
@spells = @options.spells = spells
|
||||
@sortSpells()
|
||||
@addSpellListEntries()
|
||||
|
||||
destroy: ->
|
||||
super()
|
||||
entry.destroy() for entry in @entries
|
|
@ -42,6 +42,7 @@ module.exports = class ThangListEntryView extends View
|
|||
|
||||
afterRender: ->
|
||||
super()
|
||||
@avatar?.destroy()
|
||||
@avatar = new ThangAvatarView thang: @thang, includeName: true, supermodel: @supermodel
|
||||
@$el.append @avatar.el # Before rendering, so render can use parent for popover
|
||||
@avatar.render()
|
||||
|
@ -137,4 +138,4 @@ module.exports = class ThangListEntryView extends View
|
|||
|
||||
destroy: ->
|
||||
super()
|
||||
@avatar.destroy()
|
||||
@avatar?.destroy()
|
||||
|
|
|
@ -80,3 +80,8 @@ module.exports = class ThangListView extends View
|
|||
@thangs = @options.thangs = thangs
|
||||
@sortThangs()
|
||||
@addThangListEntries()
|
||||
|
||||
destroy: ->
|
||||
super()
|
||||
entry.destroy() for entry in @entries
|
||||
|
||||
|
|
Loading…
Reference in a new issue