diff options
author | Kirill Rogovoy <[email protected]> | 2021-07-29 18:30:44 +0300 |
---|---|---|
committer | Kirill Rogovoy <[email protected]> | 2021-07-29 18:30:44 +0300 |
commit | 5c4ff3d788b9f039aabcb7d7ad43d6ca478ff7e0 (patch) | |
tree | b49471f6ef6a7d532decf20ece3c64e454ac5c25 /pages/index.tsx | |
parent | ad3c2df63a7c7c7cdf82b13cc371bdb3b1a1ccb4 (diff) |
Refactoring: simplify another useMemo
Diffstat (limited to 'pages/index.tsx')
-rw-r--r-- | pages/index.tsx | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/pages/index.tsx b/pages/index.tsx index 18cce7c..d1c9cf2 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -258,9 +258,11 @@ export const Graph = forwardRef(function (props: GraphProps, graphRef: any) { if (behavior.followLocalOrZoom) { setScope({ nodeIds: [emacsNodeId] }) setTimeout(() => { - fg?.zoomToFit(1000, numberWithinRange(20, 200, windowWidth / 8), (node: NodeObject) => - getNeighborNodes(emacsNodeId)[node.id!], - ) + fg?.zoomToFit( + 1000, + numberWithinRange(20, 200, windowWidth / 8), + (node: NodeObject) => getNeighborNodes(emacsNodeId)[node.id!], + ) }, 1) } else { fg?.zoomToFit(1000, 200, (node: NodeObject) => getNeighborNodes(emacsNodeId)[node.id!]) @@ -426,7 +428,7 @@ export const Graph = forwardRef(function (props: GraphProps, graphRef: any) { ) const getColor = (c: any) => (isNaN(c) ? theme.colors[c][500] : theme.colors.gray[c]) - const highlightColors = Object.fromEntries( + return Object.fromEntries( allColors.map((color) => { const color1 = getColor(color) const crisscross = allColors.map((color2) => [ @@ -436,8 +438,6 @@ export const Graph = forwardRef(function (props: GraphProps, graphRef: any) { return [color, Object.fromEntries(crisscross)] }), ) - console.log(highlightColors) - return highlightColors }, [ visuals.nodeColorScheme, visuals.linkHighlight, @@ -445,21 +445,15 @@ export const Graph = forwardRef(function (props: GraphProps, graphRef: any) { visuals.linkColorScheme, ]) - const previouslyHighlightedLinks = useMemo( - () => linksByNodeId[lastHoverNode.current?.id!] ?? [], - [JSON.stringify(hoverNode), lastHoverNode.current], - ) - - const previouslyHighlightedNodes = useMemo( - () => - Object.fromEntries( - [ - lastHoverNode.current?.id! as string, - ...previouslyHighlightedLinks.flatMap((link) => [link.source, link.target]), - ].map((nodeId) => [nodeId, {}]), - ), - [JSON.stringify(hoverNode), previouslyHighlightedLinks, lastHoverNode.current], - ) + const previouslyHighlightedNodes = useMemo(() => { + const previouslyHighlightedLinks = linksByNodeId[lastHoverNode.current?.id!] ?? [] + return Object.fromEntries( + [ + lastHoverNode.current?.id! as string, + ...previouslyHighlightedLinks.flatMap((link) => [link.source, link.target]), + ].map((nodeId) => [nodeId, {}]), + ) + }, [JSON.stringify(hoverNode), lastHoverNode.current]) const getNodeColorById = (id: string) => { const linklen = linksByNodeId[id!]?.length ?? 0 |