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