do not compute stats on draft object

This commit is contained in:
vcoppe
2024-05-03 17:37:34 +02:00
parent 28a50dd46e
commit e9cf49f51b
5 changed files with 13 additions and 28 deletions

View File

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

View File

@@ -40,7 +40,7 @@ function decrementColor(color: string) {
export class GPXLayer {
map: mapboxgl.Map;
fileId: string;
file: Readable<FreezedObject<GPXFile> | undefined>;
file: Readable<GPXFile | undefined>;
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<FreezedObject<GPXFile> | undefined>, popup: mapboxgl.Popup, popupElement: HTMLElement) {
constructor(map: mapboxgl.Map, fileId: string, file: Readable<GPXFile | undefined>, popup: mapboxgl.Popup, popupElement: HTMLElement) {
this.map = map;
this.fileId = fileId;
this.file = file

View File

@@ -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<FreezedObject<GPXFile> | undefined>;
file: Readable<GPXFile | undefined>;
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<GPXFile>, popup: mapboxgl.Popup, popupElement: HTMLElement) {
constructor(map: mapboxgl.Map, fileId: string, file: Readable<GPXFile | undefined>, popup: mapboxgl.Popup, popupElement: HTMLElement) {
this.map = map;
this.fileId = fileId;
this.file = file;

View File

@@ -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<GPXFile> | undefined | Promise<FreezedObject<GPXFile> | undefined>): Writable<FreezedObject<GPXFile>> {
let store = writable<FreezedObject<GPXFile>>(undefined);
function dexieFileStore(querier: () => FreezedObject<GPXFile> | undefined | Promise<FreezedObject<GPXFile> | undefined>): Readable<GPXFile> {
let store = writable<GPXFile>(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<string, FreezedObject<G
}
}
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
export const fileObservers: Writable<Map<string, Readable<GPXFile | undefined>>> = writable(new Map());
const fileState: Map<string, GPXFile> = new Map(); // Used to generate patches
liveQuery(() => db.fileids.toArray()).subscribe(dbFileIds => {
// Find new files to observe