Slight refactoring.
This commit is contained in:
parent
adc37fef03
commit
d9c4837f82
|
@ -1,5 +1,6 @@
|
||||||
import { Component } from 'solid-js';
|
import { Component } from 'solid-js';
|
||||||
import cache from '../../lib/cache';
|
import cache from '../../lib/cache';
|
||||||
|
import { peekCachedSignal } from '../../workers/cached-signals';
|
||||||
import Tree from '../tree';
|
import Tree from '../tree';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
@ -7,7 +8,7 @@ interface Props {
|
||||||
}
|
}
|
||||||
|
|
||||||
const GpxViewer: Component<Props> = ({ gpxId }) => {
|
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() });
|
console.log({ caller: 'GpxViewer', gpx: gpx() });
|
||||||
const title = () => {};
|
const title = () => {};
|
||||||
return <Tree title={'gpx'} content={undefined} subTree={undefined} />;
|
return <Tree title={'gpx'} content={undefined} subTree={undefined} />;
|
||||||
|
|
|
@ -61,29 +61,22 @@ export const clickHandler = (event: any) => {
|
||||||
selectedFeatures.map((feature: Feature<Geometry>) => {
|
selectedFeatures.map((feature: Feature<Geometry>) => {
|
||||||
const gpxId = feature.get('context').gpxId;
|
const gpxId = feature.get('context').gpxId;
|
||||||
if (!hierarchy.hasOwnProperty(gpxId)) {
|
if (!hierarchy.hasOwnProperty(gpxId)) {
|
||||||
hierarchy[gpxId] = { gpx: feature.get('context').gpx };
|
hierarchy[gpxId] = { type: 'gpx' };
|
||||||
hierarchy[gpxId].type = 'gpx';
|
|
||||||
}
|
}
|
||||||
const l2key = level2Key(feature);
|
const l2key = level2Key(feature);
|
||||||
if (!hierarchy[gpxId].hasOwnProperty(l2key)) {
|
if (!hierarchy[gpxId].hasOwnProperty(l2key)) {
|
||||||
hierarchy[gpxId][l2key] = {
|
hierarchy[gpxId][l2key] = {};
|
||||||
wpt: feature.get('context').wpt,
|
|
||||||
rte: feature.get('context').rte,
|
|
||||||
trk: feature.get('context').trk,
|
|
||||||
};
|
|
||||||
if (feature.get('type') === 'trkseg') {
|
if (feature.get('type') === 'trkseg') {
|
||||||
hierarchy[gpxId][l2key].type = 'trk';
|
hierarchy[gpxId][l2key].type = 'trk';
|
||||||
} else {
|
} else {
|
||||||
hierarchy[gpxId][l2key].type = feature.get('type');
|
hierarchy[gpxId][l2key].type = feature.get('type');
|
||||||
feature;
|
hierarchy[gpxId][l2key].feature = feature;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (feature.get('type') === 'trkseg') {
|
if (feature.get('type') === 'trkseg') {
|
||||||
const trksegId = feature.get('context').trksegId;
|
const trksegId = feature.get('context').trksegId;
|
||||||
if (!hierarchy[gpxId][l2key].hasOwnProperty(trksegId)) {
|
if (!hierarchy[gpxId][l2key].hasOwnProperty(trksegId)) {
|
||||||
hierarchy[gpxId][l2key][trksegId] = {
|
hierarchy[gpxId][l2key][trksegId] = {
|
||||||
trksegId,
|
|
||||||
trkseg: feature.get('context').trkseg,
|
|
||||||
type: 'trkseg',
|
type: 'trkseg',
|
||||||
feature,
|
feature,
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,6 +30,24 @@ export const createCachedSignal = (params: any) => {
|
||||||
return signal;
|
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) => {
|
export const destroyCachedSignal = (params: any) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
action: 'cancelWatch',
|
action: 'cancelWatch',
|
||||||
|
|
Loading…
Reference in New Issue