Remove unnecessary calls to ViewRegistry.getView

This commit is contained in:
Max Brunsfeld 2017-04-05 16:50:04 -07:00
parent 6344f9884d
commit 2ed0724fc4
9 changed files with 30 additions and 36 deletions

View File

@ -9,10 +9,10 @@ describe('Dock', () => {
const dock = atom.workspace.getLeftDock()
expect(dock.isOpen()).toBe(false)
expect(document.activeElement).toBe(atom.views.getView(atom.workspace.getCenter().getActivePane()))
expect(document.activeElement).toBe(atom.workspace.getCenter().getActivePane().getElement())
dock.activate()
expect(dock.isOpen()).toBe(true)
expect(document.activeElement).toBe(atom.views.getView(dock.getActivePane()))
expect(document.activeElement).toBe(dock.getActivePane().getElement())
})
})

View File

@ -1,14 +1,9 @@
module.exports =
activateCallCount: 0
activationCommandCallCount: 0
legacyActivationCommandCallCount: 0
activate: ->
@activateCallCount++
atom.commands.add 'atom-workspace', 'activation-command', =>
@activationCommandCallCount++
editorView = atom.views.getView(atom.workspace.getActiveTextEditor())?.__spacePenView
editorView?.command 'activation-command', =>
@legacyActivationCommandCallCount++

View File

@ -336,7 +336,6 @@ describe "PackageManager", ->
beforeEach ->
jasmine.attachToDOM(atom.workspace.getElement())
mainModule = require './fixtures/packages/package-with-activation-commands/index'
mainModule.legacyActivationCommandCallCount = 0
mainModule.activationCommandCallCount = 0
spyOn(mainModule, 'activate').andCallThrough()
spyOn(Package.prototype, 'requireMainModule').andCallThrough()
@ -366,7 +365,7 @@ describe "PackageManager", ->
atom.workspace.open()
runs ->
editorElement = atom.views.getView(atom.workspace.getActiveTextEditor())
editorElement = atom.workspace.getActiveTextEditor().getElement()
editorCommandListener = jasmine.createSpy("editorCommandListener")
atom.commands.add 'atom-text-editor', 'activation-command', editorCommandListener
atom.commands.dispatch(editorElement, 'activation-command')

View File

@ -16,20 +16,20 @@ describe "PaneAxisElement", ->
container = new PaneContainer(config: atom.config, applicationDelegate: atom.applicationDelegate, viewRegistry: atom.views)
axis = new PaneAxis({}, atom.views)
axis.setContainer(container)
axisElement = atom.views.getView(axis)
axisElement = axis.getElement()
panes = [buildPane(), buildPane(), buildPane()]
jasmine.attachToDOM(axisElement)
axis.addChild(panes[0])
expect(axisElement.children[0]).toBe(atom.views.getView(panes[0]))
expect(axisElement.children[0]).toBe(panes[0].getElement())
axisElement.remove()
axis.addChild(panes[1])
expect(axisElement.children[2]).toBeUndefined()
jasmine.attachToDOM(axisElement)
expect(axisElement.children[2]).toBe(atom.views.getView(panes[1]))
expect(axisElement.children[2]).toBe(panes[1].getElement())
axis.addChild(panes[2])
expect(axisElement.children[4]).toBe(atom.views.getView(panes[2]))
expect(axisElement.children[4]).toBe(panes[2].getElement())

View File

