fix elevation profile fill not resetting, closes #40

This commit is contained in:
vcoppe
2024-08-08 23:39:58 +02:00
parent 1cadc870f7
commit 968e26cd02

View File

@@ -42,14 +42,22 @@ class Database extends Dexie {
export const db = new Database();
// Wrap Dexie live queries in a Svelte store to avoid triggering the query for every subscriber, and updates to the store are pushed to the DB
export function bidirectionalDexieStore<K, V>(table: Dexie.Table<V, K>, key: K, initial: V, initialize: boolean = true): Writable<V> {
let store = writable(initialize ? initial : undefined);
export function bidirectionalDexieStore<K, V>(table: Dexie.Table<V, K>, key: K, initial: V, initialize: boolean = true): Writable<V | undefined> {
let first = true;
let store = writable<V | undefined>(initialize ? initial : undefined);
liveQuery(() => table.get(key)).subscribe(value => {
if (value === undefined && !initialize) {
store.set(initial);
} else if (value !== undefined) {
if (value === undefined) {
if (first) {
if (!initialize) {
store.set(initial);
}
} else {
store.set(value);
}
} else {
store.set(value);
}
first = false;
});
return {
subscribe: store.subscribe,