Skip to content

Commit

Permalink
feat(applet): add null-safety to inspector component data
Browse files Browse the repository at this point in the history
  • Loading branch information
webfansplz committed Jun 19, 2024
1 parent 222da2e commit 382402e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
13 changes: 8 additions & 5 deletions packages/applet/src/modules/components/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,20 @@ function dfs(node: { id: string, children?: { id: string }[] }, path: string[] =
if (node.children?.length === 0)
linkedList.push([...path])
node.children?.forEach((child) => {
dfs(child, path, linkedList)
})
if (Array.isArray(node.children)) {
node.children.forEach((child) => {
dfs(child, path, linkedList)
})
}
path.pop()
return linkedList
}
function flattenTreeNodes(tree: CustomInspectorNode[]) {
const res: CustomInspectorNode[] = []
const find = (treeNode: CustomInspectorNode[]) => {
treeNode.forEach((item) => {
treeNode?.forEach((item) => {
res.push(item)
if (item.children?.length)
find(item.children)
Expand All @@ -61,7 +64,7 @@ function flattenTreeNodes(tree: CustomInspectorNode[]) {
function getNodesByDepth(list: string[][], depth: number) {
const nodes: string[] = []
list.forEach((item) => {
list?.forEach((item) => {
nodes.push(...item.slice(0, depth + 1))
})
return [...new Set(nodes)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,19 @@ function dfs(node: { id: string, children?: { id: string }[] }, path: string[] =
if (node.children?.length === 0)
linkedList.push([...path])
node.children?.forEach((child) => {
dfs(child, path, linkedList)
})
if (Array.isArray(node.children)) {
node.children.forEach((child) => {
dfs(child, path, linkedList)
})
}
path.pop()
return linkedList
}
function getNodesByDepth(list: string[][], depth: number) {
const nodes: string[] = []
list.forEach((item) => {
list?.forEach((item) => {
nodes.push(...item.slice(0, depth + 1))
})
return [...new Set(nodes)]
Expand All @@ -55,7 +58,7 @@ function getNodesByDepth(list: string[][], depth: number) {
function flattenTreeNodes(tree: CustomInspectorNode[]) {
const res: CustomInspectorNode[] = []
const find = (treeNode: CustomInspectorNode[]) => {
treeNode.forEach((item) => {
treeNode?.forEach((item) => {
res.push(item)
if (item.children?.length)
find(item.children)
Expand Down
13 changes: 8 additions & 5 deletions packages/applet/src/modules/pinia/components/store/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,19 @@ function dfs(node: { id: string, children?: { id: string }[] }, path: string[] =
if (node.children?.length === 0)
linkedList.push([...path])
node.children?.forEach((child) => {
dfs(child, path, linkedList)
})
if (Array.isArray(node.children)) {
node.children.forEach((child) => {
dfs(child, path, linkedList)
})
}
path.pop()
return linkedList
}
function getNodesByDepth(list: string[][], depth: number) {
const nodes: string[] = []
list.forEach((item) => {
list?.forEach((item) => {
nodes.push(...item.slice(0, depth + 1))
})
return [...new Set(nodes)]
Expand All @@ -50,7 +53,7 @@ function getNodesByDepth(list: string[][], depth: number) {
function flattenTreeNodes(tree: CustomInspectorNode[]) {
const res: CustomInspectorNode[] = []
const find = (treeNode: CustomInspectorNode[]) => {
treeNode.forEach((item) => {
treeNode?.forEach((item) => {
res.push(item)
if (item.children?.length)
find(item.children)
Expand Down
13 changes: 8 additions & 5 deletions packages/applet/src/modules/router/components/routes/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,19 @@ function dfs(node: { id: string, children?: { id: string }[] }, path: string[] =
if (node.children?.length === 0)
linkedList.push([...path])
node.children?.forEach((child) => {
dfs(child, path, linkedList)
})
if (Array.isArray(node.children)) {
node.children.forEach((child) => {
dfs(child, path, linkedList)
})
}
path.pop()
return linkedList
}
function getNodesByDepth(list: string[][], depth: number) {
const nodes: string[] = []
list.forEach((item) => {
list?.forEach((item) => {
nodes.push(...item.slice(0, depth + 1))
})
return [...new Set(nodes)]
Expand All @@ -50,7 +53,7 @@ function getNodesByDepth(list: string[][], depth: number) {
function flattenTreeNodes(tree: CustomInspectorNode[]) {
const res: CustomInspectorNode[] = []
const find = (treeNode: CustomInspectorNode[]) => {
treeNode.forEach((item) => {
treeNode?.forEach((item) => {
res.push(item)
if (item.children?.length)
find(item.children)
Expand Down

0 comments on commit 382402e

Please sign in to comment.