From bd64c785b0d98246ca77f55516de844eb6858f43 Mon Sep 17 00:00:00 2001 From: codetypes Date: Fri, 19 Jul 2024 13:27:28 +0800 Subject: [PATCH] optimize check children count --- src/misc/b3util.ts | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/misc/b3util.ts b/src/misc/b3util.ts index fb0fc20..15ed6c2 100644 --- a/src/misc/b3util.ts +++ b/src/misc/b3util.ts @@ -73,13 +73,13 @@ export const checkNodeData = (data: NodeModel | null | undefined) => { } let hasError = false; const conf = useWorkspace.getState().getNodeDef(data.name); - if (conf.children !== undefined) { - if (conf.children == 0 && data.children?.length) { + if (conf.children !== undefined && conf.children != -1) { + const count = data.children?.length || 0; + if (conf.children !== count) { hasError = true; - console.error(`check ${data.id}|${data.name}: no children is required`); - } else if (conf.children == 1 && data.children?.length !== 1) { - hasError = true; - console.error(`check ${data.id}|${data.name}: only one child is required`); + console.error( + `check ${data.id}|${data.name}: expect ${conf.children} children, but got ${count}` + ); } } if (conf.input) { @@ -341,12 +341,8 @@ export const calcTreeDataSize = (data: TreeGraphData) => { export const checkChildrenLimit = (data: TreeGraphData) => { const conf = data.def; - if (conf.children !== undefined) { - if (conf.children == 0 && data.children?.length) { - return false; - } else if (conf.children == 1 && data.children?.length !== 1) { - return false; - } + if (conf.children !== undefined && conf.children != -1) { + return (data.children?.length || 0) === conf.children; } return true; };