Debouncing updates from the worker to the main thread (this was crashing the app during heavy syncs).
This commit is contained in:
parent
4b55763a03
commit
91916fca88
|
@ -1,4 +1,4 @@
|
|||
import { slice } from 'lodash';
|
||||
import { debounce, slice } from 'lodash';
|
||||
import { getWpt } from '../db/wpt';
|
||||
import { returnAgain } from '../workers/dispatcher-worker';
|
||||
import { getAllGpxes, getGpx } from './gpx';
|
||||
|
@ -31,6 +31,15 @@ const sendUpdate = async (params: any) => {
|
|||
}
|
||||
};
|
||||
|
||||
let debouncedSendUpdates = <any>{};
|
||||
|
||||
for (const property in methods) {
|
||||
debouncedSendUpdates[<keyof typeof debouncedSendUpdates>property] = debounce(
|
||||
sendUpdate,
|
||||
500
|
||||
);
|
||||
}
|
||||
|
||||
const changeHandler = async (change: any) => {
|
||||
console.log({ caller: 'ChangeHandler', change, watches: globalThis.watches });
|
||||
const { id } = change;
|
||||
|
@ -69,7 +78,8 @@ const changeHandler = async (change: any) => {
|
|||
}
|
||||
}
|
||||
|
||||
sendUpdate(globalThis.watches.get(parentId));
|
||||
const parentParams = globalThis.watches.get(parentId);
|
||||
debouncedSendUpdates[parentParams.method](parentParams);
|
||||
};
|
||||
|
||||
export default changeHandler;
|
||||
|
|
Loading…
Reference in New Issue