mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-09-01 08:12:32 +00:00
fix elevation profile fill not resetting, closes #40
This commit is contained in:
@@ -42,14 +42,22 @@ class Database extends Dexie {
|
|||||||
export const db = new Database();
|
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
|
// 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> {
|
export function bidirectionalDexieStore<K, V>(table: Dexie.Table<V, K>, key: K, initial: V, initialize: boolean = true): Writable<V | undefined> {
|
||||||
let store = writable(initialize ? initial : undefined);
|
let first = true;
|
||||||
|
let store = writable<V | undefined>(initialize ? initial : undefined);
|
||||||
liveQuery(() => table.get(key)).subscribe(value => {
|
liveQuery(() => table.get(key)).subscribe(value => {
|
||||||
if (value === undefined && !initialize) {
|
if (value === undefined) {
|
||||||
store.set(initial);
|
if (first) {
|
||||||
} else if (value !== undefined) {
|
if (!initialize) {
|
||||||
|
store.set(initial);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
store.set(value);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
store.set(value);
|
store.set(value);
|
||||||
}
|
}
|
||||||
|
first = false;
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
subscribe: store.subscribe,
|
subscribe: store.subscribe,
|
||||||
|
Reference in New Issue
Block a user