Unsubscribe from Buffer when an Editor is removed from the DOM.

This commit is contained in:
Nathan Sobo
2012-03-13 19:20:40 -06:00
parent 8cd0b23cd4
commit 5bf9925d0a
2 changed files with 22 additions and 2 deletions

View File

@@ -896,6 +896,19 @@ describe "Editor", ->
editor.attachToDom()
expect(editor).toMatchSelector ":has(:focus)"
it "unsubscribes from the buffer when it is removed from the dom", ->
buffer = new Buffer
previousSubscriptionCount = buffer.subscriptionCount()
editor.attachToDom()
editor.setBuffer(buffer)
expect(buffer.subscriptionCount()).toBeGreaterThan previousSubscriptionCount
expect($('.editor')).toExist()
editor.remove()
expect(buffer.subscriptionCount()).toBe previousSubscriptionCount
expect($('.editor')).not.toExist()
describe "when the editor recieves focused", ->
it "focuses the hidden input", ->
editor.attachToDom()

View File

@@ -165,8 +165,7 @@ class Editor extends View
setBuffer: (buffer) ->
if @buffer
@saveEditSession()
@buffer.off ".editor#{@id}"
@renderer.destroy()
@unsubscribeFromBuffer()
@buffer = buffer
@@ -397,3 +396,11 @@ class Editor extends View
logLines: ->
@renderer.logLines()
remove: ->
@unsubscribeFromBuffer()
super
unsubscribeFromBuffer: ->
@buffer.off ".editor#{@id}"
@renderer.destroy()