svg-layout-designer-react/src/workers/worker.js
Siklos 7ff411b988
All checks were successful
continuous-integration/drone/push Build is passing
Implement webworker for save operation + Limit the history size (#29)
- Implement webworker for save operation
- Limit the history size

Reviewed-on: https://git.siklos-chaneru.duckdns.org/Siklos/svg-layout-designer-react/pulls/29
2022-08-15 11:52:17 -04:00

25 lines
500 B
JavaScript

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;
};
};