| 158 | if ($[4] !== isExpanded || $[5] !== nodes) { |
| 159 | result = []; |
| 160 | function traverse(node, depth, parentId) { |
| 161 | const hasChildren = !!node.children && node.children.length > 0; |
| 162 | const nodeIsExpanded = isExpanded(node.id); |
| 163 | result.push({ |
| 164 | node, |
| 165 | depth, |
| 166 | isExpanded: nodeIsExpanded, |
| 167 | hasChildren, |
| 168 | parentId |
| 169 | }); |
| 170 | if (hasChildren && nodeIsExpanded && node.children) { |
| 171 | for (const child of node.children) { |
| 172 | traverse(child, depth + 1, node.id); |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | for (const node_0 of nodes) { |
| 177 | traverse(node_0, 0); |
| 178 | } |