Tighten up data loading code

feature/default_network_editable
Dan Finlay 7 years ago
parent b97ac5106f
commit 64fcd27102
  1. 12
      app/scripts/background.js

@ -68,10 +68,10 @@ async function initialize () {
async function loadStateFromPersistence () {
// migrations
const migrator = new Migrator({ migrations })
// read from disk
versionedData = diskStore.getState() || migrator.generateInitialState(firstTimeState)
// fetch from extension store and merge in data
// read from disk
// first from preferred, async API:
let localStoreData
if (localStore.isSupported) {
let localData
try {
@ -82,10 +82,14 @@ async function loadStateFromPersistence () {
// If localStore is supported but has not been written to yet, ignore:
if (Object.keys(localData).length > 0) {
versionedData = localData
localStoreData = localData
}
}
versionedData = localStoreData ||
diskStore.getState() ||
migrator.generateInitialState(firstTimeState)
// migrate data
versionedData = await migrator.migrateData(versionedData)

Loading…
Cancel
Save