@ -50,11 +50,11 @@ describe "PaneContainerElement", ->
it "transfers focus to the next pane if a focused pane is removed", ->
container = new PaneContainer(params)
containerElement = atom.views.getView(container)
containerElement = container.getElement()
leftPane = container.getActivePane()
leftPaneElement = atom.views.getView(leftPane)
leftPaneElement = leftPane.getElement()
rightPane = leftPane.splitRight()
rightPaneElement = atom.views.getView(rightPane)
rightPaneElement = rightPane.getElement()
jasmine.attachToDOM(containerElement)
rightPaneElement.focus()
@ -74,25 +74,25 @@ describe "PaneContainerElement", ->
horizontalPanes = containerElement.querySelectorAll('atom-pane-container > atom-pane-axis.horizontal > atom-pane')
expect(horizontalPanes.length).toBe 1
expect(horizontalPanes[0]).toBe atom.views.getView(pane1)
expect(horizontalPanes[0]).toBe pane1.getElement()
verticalPanes = containerElement.querySelectorAll('atom-pane-container > atom-pane-axis.horizontal > atom-pane-axis.vertical > atom-pane')
expect(verticalPanes.length).toBe 2
expect(verticalPanes[0]).toBe atom.views.getView(pane2)
expect(verticalPanes[1]).toBe atom.views.getView(pane3)
expect(verticalPanes[0]).toBe pane2.getElement()
expect(verticalPanes[1]).toBe pane3.getElement()
pane1.destroy()
verticalPanes = containerElement.querySelectorAll('atom-pane-container > atom-pane-axis.vertical > atom-pane')
expect(verticalPanes.length).toBe 2
expect(verticalPanes[0]).toBe atom.views.getView(pane2)
expect(verticalPanes[1]).toBe atom.views.getView(pane3)
expect(verticalPanes[0]).toBe pane2.getElement()
expect(verticalPanes[1]).toBe pane3.getElement()
describe "when the resize element is dragged ", ->
[container, containerElement] = []
beforeEach ->
container = new PaneContainer(params)
containerElement = atom.views.getView(container)
containerElement = container.getElement()
document.querySelector('#jasmine-content').appendChild(containerElement)
dragElementToPosition = (element, clientX) ->
@ -217,11 +217,11 @@ describe "PaneContainerElement", ->
expect(leftPane.getFlexScale()).toBe 1
expect(rightPane.getFlexScale()).toBe 1
atom.commands.dispatch(atom.views.getView(leftPane), 'pane:increase-size')
atom.commands.dispatch(leftPane.getElement(), 'pane:increase-size')
expect(leftPane.getFlexScale()).toBe 1.1
expect(rightPane.getFlexScale()).toBe 1
atom.commands.dispatch(atom.views.getView(rightPane), 'pane:increase-size')
atom.commands.dispatch(rightPane.getElement(), 'pane:increase-size')
expect(leftPane.getFlexScale()).toBe 1.1
expect(rightPane.getFlexScale()).toBe 1.1
@ -230,11 +230,11 @@ describe "PaneContainerElement", ->
expect(leftPane.getFlexScale()).toBe 1
expect(rightPane.getFlexScale()).toBe 1
atom.commands.dispatch(atom.views.getView(leftPane), 'pane:decrease-size')
atom.commands.dispatch(leftPane.getElement(), 'pane:decrease-size')
expect(leftPane.getFlexScale()).toBe 1/1.1
expect(rightPane.getFlexScale()).toBe 1
atom.commands.dispatch(atom.views.getView(rightPane), 'pane:decrease-size')
atom.commands.dispatch(rightPane.getElement(), 'pane:decrease-size')
expect(leftPane.getFlexScale()).toBe 1/1.1
expect(rightPane.getFlexScale()).toBe 1/1.1
@ -286,7 +286,7 @@ describe "PaneContainerElement", ->
pane8 = pane7.splitRight(items: [item8])
pane9 = pane8.splitRight(items: [item9])
containerElement = atom.views.getView(container)
containerElement = container.getElement()
containerElement.style.height = '400px'
containerElement.style.width = '400px'
jasmine.attachToDOM(containerElement)

View File

@ -12,9 +12,9 @@ describe "PaneElement", ->
confirm: atom.confirm.bind(atom)
viewRegistry: atom.views
applicationDelegate: atom.applicationDelegate
containerElement = atom.views.getView(container)
containerElement = container.getElement()
pane = container.getActivePane()
paneElement = atom.views.getView(pane)
paneElement = pane.getElement()
describe "when the pane's active status changes", ->
it "adds or removes the .active class as appropriate", ->
@ -120,7 +120,7 @@ describe "PaneElement", ->
item2 = document.createElement('div')
pane.addItem(item1)
pane.addItem(item2)
paneElement = atom.views.getView(pane)
paneElement = pane.getElement()
expect(item1.parentElement).toBe paneElement.itemViews
pane.destroyItem(item1)

View File

@ -53,7 +53,7 @@ describe "TextEditorElement", ->
it "does not render duplicate line numbers", ->
editor = new TextEditor
editor.setText('1\n2\n3')
element = atom.views.getView(editor)
element = editor.getElement()
jasmine.attachToDOM(element)
@ -69,7 +69,7 @@ describe "TextEditorElement", ->
editor.addGutter({name: 'test-gutter'})
marker = editor.markBufferRange([[0, 0], [2, 0]])
editor.decorateMarker(marker, {type: 'gutter', gutterName: 'test-gutter'})
element = atom.views.getView(editor)
element = editor.getElement()
jasmine.attachToDOM(element)
initialDecorationCount = element.querySelectorAll('.decoration').length
@ -230,7 +230,7 @@ describe "TextEditorElement", ->
it "returns the maximum scroll top that can be applied to the element", ->
editor = new TextEditor
editor.setText('1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16')
element = atom.views.getView(editor)
element = editor.getElement()
element.style.lineHeight = "10px"
element.style.width = "200px"
jasmine.attachToDOM(element)

View File

@ -50,7 +50,7 @@ describe('WorkspaceElement', () => {
workspaceElement = atom.workspace.getElement()
jasmine.attachToDOM(workspaceElement)
editor = atom.workspace.getActiveTextEditor()
editorElement = atom.views.getView(editor)
editorElement = editor.getElement()
})
})

View File

@ -43,7 +43,7 @@ AnyConstructor = Symbol('any-constructor')
#
# ```coffee
# pane = atom.workspace.getActivePane()
# paneElement = atom.views.getView(pane)
# paneElement = pane.getElement()
# ```
module.exports =
class ViewRegistry
@ -133,7 +133,7 @@ class ViewRegistry
#
# ```coffee
# pane = atom.workspace.getActivePane()
# paneElement = atom.views.getView(pane)
# paneElement = pane.getElement()
# ```
#
# ### Getting The Workspace Element