RootView talks about packages and packageModules, not extensions

Now you call `rootView.activatePackage`, etc
This commit is contained in:
Nathan Sobo
2012-12-19 19:24:44 -07:00
parent 275f6f2df5
commit 7dcb12ada2
12 changed files with 77 additions and 82 deletions

View File

@@ -6,9 +6,9 @@ describe "the `atom` global", ->
beforeEach ->
rootView = new RootView
extension = require "package-with-extension"
extension = require "package-with-module"
it "requires and activates the package's main module if it exists", ->
spyOn(rootView, 'activateExtension').andCallThrough()
atom.loadPackage("package-with-extension")
expect(rootView.activateExtension).toHaveBeenCalledWith(extension)
spyOn(rootView, 'activatePackage').andCallThrough()
atom.loadPackage("package-with-module")
expect(rootView.activatePackage).toHaveBeenCalledWith(extension)

View File

@@ -125,24 +125,24 @@ describe "RootView", ->
expect(rootView.getTitle()).toBe 'untitled'
describe ".serialize()", ->
it "absorbs exceptions that are thrown by extension serialize methods", ->
it "absorbs exceptions that are thrown by the package module's serialize methods", ->
spyOn(console, 'error')
rootView.activateExtension(
rootView.activatePackage(
name: "bad-egg"
activate: ->
serialize: -> throw new Error("I'm broken")
)
rootView.activateExtension(
rootView.activatePackage(
name: "good-egg"
activate: ->
serialize: -> "I still get called"
)
data = rootView.serialize()
expect(data.extensionStates['good-egg']).toBe "I still get called"
expect(data.extensionStates['bad-egg']).toBeUndefined()
expect(data.packageStates['good-egg']).toBe "I still get called"
expect(data.packageStates['bad-egg']).toBeUndefined()
expect(console.error).toHaveBeenCalled()
describe "focus", ->
@@ -393,54 +393,49 @@ describe "RootView", ->
rootView.focusNextPane()
expect(view1.focus).toHaveBeenCalled()
describe "extensions", ->
extension = null
describe "packages", ->
packageModule = null
beforeEach ->
extension =
name: 'extension'
packageModule =
name: 'package'
deactivate: ->
activate: jasmine.createSpy("activate")
serialize: -> "it worked"
describe ".activateExtension(extension)", ->
it "calls activate on the extension", ->
rootView.activateExtension(extension)
expect(extension.activate).toHaveBeenCalledWith(rootView, undefined, undefined)
describe ".activatePackage(packageModule)", ->
it "calls activate on the package module", ->
rootView.activatePackage(packageModule)
expect(packageModule.activate).toHaveBeenCalledWith(rootView, undefined)
it "calls activate on the extension with its previous state", ->
rootView.activateExtension(extension)
extension.activate.reset()
it "calls activate on the package module with its previous state", ->
rootView.activatePackage(packageModule)
packageModule.activate.reset()
newRootView = RootView.deserialize(rootView.serialize())
newRootView.activateExtension(extension)
expect(extension.activate).toHaveBeenCalledWith(newRootView, "it worked", undefined)
newRootView.activatePackage(packageModule)
expect(packageModule.activate).toHaveBeenCalledWith(newRootView, "it worked")
newRootView.remove()
it "calls activate on the extension with the config data", ->
config = {}
rootView.activateExtension(extension, config)
expect(extension.activate).toHaveBeenCalledWith(rootView, undefined, config)
it "throws an exception if the package module has no 'name' property", ->
expect(-> rootView.activatePackage({ activate: -> })).toThrow()
it "throws an exception if the extension has no 'name' property", ->
expect(-> rootView.activateExtension({ activate: -> })).toThrow()
describe ".deactivatePackage(packageModule)", ->
it "deactivates and removes the package module from the package module map", ->
rootView.activatePackage(packageModule)
expect(rootView.packageModules[packageModule.name]).toBeTruthy()
spyOn(packageModule, "deactivate").andCallThrough()
rootView.deactivatePackage(packageModule)
expect(packageModule.deactivate).toHaveBeenCalled()
expect(rootView.packageModules[packageModule.name]).toBeFalsy()
describe ".deactivateExtension(extension)", ->
it "deactivates and removes the extension from the extension list", ->
rootView.activateExtension(extension)
expect(rootView.extensions[extension.name]).toBeTruthy()
spyOn(extension, "deactivate").andCallThrough()
rootView.deactivateExtension(extension)
expect(extension.deactivate).toHaveBeenCalled()
expect(rootView.extensions[extension.name]).toBeFalsy()
it "is called when the rootView is deactivated to deactivate all extensions", ->
rootView.activateExtension(extension)
spyOn(rootView, "deactivateExtension").andCallThrough()
spyOn(extension, "deactivate").andCallThrough()
it "is called when the rootView is deactivated to deactivate all packages", ->
rootView.activatePackage(packageModule)
spyOn(rootView, "deactivatePackage").andCallThrough()
spyOn(packageModule, "deactivate").andCallThrough()
rootView.deactivate()
expect(rootView.deactivateExtension).toHaveBeenCalled()
expect(extension.deactivate).toHaveBeenCalled()
expect(rootView.deactivatePackage).toHaveBeenCalled()
expect(packageModule.deactivate).toHaveBeenCalled()
describe "keymap wiring", ->
commandHandler = null

View File

@@ -14,9 +14,9 @@ _.extend atom,
packagePath = require.resolve(name, verifyExistence: false)
throw new Error("No package found named '#{name}'") unless packagePath
packagePath = fs.directory(packagePath)
extension = require(packagePath)
extension.name = name
rootView.activateExtension(extension)
packageModule = require(packagePath)
packageModule.name = name
rootView.activatePackage(packageModule)
extensionKeymapPath = require.resolve(fs.join(name, "src/keymap"), verifyExistence: false)
require extensionKeymapPath if fs.exists(extensionKeymapPath)
catch e

View File

@@ -24,19 +24,19 @@ class RootView extends View
@div id: 'vertical', outlet: 'vertical', =>
@div id: 'panes', outlet: 'panes'
@deserialize: ({ projectPath, panesViewState, extensionStates }) ->
rootView = new RootView(projectPath, extensionStates: extensionStates, suppressOpen: true)
@deserialize: ({ projectPath, panesViewState, packageStates }) ->
rootView = new RootView(projectPath, packageStates: packageStates, suppressOpen: true)
rootView.setRootPane(rootView.deserializeView(panesViewState)) if panesViewState
rootView
extensions: null
extensionStates: null
packageModules: null
packageStates: null
title: null
initialize: (pathToOpen, { @extensionStates, suppressOpen } = {}) ->
initialize: (pathToOpen, { @packageStates, suppressOpen } = {}) ->
window.rootView = this
@extensionStates ?= {}
@extensions = {}
@packageStates ?= {}
@packageModules = {}
@project = new Project(pathToOpen)
config.load()
@@ -53,7 +53,7 @@ class RootView extends View
serialize: ->
projectPath: @project?.getPath()
panesViewState: @panes.children().view()?.serialize()
extensionStates: @serializeExtensions()
packageStates: @serializePackages()
handleEvents: ->
@on 'toggle-dev-tools', => atom.toggleDevTools()
@@ -95,14 +95,14 @@ class RootView extends View
afterAttach: (onDom) ->
@focus() if onDom
serializeExtensions: ->
extensionStates = {}
for name, extension of @extensions
serializePackages: ->
packageStates = {}
for name, packageModule of @packageModules
try
extensionStates[name] = extension.serialize?()
packageStates[name] = packageModule.serialize?()
catch e
console?.error("Exception serializing '#{name}' extension\n", e.stack)
extensionStates
console?.error("Exception serializing '#{name}' package's module\n", e.stack)
packageStates
deserializeView: (viewState) ->
switch viewState.viewClass
@@ -111,18 +111,18 @@ class RootView extends View
when 'PaneColumn' then PaneColumn.deserialize(viewState, this)
when 'Editor' then Editor.deserialize(viewState, this)
activateExtension: (extension, config) ->
throw new Error("Trying to activate an extension with no name attribute") unless extension.name?
@extensions[extension.name] = extension
extension.activate(this, @extensionStates[extension.name], config)
activatePackage: (packageModule) ->
throw new Error("Trying to activate a package module with no name attribute") unless packageModule.name?
@packageModules[packageModule.name] = packageModule
packageModule.activate(this, @packageStates[packageModule.name])
deactivateExtension: (extension) ->
extension.deactivate?()
delete @extensions[extension.name]
deactivatePackage: (packageModule) ->
packageModule.deactivate?()
delete @packageModules[packageModule.name]
deactivate: ->
atom.setRootViewStateForPath(@project.getPath(), @serialize())
@deactivateExtension(extension) for name, extension of @extensions
@deactivatePackage(packageModule) for name, packageModule of @packageModules
@remove()
open: (path, options = {}) ->

View File

@@ -36,7 +36,7 @@ describe "CommandPanel", ->
rootView.deactivate()
rootView2.attachToDom()
commandPanel = rootView2.activateExtension(CommandPanel)
commandPanel = rootView2.activatePackage(CommandPanel)
expect(rootView2.find('.command-panel')).toExist()
expect(commandPanel.miniEditor.getText()).toBe 'abc'
expect(commandPanel.miniEditor.isFocused).toBeTruthy()
@@ -49,7 +49,7 @@ describe "CommandPanel", ->
rootView3 = RootView.deserialize(rootView2.serialize())
rootView2.deactivate()
rootView3.attachToDom()
commandPanel = rootView3.activateExtension(CommandPanel)
commandPanel = rootView3.activatePackage(CommandPanel)
expect(commandPanel.miniEditor.isFocused).toBeFalsy()
rootView3.deactivate()
@@ -71,7 +71,7 @@ describe "CommandPanel", ->
rootView.deactivate()
rootView2.attachToDom()
commandPanel = rootView2.activateExtension(CommandPanel)
commandPanel = rootView2.activatePackage(CommandPanel)
expect(commandPanel.history.length).toBe(2)
expect(commandPanel.history[0]).toBe('/test2')
expect(commandPanel.history[1]).toBe('/test3')

View File

@@ -8,7 +8,7 @@ describe "EventPalette", ->
beforeEach ->
rootView = new RootView(require.resolve('fixtures/sample.js'))
rootView.activateExtension(EventPalette)
atom.loadPackage("event-palette")
palette = EventPalette.instance
rootView.attachToDom().focus()
rootView.trigger 'event-palette:toggle'

View File

@@ -9,7 +9,7 @@ describe 'FuzzyFinder', ->
beforeEach ->
rootView = new RootView(require.resolve('fixtures/sample.js'))
rootView.enableKeymap()
rootView.activateExtension(FuzzyFinder)
atom.loadPackage("fuzzy-finder")
finder = FuzzyFinder.instance
afterEach ->

View File

@@ -7,7 +7,7 @@ describe "MarkdownPreview", ->
beforeEach ->
rootView = new RootView(require.resolve('fixtures/markdown'))
rootView.activateExtension(MarkdownPreview)
atom.loadPackage("markdown-preview")
markdownPreview = MarkdownPreview.instance
rootView.attachToDom()

View File

@@ -7,7 +7,7 @@ describe "OutlineView", ->
beforeEach ->
rootView = new RootView(require.resolve('fixtures'))
rootView.activateExtension(OutlineView)
atom.loadPackage("outline-view")
outlineView = OutlineView.instance
rootView.attachToDom()
setArraySpy = spyOn(outlineView, 'setArray').andCallThrough()

View File

@@ -11,7 +11,7 @@ describe "Tabs", ->
rootView = new RootView(require.resolve('fixtures/sample.js'))
rootView.open('sample.txt')
rootView.simulateDomAttachment()
rootView.activateExtension(Tabs)
atom.loadPackage("tabs")
editor = rootView.getActiveEditor()
tabs = rootView.find('.tabs').view()

View File

@@ -13,7 +13,7 @@ describe "TreeView", ->
rootView = new RootView(require.resolve('fixtures/tree-view'))
project = rootView.project
rootView.activateExtension(TreeView)
atom.loadPackage("tree-view")
treeView = rootView.find(".tree-view").view()
treeView.root = treeView.find('> li:first').view()
sampleJs = treeView.find('.file:contains(tree-view.js)')
@@ -51,7 +51,7 @@ describe "TreeView", ->
rootView.deactivate()
rootView = new RootView
rootView.activateExtension(TreeView)
rootView.activatePackage(TreeView)
treeView = rootView.find(".tree-view").view()
it "does not create a root node", ->
@@ -74,7 +74,7 @@ describe "TreeView", ->
describe "when the prototypes deactivate method is called", ->
it "calls the deactivate on tree view instance", ->
spyOn(treeView, "deactivate").andCallThrough()
rootView.deactivateExtension(TreeView)
rootView.deactivatePackage(TreeView)
expect(treeView.deactivate).toHaveBeenCalled()
describe "serialization", ->
@@ -89,7 +89,7 @@ describe "TreeView", ->
newRootView = RootView.deserialize(rootView.serialize())
rootView.deactivate() # Deactivates previous TreeView
newRootView.activateExtension(TreeView)
newRootView.activatePackage(TreeView)
newTreeView = newRootView.find(".tree-view").view()
@@ -106,7 +106,7 @@ describe "TreeView", ->
rootView.deactivate() # Deactivates previous TreeView
newRootView.attachToDom()
newRootView.activateExtension(TreeView)
newRootView.activatePackage(TreeView)
newTreeView = newRootView.find(".tree-view").view()
expect(newTreeView).toMatchSelector ':focus'
@@ -589,7 +589,7 @@ describe "TreeView", ->
rootView = new RootView(rootDirPath)
project = rootView.project
rootView.activateExtension(TreeView)
rootView.activatePackage(TreeView)
treeView = rootView.find(".tree-view").view()
dirView = treeView.root.entries.find('.directory:contains(test-dir)').view()
dirView.expand()