mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-09-02 16:52:31 +00:00
avoid livequerying all patches
This commit is contained in:
@@ -107,9 +107,9 @@ liveQuery(() => db.fileids.toArray()).subscribe(dbFileIds => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const patchIndex: Readable<number> = dexieStore(() => db.settings.get('patchIndex'), -1);
|
const patchIndex: Readable<number> = dexieStore(() => db.settings.get('patchIndex'), -1);
|
||||||
const patches: Readable<{ patch: Patch[], inversePatch: Patch[] }[]> = dexieStore(() => db.patches.toArray(), []);
|
const patchCount: Readable<number> = dexieStore(() => db.patches.count(), 0);
|
||||||
export const canUndo: Readable<boolean> = derived(patchIndex, ($patchIndex) => $patchIndex >= 0);
|
export const canUndo: Readable<boolean> = derived(patchIndex, ($patchIndex) => $patchIndex >= 0);
|
||||||
export const canRedo: Readable<boolean> = derived([patchIndex, patches], ([$patchIndex, $patches]) => $patchIndex < $patches.length - 1);
|
export const canRedo: Readable<boolean> = derived([patchIndex, patchCount], ([$patchIndex, $patchCount]) => $patchIndex < $patchCount - 1);
|
||||||
|
|
||||||
export function applyGlobal(callback: (files: Map<string, GPXFile>) => void) {
|
export function applyGlobal(callback: (files: Map<string, GPXFile>) => void) {
|
||||||
const [newFileState, patch, inversePatch] = produceWithPatches(fileState, callback);
|
const [newFileState, patch, inversePatch] = produceWithPatches(fileState, callback);
|
||||||
@@ -177,16 +177,24 @@ function getFileIds(n: number) {
|
|||||||
export function undo() {
|
export function undo() {
|
||||||
if (get(canUndo)) {
|
if (get(canUndo)) {
|
||||||
let index = get(patchIndex);
|
let index = get(patchIndex);
|
||||||
applyPatch(get(patches)[index].inversePatch);
|
db.patches.get(index).then(patch => {
|
||||||
db.settings.put(index - 1, 'patchIndex');
|
if (patch) {
|
||||||
|
applyPatch(patch.inversePatch);
|
||||||
|
db.settings.put(index - 1, 'patchIndex');
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function redo() {
|
export function redo() {
|
||||||
if (get(canRedo)) {
|
if (get(canRedo)) {
|
||||||
let index = get(patchIndex) + 1;
|
let index = get(patchIndex) + 1;
|
||||||
applyPatch(get(patches)[index].patch);
|
db.patches.get(index).then(patch => {
|
||||||
db.settings.put(index, 'patchIndex');
|
if (patch) {
|
||||||
|
applyPatch(patch.patch);
|
||||||
|
db.settings.put(index, 'patchIndex');
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user