Debouncing Map state db persisting

This commit is contained in:
Eric van der Vlist 2022-12-14 08:22:51 +01:00
parent 600ce534fe
commit d1a3e6bf82
1 changed files with 7 additions and 2 deletions

View File

@ -37,7 +37,7 @@ import Infos, { clickHandler } from '../infos';
import GpxDialog from '../gpx-dialog';
import GpxRecord from '../gpx-record';
import dispatch from '../../workers/dispatcher-main';
import { isEqual } from 'lodash';
import { debounce } from 'lodash';
const [getState, setState] = createSignal({
lon: 0,
@ -76,6 +76,11 @@ const Map: Component = () => {
let target: HTMLDivElement;
const debouncedDbSetState = debounce((state: any) => {
console.log({ caller: 'Map / debouncedDbSetState', state });
dispatch({ action: 'setState', params: state });
}, 60000);
createEffect(async () => {
console.log({
caller: 'Map / setState',
@ -90,7 +95,7 @@ const Map: Component = () => {
rotation: +params.rotation,
zoom: +params.zoom,
});
await dispatch({ action: 'setState', params: getState() });
debouncedDbSetState(getState());
const map = getMap();
const layers = map?.getLayers();