Save state asynchronously on mousedown and keydown events. Tests WIP

This commit is contained in:
Katrina Uychaco
2016-01-28 00:56:52 -07:00
parent 5148b8ca3d
commit 54a03516bf
3 changed files with 23 additions and 15 deletions

View File

@@ -121,8 +121,8 @@ class AtomEnvironment extends Model
constructor: (params={}) ->
{@blobStore, @applicationDelegate, @window, @document, configDirPath, @enablePersistence, onlyLoadBaseStyleSheets} = params
debouncedSaveStateSync = _.debounce((=> @saveStateSync()), @saveStateDebounceInterval)
@document.addEventListener('mousedown', debouncedSaveStateSync, true)
debouncedSaveState = _.debounce((=> @saveState()), @saveStateDebounceInterval)
@document.addEventListener('mousedown', debouncedSaveState, true)
@document.addEventListener('keydown', debouncedSaveState, true)
@state = {version: @constructor.version}
@@ -653,9 +653,8 @@ class AtomEnvironment extends Model
return if not @project
@storeWindowBackground()
@serialize()
@saveState(true)
@packages.deactivatePackages()
@saveStateSync()
@saveBlobStoreSync()
openInitialEmptyEditorIfNecessary: ->
@@ -789,12 +788,15 @@ class AtomEnvironment extends Model
@blobStore.save()
saveStateSync: ->
saveState: (synchronous) ->
return unless @enablePersistence
@serialize()
if storageKey = @getStateKey(@project?.getPaths())
@getStorageFolder().storeSync(storageKey, @state)
if synchronous
@getStorageFolder().storeSync(storageKey, @state)
else
@getStorageFolder().storeAsync(storageKey, @state)
else
@getCurrentWindow().loadSettings.windowState = JSON.stringify(@state)

View File

@@ -11,6 +11,11 @@ class StorageFolder
fs.writeFileSync(@pathForKey(name), JSON.stringify(object), 'utf8')
storeAsync: (name, object) ->
return unless @path?
fs.writeFile(@pathForKey(name), JSON.stringify(object), 'utf8')
load: (name) ->
return unless @path?