Implement webworker for save operation + Limit the history size (#29)
All checks were successful
continuous-integration/drone/push Build is passing

- Implement webworker for save operation
- Limit the history size

Reviewed-on: https://git.siklos-chaneru.duckdns.org/Siklos/svg-layout-designer-react/pulls/29
This commit is contained in:
Siklos 2022-08-15 11:52:17 -04:00
parent 5b20e4f2dc
commit 7ff411b988
6 changed files with 64 additions and 18 deletions

25
src/workers/worker.js Normal file
View file

@ -0,0 +1,25 @@
onmessage = (e) => {
const data = JSON.stringify(e.data.editorState, getCircularReplacer(), e.data.spaces);
postMessage(data);
};
const getCircularReplacer = () => {
const seen = new WeakSet();
return (key, value) => {
if (key === 'parent') {
return;
}
if (key === 'SelectedContainer') {
return;
}
if (typeof value === 'object' && value !== null) {
if (seen.has(value)) {
return;
}
seen.add(value);
}
return value;
};
};