Relying on the change handler for AllGpxes and FPX import.

This commit is contained in:
vdv committed 2022-12-09 14:57:54 +01:00
1 parent 21a63ec54c
commit c2d6f6f285
4 files changed
+57 -20

No files matched your search

+17 -8
View File
@@ -1,28 +1,37 @@
import { getWpt } from '../db/wpt';
import { returnAgain } from '../workers/dispatcher-worker';
import { getAllGpxes } from './gpx';
declare global {
var watches: Map<string, any>;
}
const methods = {
getAllGpxes,
getWpt,
};
const sendUpdate = async (params: any) => {
if (params) {
console.log({ caller: 'ChangeHandler / sendUpdate', params });
const { method, _dispatchId, id, ...otherParams } = params;
const returnValue = await methods[<keyof typeof methods>method](params);
if (returnValue) {
returnAgain(_dispatchId, returnValue);
}
}
};
const changeHandler = async (change: any) => {
console.log({ caller: 'ChangeHandler', change });
const { id } = change;
if (!globalThis.watches) {
globalThis.watches = new Map();
}
const params = globalThis.watches.get(id);
if (params) {
const { method, _dispatchId, id, ...otherParams } = params;
const returnValue = await methods[<keyof typeof methods>method](params);
if (returnValue) {
returnAgain(_dispatchId, returnValue);
}
}
sendUpdate(globalThis.watches.get(id));
const parentId = id.substring(0, id.lastIndexOf('/'));
sendUpdate(globalThis.watches.get(parentId));
};
export default changeHandler;