f7164dd4c0
try to defer more work, split everything up into more functional code for easier reading
21 lines
691 B
JavaScript
21 lines
691 B
JavaScript
import { store } from '../_store/store'
|
|
import { getLists } from '../_api/lists'
|
|
import { cacheFirstUpdateAfter } from '../_utils/sync'
|
|
import { database } from '../_database/database'
|
|
|
|
export async function updateListsForInstance (instanceName) {
|
|
let { loggedInInstances } = store.get()
|
|
let accessToken = loggedInInstances[instanceName].access_token
|
|
|
|
await cacheFirstUpdateAfter(
|
|
() => getLists(instanceName, accessToken),
|
|
() => database.getLists(instanceName),
|
|
lists => database.setLists(instanceName, lists),
|
|
lists => {
|
|
let { instanceLists } = store.get()
|
|
instanceLists[instanceName] = lists
|
|
store.set({ instanceLists: instanceLists })
|
|
}
|
|
)
|
|
}
|