Unmount TextEditorComponent when TextEditorElement is detached

Fixes #4381
Fixes #4700
This commit is contained in:
Nathan Sobo 2015-01-06 11:35:18 -07:00
parent 03468e405a
commit 180725799a
3 changed files with 16 additions and 4 deletions

View File

@ -42,9 +42,12 @@ describe "TextEditorElement", ->
component = element.component
expect(component.isMounted()).toBe true
element.getModel().destroy()
element.remove()
expect(component.isMounted()).toBe false
jasmine.attachToDOM(element)
expect(element.component.isMounted()).toBe true
describe "when the editor.useShadowDOM config option is false", ->
it "mounts the react component and unmounts when removed from the dom", ->
atom.config.set('editor.useShadowDOM', false)

View File

@ -67,6 +67,7 @@ class TextEditorElement extends HTMLElement
@emitter.emit("did-attach")
detachedCallback: ->
@unmountComponent()
@emitter.emit("did-detach")
initialize: (model) ->

View File

@ -62,6 +62,7 @@ class WorkspaceView extends View
return atom.views.getView(atom.workspace).__spacePenView
super
@deprecateViewEvents()
@attachedEditorViews = new WeakSet
setModel: (@model) ->
@horizontal = @find('atom-workspace-axis.horizontal')
@ -95,10 +96,17 @@ class WorkspaceView extends View
# Returns a subscription object with an `.off` method that you can call to
# unregister the callback.
eachEditorView: (callback) ->
callback(editorView) for editorView in @getEditorViews()
attachedCallback = (e, editorView) ->
callback(editorView) unless editorView.mini
for editorView in @getEditorViews()
@attachedEditorViews.add(editorView)
callback(editorView)
attachedCallback = (e, editorView) =>
unless @attachedEditorViews.has(editorView)
@attachedEditorViews.add(editorView)
callback(editorView) unless editorView.mini
@on('editor:attached', attachedCallback)
off: => @off('editor:attached', attachedCallback)
# Essential: Register a function to be called for every current and future