pinafore/routes/_actions/lists.js
Nolan Lawson f7164dd4c0
fix(observers): refactor instance observers, minor optimizations (#730)
try to defer more work, split everything up into more functional code for easier reading
2018-12-05 00:21:54 -08:00

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 })
}
)
}