From d08180ceb0c640c1d69e0a7ca735b5aa31f18799 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 1 Oct 2015 16:43:16 -0600 Subject: [PATCH] Remove mode parameter from atom environment --- spec/atom-spec.coffee | 5 ++--- src/atom.coffee | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/spec/atom-spec.coffee b/spec/atom-spec.coffee index 9bcb985ee..7fb26f102 100644 --- a/spec/atom-spec.coffee +++ b/spec/atom-spec.coffee @@ -151,16 +151,15 @@ describe "the `atom` global", -> spyOn(Atom, 'getLoadSettings').andCallFake -> loadSettings spyOn(Atom.getStorageFolder(), 'getPath').andReturn(temp.mkdirSync("storage-dir-")) - atom.mode = "editor" atom.state.stuff = "cool" atom.project.setPaths([dir1, dir2]) atom.saveSync.originalValue.call(atom) - atom1 = Atom.loadOrCreate("editor") + atom1 = Atom.loadOrCreate() expect(atom1.state.stuff).toBeUndefined() loadSettings.initialPaths = [dir2, dir1] - atom2 = Atom.loadOrCreate("editor") + atom2 = Atom.loadOrCreate() expect(atom2.state.stuff).toBe("cool") describe "openInitialEmptyEditorIfNecessary", -> diff --git a/src/atom.coffee b/src/atom.coffee index 6ae31c767..090ce4ee3 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -43,9 +43,9 @@ class Atom extends Model # kind of environment you want to build. # # Returns an Atom instance, fully initialized - @loadOrCreate: (mode) -> + @loadOrCreate: -> startTime = Date.now() - atom = @deserialize(@loadState(mode)) ? new this({mode, @version}) + atom = @deserialize(@loadState()) ? new this({@version}) atom.deserializeTimings.atom = Date.now() - startTime atom @@ -55,8 +55,8 @@ class Atom extends Model # Loads and returns the serialized state corresponding to this window # if it exists; otherwise returns undefined. - @loadState: (mode) -> - if stateKey = @getStateKey(@getLoadSettings().initialPaths, mode) + @loadState: -> + if stateKey = @getStateKey(@getLoadSettings().initialPaths) if state = @getStorageFolder().load(stateKey) return state @@ -68,10 +68,8 @@ class Atom extends Model # Returns the path where the state for the current window will be # located if it exists. - @getStateKey: (paths, mode) -> - if mode is 'spec' - 'spec' - else if mode is 'editor' and paths?.length > 0 + @getStateKey: (paths) -> + if paths?.length > 0 sha1 = crypto.createHash('sha1').update(paths.slice().sort().join("\n")).digest('hex') "editor-#{sha1}" else @@ -156,8 +154,9 @@ class Atom extends Model ### # Call .loadOrCreate instead - constructor: (@state) -> - {@mode} = @state + constructor: (@state={}) -> + @state.version ?= @constructor.version + @loadTime = null {devMode, safeMode, resourcePath} = @getLoadSettings() configDirPath = @getConfigDirPath() @@ -779,7 +778,7 @@ class Atom extends Model dialog.showSaveDialog currentWindow, options saveSync: -> - if storageKey = @constructor.getStateKey(@project?.getPaths(), @mode) + if storageKey = @constructor.getStateKey(@project?.getPaths()) @constructor.getStorageFolder().store(storageKey, @state) else @getCurrentWindow().loadSettings.windowState = JSON.stringify(@state)