MCPcopy Create free account
hub / github.com/DTStack/Taier / visit

Function visit

taier-ui/src/utils/index.ts:673–695  ·  view source on GitHub ↗
(
    obj: T,
    filter: (item: P) => boolean,
    handler: (item: P, vNode: { formName: string[] }) => void
)

Source from the content-addressed store, hash-verified

671 * ```
672 */
673export function visit<T extends { children: P[]; [key: string]: any }, P extends { type: string; [key: string]: any }>(
674 obj: T,
675 filter: (item: P) => boolean,
676 handler: (item: P, vNode: { formName: string[] }) => void
677) {
678 const stack = [...obj.children.map((child) => ({ node: child, vNode: { formName: [child.name] } }))];
679 while (stack.length) {
680 const item = stack.pop()!;
681 const isVisit = filter(item.node);
682 if (isVisit) {
683 handler(item.node, item.vNode);
684 }
685
686 if (item.node.type === 'object' && item.node.children.length) {
687 stack.push(
688 ...item.node.children.map((child: any) => ({
689 node: child,
690 vNode: { formName: [...item.vNode.formName, child.name] },
691 }))
692 );
693 }
694 }
695}
696
697/**
698 * 过滤掉对象中的 `undefined` 和 `null` 的值

Callers 2

handlerFunction · 0.90
index.test.tsxFile · 0.85

Calls 2

handlerFunction · 0.50
mapMethod · 0.45

Tested by

no test coverage detected