Slight refactoring.

This commit is contained in:
Eric van der Vlist 2023-01-03 11:39:17 +01:00
parent adc37fef03
commit d9c4837f82
3 changed files with 23 additions and 11 deletions

View File

@ -1,5 +1,6 @@
import { Component } from 'solid-js';
import cache from '../../lib/cache';
import { peekCachedSignal } from '../../workers/cached-signals';
import Tree from '../tree';
interface Props {
@ -7,7 +8,7 @@ interface Props {
}
const GpxViewer: Component<Props> = ({ gpxId }) => {
const gpx = cache.get({ cacheId: 'signals', key: gpxId });
const gpx = peekCachedSignal({ id: gpxId, method: 'getGpx' });
console.log({ caller: 'GpxViewer', gpx: gpx() });
const title = () => {};
return <Tree title={'gpx'} content={undefined} subTree={undefined} />;

View File

@ -61,29 +61,22 @@ export const clickHandler = (event: any) => {
selectedFeatures.map((feature: Feature<Geometry>) => {
const gpxId = feature.get('context').gpxId;
if (!hierarchy.hasOwnProperty(gpxId)) {
hierarchy[gpxId] = { gpx: feature.get('context').gpx };
hierarchy[gpxId].type = 'gpx';
hierarchy[gpxId] = { type: 'gpx' };
}
const l2key = level2Key(feature);
if (!hierarchy[gpxId].hasOwnProperty(l2key)) {
hierarchy[gpxId][l2key] = {
wpt: feature.get('context').wpt,
rte: feature.get('context').rte,
trk: feature.get('context').trk,
};
hierarchy[gpxId][l2key] = {};
if (feature.get('type') === 'trkseg') {
hierarchy[gpxId][l2key].type = 'trk';
} else {
hierarchy[gpxId][l2key].type = feature.get('type');
feature;
hierarchy[gpxId][l2key].feature = feature;
}
}
if (feature.get('type') === 'trkseg') {
const trksegId = feature.get('context').trksegId;
if (!hierarchy[gpxId][l2key].hasOwnProperty(trksegId)) {
hierarchy[gpxId][l2key][trksegId] = {
trksegId,
trkseg: feature.get('context').trkseg,
type: 'trkseg',
feature,
};

View File

@ -30,6 +30,24 @@ export const createCachedSignal = (params: any) => {
return signal;
};
export const peekCachedSignal = (params: any) => {
const cachedSignal = cache.get({ cacheId: 'signals', key: params.id });
if (cachedSignal !== null) {
return cachedSignal;
}
const [signal, setSignal] = createSignal();
const callBack = (error: any, result: any, id?: number) => {
if (error) {
console.error({ caller: 'peekCachedSignal / callBack', error });
} else {
console.log({ caller: 'peekCachedSignal / callBack', result });
setSignal(result);
}
};
dispatch(params, callBack, false);
return signal;
};
export const destroyCachedSignal = (params: any) => {
dispatch({
action: 'cancelWatch',