From ed0ced205bac32815fb9cdc7442784d5e8fdc858 Mon Sep 17 00:00:00 2001 From: Corey Johnson & Kevin Sawicki Date: Fri, 8 Feb 2013 16:10:05 -0800 Subject: [PATCH] Store packages in array instead of a hash by name --- spec/app/root-view-spec.coffee | 22 +++++++++++----------- src/app/root-view.coffee | 18 +++++++++--------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/spec/app/root-view-spec.coffee b/spec/app/root-view-spec.coffee index 75dd65862..b4bf6eed6 100644 --- a/spec/app/root-view-spec.coffee +++ b/spec/app/root-view-spec.coffee @@ -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", -> diff --git a/src/app/root-view.coffee b/src/app/root-view.coffee index 09bf42ca9..96692c429 100644 --- a/src/app/root-view.coffee +++ b/src/app/root-view.coffee @@ -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