fix typings

This commit is contained in:
vcoppe
2024-05-03 16:19:11 +02:00
parent 6c9faf54b1
commit 28a50dd46e
4 changed files with 14 additions and 9 deletions

View File

@@ -10,8 +10,9 @@
import { _ } from 'svelte-i18n';
import type { GPXFile } from 'gpx';
import type { FreezedObject } from 'structurajs';
export let file: Readable<GPXFile | undefined>;
export let file: Readable<FreezedObject<GPXFile> | undefined>;
</script>
<!-- svelte-ignore a11y-no-static-element-interactions -->

View File

@@ -8,11 +8,12 @@ import { toast } from "svelte-sonner";
import { _ } from "svelte-i18n";
import { dbUtils } from "$lib/db";
import type { FreezedObject } from "structurajs";
export class RoutingControls {
map: mapboxgl.Map;
fileId: string = '';
file: Readable<GPXFile | undefined>;
file: Readable<FreezedObject<GPXFile> | undefined>;
anchors: AnchorWithMarker[] = [];
shownAnchors: AnchorWithMarker[] = [];
popup: mapboxgl.Popup;

View File

@@ -1,6 +1,6 @@
import Dexie, { liveQuery } from 'dexie';
import { GPXFile } from 'gpx';
import { type FreezedObject, type Patch, produceWithPatches, applyPatches } from 'structurajs';
import { type FreezedObject, type Patch, produceWithPatches, applyPatches, freeze } from 'structurajs';
import { writable, get, derived, type Readable, type Writable } from 'svelte/store';
import { fileOrder, selectedFiles } from './stores';
@@ -27,17 +27,19 @@ class Database extends Dexie {
const db = new Database();
function dexieFileStore(querier: () => FreezedObject<GPXFile> | undefined | Promise<FreezedObject<GPXFile> | undefined>): Readable<GPXFile> {
let store = writable<GPXFile>(undefined);
function dexieFileStore(querier: () => FreezedObject<GPXFile> | undefined | Promise<FreezedObject<GPXFile> | undefined>): Writable<FreezedObject<GPXFile>> {
let store = writable<FreezedObject<GPXFile>>(undefined);
liveQuery(querier).subscribe(value => {
if (value !== undefined) {
let gpx = new GPXFile(value);
let gpx = freeze(new GPXFile(value));
fileState.set(gpx._data.id, gpx);
store.set(gpx);
}
});
return {
subscribe: store.subscribe,
update: store.update,
set: store.set
};
}
@@ -83,8 +85,8 @@ function commitFileStateChange(newFileState: ReadonlyMap<string, FreezedObject<G
}
}
export const fileObservers: Writable<Map<string, Readable<GPXFile | undefined>>> = writable(new Map());
const fileState: Map<string, GPXFile> = new Map(); // Used to generate patches
export const fileObservers: Writable<Map<string, Writable<FreezedObject<GPXFile> | undefined>>> = writable(new Map());
const fileState: Map<string, FreezedObject<GPXFile>> = new Map(); // Used to generate patches
liveQuery(() => db.fileids.toArray()).subscribe(dbFileIds => {
// Find new files to observe

View File

@@ -6,6 +6,7 @@ import { tick } from 'svelte';
import { _ } from 'svelte-i18n';
import type { GPXLayer } from '$lib/components/gpx-layer/GPXLayer';
import { dbUtils, fileObservers } from './db';
import type { FreezedObject } from 'structurajs';
export const map = writable<mapboxgl.Map | null>(null);
@@ -192,7 +193,7 @@ export function exportAllFiles() {
});
}
export function exportFile(file: GPXFile) {
export function exportFile(file: FreezedObject<GPXFile>) {
let blob = new Blob([buildGPX(file)], { type: 'application/gpx+xml' });
let url = URL.createObjectURL(blob);
let a = document.createElement('a');