diff --git a/gpx/src/gpx.ts b/gpx/src/gpx.ts index 0263c012..bd25bbc9 100644 --- a/gpx/src/gpx.ts +++ b/gpx/src/gpx.ts @@ -309,14 +309,8 @@ export class TrackSegment extends GPXTreeLeaf { if (segment) { if (segment instanceof TrackSegment) { this.trkpt = segment.trkpt; - this.statistics = segment.statistics; - this.trkptStatistics = segment.trkptStatistics; } else { this.trkpt = segment.trkpt.map((point) => new TrackPoint(point)); - if (segment.hasOwnProperty('statistics') && segment.hasOwnProperty('trkptStatistics')) { - this.statistics = segment.statistics; - this.trkptStatistics = segment.trkptStatistics; - } } if (segment.hasOwnProperty('_data')) { this._data = cloneJSON(segment._data); @@ -325,9 +319,7 @@ export class TrackSegment extends GPXTreeLeaf { this.trkpt = []; } - if (!this.statistics) { - this._computeStatistics(); - } + this._computeStatistics(); } _computeStatistics(): void { @@ -431,12 +423,10 @@ export class TrackSegment extends GPXTreeLeaf { append(points: TrackPoint[]): void { this.trkpt = this.trkpt.concat(points); - this._computeStatistics(); } replace(start: number, end: number, points: TrackPoint[]): void { this.trkpt.splice(start, end - start + 1, ...points); - this._computeStatistics(); } reverse(originalNextTimestamp: Date | undefined, newPreviousTimestamp: Date | undefined): void { @@ -456,7 +446,6 @@ export class TrackSegment extends GPXTreeLeaf { } else { this.trkpt.reverse(); } - this._computeStatistics(); } getStartTimestamp(): Date { diff --git a/website/src/lib/components/FileListItem.svelte b/website/src/lib/components/FileListItem.svelte index 63c7864c..cde4ecd2 100644 --- a/website/src/lib/components/FileListItem.svelte +++ b/website/src/lib/components/FileListItem.svelte @@ -10,9 +10,8 @@ import { _ } from 'svelte-i18n'; import type { GPXFile } from 'gpx'; - import type { FreezedObject } from 'structurajs'; - export let file: Readable | undefined>; + export let file: Readable; diff --git a/website/src/lib/components/gpx-layer/GPXLayer.ts b/website/src/lib/components/gpx-layer/GPXLayer.ts index f7df044f..ed94ed14 100644 --- a/website/src/lib/components/gpx-layer/GPXLayer.ts +++ b/website/src/lib/components/gpx-layer/GPXLayer.ts @@ -40,7 +40,7 @@ function decrementColor(color: string) { export class GPXLayer { map: mapboxgl.Map; fileId: string; - file: Readable | undefined>; + file: Readable; layerColor: string; popup: mapboxgl.Popup; popupElement: HTMLElement; @@ -50,7 +50,7 @@ export class GPXLayer { updateBinded: () => void = this.update.bind(this); selectOnClickBinded: (e: any) => void = this.selectOnClick.bind(this); - constructor(map: mapboxgl.Map, fileId: string, file: Readable | undefined>, popup: mapboxgl.Popup, popupElement: HTMLElement) { + constructor(map: mapboxgl.Map, fileId: string, file: Readable, popup: mapboxgl.Popup, popupElement: HTMLElement) { this.map = map; this.fileId = fileId; this.file = file diff --git a/website/src/lib/components/toolbar/tools/routing/RoutingControls.ts b/website/src/lib/components/toolbar/tools/routing/RoutingControls.ts index 31834675..c5916fe6 100644 --- a/website/src/lib/components/toolbar/tools/routing/RoutingControls.ts +++ b/website/src/lib/components/toolbar/tools/routing/RoutingControls.ts @@ -8,12 +8,11 @@ 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 | undefined>; + file: Readable; anchors: AnchorWithMarker[] = []; shownAnchors: AnchorWithMarker[] = []; popup: mapboxgl.Popup; @@ -26,7 +25,7 @@ export class RoutingControls { updateTemporaryAnchorBinded: (e: any) => void = this.updateTemporaryAnchor.bind(this); appendAnchorBinded: (e: mapboxgl.MapMouseEvent) => void = this.appendAnchor.bind(this); - constructor(map: mapboxgl.Map, fileId: string, file: Writable, popup: mapboxgl.Popup, popupElement: HTMLElement) { + constructor(map: mapboxgl.Map, fileId: string, file: Readable, popup: mapboxgl.Popup, popupElement: HTMLElement) { this.map = map; this.fileId = fileId; this.file = file; diff --git a/website/src/lib/db.ts b/website/src/lib/db.ts index bbbcf2a8..60d82caf 100644 --- a/website/src/lib/db.ts +++ b/website/src/lib/db.ts @@ -1,6 +1,6 @@ import Dexie, { liveQuery } from 'dexie'; import { GPXFile } from 'gpx'; -import { type FreezedObject, type Patch, produceWithPatches, applyPatches, freeze } from 'structurajs'; +import { type FreezedObject, type Patch, produceWithPatches, applyPatches } from 'structurajs'; import { writable, get, derived, type Readable, type Writable } from 'svelte/store'; import { fileOrder, selectedFiles } from './stores'; @@ -27,19 +27,17 @@ class Database extends Dexie { const db = new Database(); -function dexieFileStore(querier: () => FreezedObject | undefined | Promise | undefined>): Writable> { - let store = writable>(undefined); +function dexieFileStore(querier: () => FreezedObject | undefined | Promise | undefined>): Readable { + let store = writable(undefined); liveQuery(querier).subscribe(value => { if (value !== undefined) { - let gpx = freeze(new GPXFile(value)); + let gpx = new GPXFile(value); fileState.set(gpx._data.id, gpx); store.set(gpx); } }); return { - subscribe: store.subscribe, - update: store.update, - set: store.set + subscribe: store.subscribe }; } @@ -85,8 +83,8 @@ function commitFileStateChange(newFileState: ReadonlyMap | undefined>>> = writable(new Map()); -const fileState: Map> = new Map(); // Used to generate patches +export const fileObservers: Writable>> = writable(new Map()); +const fileState: Map = new Map(); // Used to generate patches liveQuery(() => db.fileids.toArray()).subscribe(dbFileIds => { // Find new files to observe