Destroy preview list's previous operations when populating new ones

This commit is contained in:
Nathan Sobo
2012-07-23 19:05:37 -06:00
parent c3c4e07a3f
commit 5659f9bab1
2 changed files with 11 additions and 2 deletions

View File

@@ -241,6 +241,10 @@ describe "CommandPanel", ->
rootView.trigger 'command-panel:toggle-preview' # ensure we can close panel without problems
expect(commandPanel).toBeHidden()
it "destroys previously previewed operations if there are any", ->
waitsForPromise -> commandPanel.execute('X x/b+/')
# there shouldn't be any dangling operations after this
describe "if the command is malformed", ->
it "adds and removes an error class to the command panel and does not close it", ->
rootView.trigger 'command-panel:toggle'

View File

@@ -15,7 +15,9 @@ class PreviewList extends View
hasOperations: -> @operations?
populate: (@operations) ->
populate: (operations) ->
@destroyOperations() if @operations
@operations = operations
@empty()
@html $$$ ->
for operation in operations
@@ -28,7 +30,6 @@ class PreviewList extends View
@span suffix
@setSelectedOperationIndex(0)
@show()
selectNextOperation: ->
@@ -55,6 +56,10 @@ class PreviewList extends View
getOperations: ->
new Array(@operations...)
destroyOperations: ->
operation.destroy() for operation in @getOperations()
@operations = null
getSelectedOperation: ->
@operations[@selectedOperationIndex]