svg-layout-designer-react/src/workers/worker.js
Siklos 991683fd7e
All checks were successful
continuous-integration/drone/push Build is passing
Add Web Worker for the save to json function
2022-08-15 16:56:32 +02: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;
};
};