fix: 修复重连后多画布空白
parent
faaaf2d5bb
commit
40bc22f6e8
@ -0,0 +1,48 @@
|
||||
function hasObjectValues(value) {
|
||||
return Boolean(value && typeof value === 'object' && Object.keys(value).length > 0);
|
||||
}
|
||||
|
||||
function hasInitialCanvasData(initialData, useDefault) {
|
||||
if (!initialData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Array.isArray(initialData)) {
|
||||
return initialData.length > 0;
|
||||
}
|
||||
|
||||
if (useDefault) {
|
||||
return hasObjectValues(initialData?.main?.components) || hasObjectValues(initialData?.components);
|
||||
}
|
||||
|
||||
return hasObjectValues(initialData);
|
||||
}
|
||||
|
||||
function hasCanvasContent(canvas) {
|
||||
return Boolean(
|
||||
canvas &&
|
||||
((Array.isArray(canvas.nodes) && canvas.nodes.length > 0) ||
|
||||
(Array.isArray(canvas.edges) && canvas.edges.length > 0))
|
||||
);
|
||||
}
|
||||
|
||||
function shouldUseCachedCanvas({ cachedCanvas, initialData, useDefault }) {
|
||||
if (!cachedCanvas) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hasCanvasContent(cachedCanvas)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return !hasInitialCanvasData(initialData, useDefault);
|
||||
}
|
||||
|
||||
function shouldPersistCanvas({ nodes, edges }) {
|
||||
return hasCanvasContent({ nodes, edges });
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
shouldUseCachedCanvas,
|
||||
shouldPersistCanvas,
|
||||
};
|
||||
Loading…
Reference in New Issue