Dirty hack to store the app state and restore it at app startup.

This commit is contained in:
vdv committed 2022-12-13 22:26:17 +01:00
1 parent acc1d7cc1e
commit 040122189c
4 files changed
+52 -4

No files matched your search

+1 -1
View File
@@ -17,7 +17,7 @@ export const put = async (
current = { _rev: undefined, doc: cloneDeep(defaultDoc) };
}
try {
db.put({ _id, _rev: current._rev, type, doc: update(current.doc) });
await db.put({ _id, _rev: current._rev, type, doc: update(current.doc) });
} catch (error: any) {
if (error.name === 'conflict') {
console.log({ caller: 'db.put', _id, type, defaultDoc, error });
+25
View File
@@ -0,0 +1,25 @@
import { get, put } from './lib';
interface State {
lon: number;
lat: number;
rotation: number;
zoom: number;
provider: string;
}
export const getState = async <State>() => {
try {
const state = (await get('state')).doc;
console.log({ caller: 'getState', state });
return state;
} catch {
return null;
}
};
export const setState = async (state: State) => {
await put('state', 'state', (doc) => state, {});
console.log({ caller: 'setState', state });
return 'state';
};