Re-work storage adapter a bit

This commit is contained in:
Jon Staab
2025-11-14 14:59:27 -08:00
parent 62f573eac0
commit bac433b640
2 changed files with 69 additions and 93 deletions
+10 -3
View File
@@ -88,6 +88,9 @@
}
})
// Cleanup on page close
window.addEventListener("beforeunload", () => db.close())
const unsubscribe = call(async () => {
const unsubscribers: Unsubscriber[] = []
@@ -110,10 +113,14 @@
}),
])
// Set up our storage adapters
db.adapters = storage.adapters
// Wait until data storage is initialized before syncing other stuff
if (!db.idbp) {
await db.init(storage.adapters)
}
await db.connect()
// Close the database connection on reload
unsubscribers.push(() => db.close())
// Add our extra policies now that we're set up
defaultSocketPolicies.push(...policies)