improve flow

This commit is contained in:
vcoppe committed 2026-10-14 08:07:58 +02:00
1 parent 1d13972014
commit 3c2055b50e
7 files changed
+80 -90

No files matched your search

+3 -8
View File
@@ -33,9 +33,6 @@ import {
type WaypointDetails,
} from './types';
/** The error of the outcomes while the stored files come from a newer version of the app. */
const OUTDATED = 'saved by a newer version';
/**
* Thin wrapper around the WASM engine.
*
@@ -70,7 +67,7 @@ class Engine {
readonly order: Readable<string[]> = { subscribe: this._order.subscribe };
/** Statistics of what is currently selected. */
readonly statistics: Readable<SelectionStatistics> = this._statistics.store;
/** Whether the stored files are from a newer version of the app: they cannot be changed. */
/** Whether the stored files are from a newer version of the app: changes are not kept, the page has to be reloaded. */
readonly outdated: Readable<boolean> = { subscribe: this._outdated.subscribe };
readonly canUndo: Readable<boolean> = { subscribe: this._canUndo.subscribe };
readonly canRedo: Readable<boolean> = { subscribe: this._canRedo.subscribe };
@@ -116,6 +113,7 @@ class Engine {
wasm: this.wasm!,
visibility: this._visibility,
sync: (update) => this.sync(this.wasm!, update),
outdated: () => this._outdated.set(true),
hasFiles: () => get(this._order).length > 0,
loadFiles: (files) => this.loadFiles(files),
deselect: () => this.select([]),
@@ -702,16 +700,13 @@ class Engine {
this._lastError.set(outcome.error);
if (outcome.error === 'nothing to do') {
console.debug('engine:', outcome.error);
} else if (outcome.error !== undefined && outcome.error !== OUTDATED) {
} else if (outcome.error !== undefined) {
console.warn('engine:', outcome.error);
}
}
/** Updates what is kept of the engine with what a call changed. */
private sync(wasm: Wasm, update: Outcome) {
if (update.error === OUTDATED) {
this._outdated.set(true);
}
this._canUndo.set(wasm.can_undo());
this._canRedo.set(wasm.can_redo());
this._canPaste.set(wasm.can_paste());
+13 -3
View File
@@ -16,6 +16,8 @@ export type StorageHost = {
visibility: Map<string, Visibility>;
/** Applies what a call changed to what the facade keeps of the files. */
sync(update: Outcome): void;
/** Tells that what is stored comes from a newer version of the app: nothing can be saved. */
outdated(): void;
hasFiles(): boolean;
loadFiles(files: { data: Uint8Array; name: string }[]): Promise<boolean>;
deselect(): Promise<boolean>;
@@ -27,7 +29,11 @@ export type StorageHost = {
* what they hold (see `sync_storage`). The same happens when a write of this tab is refused
* because of that, and when the tab is shown again (a hidden tab can miss messages).
*/
function followOtherTabs(host: StorageHost): { saved: () => void; behind: () => void } {
function followOtherTabs(host: StorageHost): {
saved: () => void;
behind: () => void;
newer: () => void;
} {
const { wasm } = host;
let reading = Promise.resolve();
const refresh = () => {
@@ -47,7 +53,11 @@ function followOtherTabs(host: StorageHost): { saved: () => void; behind: () =>
}
});
}
return { saved: () => channel?.postMessage('saved'), behind: refresh };
return {
saved: () => channel?.postMessage('saved'),
behind: refresh,
newer: () => host.outdated(),
};
}
/**
@@ -61,7 +71,7 @@ export async function openStoredFiles(host: StorageHost): Promise<Record<string,
let opened: StorageOpened;
const tabs = followOtherTabs(host);
try {
opened = await wasm.open_storage(STORAGE_NAME, tabs.saved, tabs.behind);
opened = await wasm.open_storage(STORAGE_NAME, tabs.saved, tabs.behind, tabs.newer);
} catch (error) {
console.error('The files cannot be kept in this browser', error);
return {};