Make stateStore.isConnected a method

This commit is contained in:
Ian Olsen
2017-01-18 15:57:35 -08:00
parent 64f53ee2db
commit 66ae68828e
2 changed files with 8 additions and 3 deletions

View File

@@ -3,6 +3,7 @@
module.exports =
class StateStore {
constructor (databaseName, version) {
this.connected = false
this.dbPromise = new Promise((resolve) => {
let dbOpenRequest = indexedDB.open(databaseName, version)
dbOpenRequest.onupgradeneeded = (event) => {
@@ -10,17 +11,21 @@ class StateStore {
db.createObjectStore('states')
}
dbOpenRequest.onsuccess = () => {
this.isConnected = true
this.connected = true
resolve(dbOpenRequest.result)
}
dbOpenRequest.onerror = (error) => {
console.error('Could not connect to indexedDB', error)
this.isConnected = false
this.connected = false
resolve(null)
}
})
}
isConnected () {
return this.connected
}
connect () {
return this.dbPromise.then((db) => !!db)
}

View File

@@ -892,7 +892,7 @@ class TextEditor extends Model
# Determine whether the user should be prompted to save before closing
# this editor.
shouldPromptToSave: ({windowCloseRequested, projectHasPaths}={}) ->
if windowCloseRequested and projectHasPaths and atom.stateStore.isConnected
if windowCloseRequested and projectHasPaths and atom.stateStore.isConnected()
false
else
@isModified() and not @buffer.hasMultipleEditors()