Allow element to work without attaching it to DOM

This commit is contained in:
Antonio Scandurra 2016-03-28 16:40:39 +02:00
parent 3d4611ce4c
commit 8adf47b1c2
2 changed files with 11 additions and 22 deletions

View File

@ -10,7 +10,6 @@ describe "PaneContainerElement", ->
paneAxis = new PaneAxis
paneAxisElement = new PaneAxisElement().initialize(paneAxis, atom)
jasmine.attachToDOM(paneAxisElement)
expect(childTagNames()).toEqual []
@ -42,8 +41,6 @@ describe "PaneContainerElement", ->
'atom-pane-axis'
]
paneAxisElement.remove()
it "transfers focus to the next pane if a focused pane is removed", ->
container = new PaneContainer(config: atom.config, confirm: atom.confirm.bind(atom))
containerElement = atom.views.getView(container)
@ -63,7 +60,6 @@ describe "PaneContainerElement", ->
it "builds appropriately-oriented atom-pane-axis elements", ->
container = new PaneContainer(config: atom.config, confirm: atom.confirm.bind(atom))
containerElement = atom.views.getView(container)
jasmine.attachToDOM(containerElement)
pane1 = container.getActivePane()
pane2 = pane1.splitRight()
@ -84,8 +80,6 @@ describe "PaneContainerElement", ->
expect(verticalPanes[0]).toBe atom.views.getView(pane2)
expect(verticalPanes[1]).toBe atom.views.getView(pane3)
containerElement.remove()
describe "when the resize element is dragged ", ->
[container, containerElement] = []

View File

@ -3,7 +3,17 @@ PaneResizeHandleElement = require './pane-resize-handle-element'
class PaneAxisElement extends HTMLElement
attachedCallback: ->
@subscriptions = @subscribeToModel()
@subscriptions ?= @subscribeToModel()
@childAdded({child, index}) for child, index in @model.getChildren()
detachedCallback: ->
@subscriptions.dispose()
@subscriptions = null
@childRemoved({child}) for child in @model.getChildren()
initialize: (@model, {@views}) ->
throw new Error("Must pass a views parameter when initializing TextEditorElements") unless @views?
@subscriptions ?= @subscribeToModel()
@childAdded({child, index}) for child, index in @model.getChildren()
switch @model.getOrientation()
@ -11,21 +21,6 @@ class PaneAxisElement extends HTMLElement
@classList.add('horizontal', 'pane-row')
when 'vertical'
@classList.add('vertical', 'pane-column')
detachedCallback: ->
@subscriptions.dispose()
@subscriptions = null
@childRemoved({child}) for child in @model.getChildren()
switch @model.getOrientation()
when 'horizontal'
@classList.remove('horizontal', 'pane-row')
when 'vertical'
@classList.remove('vertical', 'pane-column')
initialize: (@model, {@views}) ->
throw new Error("Must pass a views parameter when initializing TextEditorElements") unless @views?
this
subscribeToModel: ->