mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Cleanup all subscriptions when a view is removed from the DOM
This commit is contained in:
@@ -32,10 +32,9 @@ describe "SpacePen extensions", ->
|
||||
|
||||
expect(observeHandler).not.toHaveBeenCalled()
|
||||
|
||||
it "unsubscribes on remove", ->
|
||||
it "unsubscribes when the view is removed from the DOM", ->
|
||||
observeHandler.reset()
|
||||
view.remove()
|
||||
expect(view.hasParent()).toBeFalsy()
|
||||
parent.remove()
|
||||
config.foo = { bar: "hello" }
|
||||
config.update()
|
||||
expect(observeHandler).not.toHaveBeenCalled()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
_ = require 'underscore'
|
||||
{View} = require 'space-pen'
|
||||
jQuery = require 'jquery'
|
||||
|
||||
originalRemove = View.prototype.remove
|
||||
|
||||
@@ -17,3 +18,8 @@ _.extend View.prototype,
|
||||
remove: (args...) ->
|
||||
@unsubscribe()
|
||||
originalRemove.apply(this, args)
|
||||
|
||||
originalCleanData = jQuery.cleanData
|
||||
jQuery.cleanData = (elements) ->
|
||||
jQuery(element).view()?.unsubscribe?() for element in elements
|
||||
originalCleanData(elements)
|
||||
|
||||
Reference in New Issue
Block a user