mirror of
https://github.com/atom/atom.git
synced 2026-01-26 07:19:06 -05:00
Store packages in array instead of a hash by name
This commit is contained in:
@@ -155,12 +155,14 @@ describe "RootView", ->
|
||||
it "absorbs exceptions that are thrown by the package module's serialize methods", ->
|
||||
spyOn(console, 'error')
|
||||
|
||||
rootView.activatePackage "bad-egg",
|
||||
rootView.activatePackage "REMOVE THIS",
|
||||
name: "bad-egg"
|
||||
packageMain:
|
||||
activate: ->
|
||||
serialize: -> throw new Error("I'm broken")
|
||||
|
||||
rootView.activatePackage "good-egg"
|
||||
rootView.activatePackage "REMOVE THIS",
|
||||
name: "good-egg"
|
||||
packageMain:
|
||||
activate: ->
|
||||
serialize: -> "I still get called"
|
||||
@@ -423,6 +425,7 @@ describe "RootView", ->
|
||||
|
||||
beforeEach ->
|
||||
pack =
|
||||
name: "package"
|
||||
packageMain:
|
||||
configDefaults: foo: { bar: 2, baz: 3 }
|
||||
activate: jasmine.createSpy("activate")
|
||||
@@ -433,33 +436,30 @@ describe "RootView", ->
|
||||
|
||||
describe ".activatePackage(name, package)", ->
|
||||
it "calls activate on the package", ->
|
||||
rootView.activatePackage('package', pack)
|
||||
rootView.activatePackage('REMOVE ME', pack)
|
||||
expect(packageModule.activate).toHaveBeenCalledWith(undefined)
|
||||
|
||||
it "calls activate on the package module with its previous state", ->
|
||||
rootView.activatePackage('package', pack)
|
||||
rootView.activatePackage('REMOVE ME', pack)
|
||||
packageModule.activate.reset()
|
||||
|
||||
newRootView = RootView.deserialize(rootView.serialize())
|
||||
newRootView.activatePackage('package', pack)
|
||||
newRootView.activatePackage('REMOVE ME', pack)
|
||||
expect(packageModule.activate).toHaveBeenCalledWith("it worked")
|
||||
newRootView.remove()
|
||||
|
||||
describe ".deactivatePackage(packageName)", ->
|
||||
it "deactivates and removes the package module from the package module map", ->
|
||||
rootView.activatePackage('package', pack)
|
||||
expect(rootView.packages['package']).toBeTruthy()
|
||||
rootView.activatePackage('REMOVE ME', pack)
|
||||
spyOn(packageModule, "deactivate").andCallThrough()
|
||||
rootView.deactivatePackage('package')
|
||||
rootView.deactivatePackages()
|
||||
expect(packageModule.deactivate).toHaveBeenCalled()
|
||||
expect(rootView.packages['package']).toBeFalsy()
|
||||
expect(rootView.packages.length).toBe 0
|
||||
|
||||
it "is called when the rootView is deactivated to deactivate all packages", ->
|
||||
rootView.activatePackage('package', pack)
|
||||
spyOn(rootView, "deactivatePackage").andCallThrough()
|
||||
spyOn(packageModule, "deactivate").andCallThrough()
|
||||
rootView.deactivate()
|
||||
expect(rootView.deactivatePackage).toHaveBeenCalled()
|
||||
expect(packageModule.deactivate).toHaveBeenCalled()
|
||||
|
||||
describe "keymap wiring", ->
|
||||
|
||||
@@ -41,7 +41,7 @@ class RootView extends View
|
||||
initialize: (projectOrPathToOpen, { @packageStates, suppressOpen } = {}) ->
|
||||
window.rootView = this
|
||||
@packageStates ?= {}
|
||||
@packages = {}
|
||||
@packages = []
|
||||
@viewClasses = {
|
||||
"Pane": Pane,
|
||||
"PaneRow": PaneRow,
|
||||
@@ -126,7 +126,7 @@ class RootView extends View
|
||||
|
||||
deactivate: ->
|
||||
atom.setRootViewStateForPath(@project.getPath(), @serialize())
|
||||
@deactivatePackage(name) for name of @packages
|
||||
@deactivatePackages()
|
||||
@remove()
|
||||
|
||||
open: (path, options = {}) ->
|
||||
@@ -263,18 +263,18 @@ class RootView extends View
|
||||
@project.eachBuffer(callback)
|
||||
|
||||
activatePackage: (name, pack) ->
|
||||
@packages[name] = pack
|
||||
pack.packageMain.activate(@packageStates[name])
|
||||
@packages.push(pack)
|
||||
pack.packageMain.activate(@packageStates[pack.name])
|
||||
|
||||
deactivatePackage: (name) ->
|
||||
@packages[name].packageMain.deactivate?()
|
||||
delete @packages[name]
|
||||
deactivatePackages: ->
|
||||
pack.packageMain.deactivate?() for pack in @packages
|
||||
@packages = []
|
||||
|
||||
serializePackages: ->
|
||||
packageStates = {}
|
||||
for name, pack of @packages
|
||||
for pack in @packages
|
||||
try
|
||||
packageStates[name] = pack.packageMain.serialize?()
|
||||
packageStates[pack.name] = pack.packageMain.serialize?()
|
||||
catch e
|
||||
console?.error("Exception serializing '#{name}' package's module\n", e.stack)
|
||||
packageStates
|
||||
|
||||
Reference in New Issue
Block a user