Save state on mousedown or keypress events (debounce 1s). Tests WIP

This commit is contained in:
Katrina Uychaco 2016-01-27 11:15:02 -07:00
parent 39cb52c224
commit df83078d74
2 changed files with 16 additions and 0 deletions

View File

@ -174,6 +174,19 @@ describe "AtomEnvironment", ->
atom.loadStateSync()
expect(atom.state.stuff).toBe("cool")
it "saves state on keypress and mousedown events", ->
spyOn(atom, 'saveStateSync')
keypress = new KeyboardEvent('keypress')
atom.document.dispatchEvent(keypress)
advanceClock 1100
expect(atom.saveStateSync).toHaveBeenCalled()
mousedown = new MouseEvent('mousedown')
atom.document.dispatchEvent(mousedown)
advanceClock 1100
expect(atom.saveStateSync).toHaveBeenCalled()
describe "openInitialEmptyEditorIfNecessary", ->
describe "when there are no paths set", ->
beforeEach ->

View File

@ -119,6 +119,9 @@ class AtomEnvironment extends Model
constructor: (params={}) ->
{@blobStore, @applicationDelegate, @window, @document, configDirPath, @enablePersistence, onlyLoadBaseStyleSheets} = params
@document.addEventListener('mousedown', _.debounce(@saveStateSync.bind(this), 1000), true)
@document.addEventListener('keypress', _.debounce(@saveStateSync.bind(this), 1000), true)
@state = {version: @constructor.version}
@loadTime = null