-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve performance by using stack instead of recursion
- Loading branch information
1 parent
2fbb611
commit 8b5abbe
Showing
8 changed files
with
62 additions
and
123 deletions.
There are no files selected for viewing
5 changes: 3 additions & 2 deletions
5
packages/fdr-sdk/src/navigation/versions/v1/NavigationNodeLeaf.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
import { LinkNode } from "."; | ||
import type { NavigationNode } from "./NavigationNode"; | ||
import { isApiLeaf, type NavigationNodeApiLeaf } from "./NavigationNodeApiLeaf"; | ||
import { isMarkdownLeaf, type NavigationNodeMarkdownLeaf } from "./NavigationNodePageLeaf"; | ||
|
||
/** | ||
* A navigation node that represents a leaf in the navigation tree (i.e. a node that does not have children) | ||
*/ | ||
export type NavigationNodeLeaf = NavigationNodeApiLeaf | NavigationNodeMarkdownLeaf; | ||
export type NavigationNodeLeaf = NavigationNodeApiLeaf | NavigationNodeMarkdownLeaf | LinkNode; | ||
|
||
export function isLeaf(node: NavigationNode): node is NavigationNodeLeaf { | ||
return isApiLeaf(node) || isMarkdownLeaf(node); | ||
return isApiLeaf(node) || isMarkdownLeaf(node) || node.type === "link"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/fdr-sdk/src/navigation/versions/v1/getChildren.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { UnreachableCaseError } from "ts-essentials"; | ||
import { NavigationNode } from "./NavigationNode"; | ||
import { isLeaf } from "./NavigationNodeLeaf"; | ||
|
||
export function getChildren(node: NavigationNode): readonly NavigationNode[] { | ||
if (isLeaf(node)) { | ||
return []; | ||
} | ||
|
||
switch (node.type) { | ||
case "apiPackage": | ||
case "changelog": | ||
case "changelogMonth": | ||
case "changelogYear": | ||
case "section": | ||
case "sidebarGroup": | ||
case "sidebarRoot": | ||
case "tabbed": | ||
case "versioned": | ||
return node.children; | ||
case "product": | ||
case "root": | ||
case "tab": | ||
return [node.child]; | ||
case "apiReference": | ||
return [...node.children, ...(node.changelog ? [node.changelog] : [])]; | ||
case "endpointPair": | ||
return [node.nonStream, node.stream]; | ||
case "productgroup": | ||
return [...(node.landingPage ? [node.landingPage] : []), ...node.children]; | ||
case "unversioned": | ||
case "version": | ||
return [...(node.landingPage ? [node.landingPage] : []), node.child]; | ||
default: | ||
throw new UnreachableCaseError(node); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { dfs } from "../../../utils/traversers/dfs"; | ||
import { TraverserVisit } from "../../../utils/traversers/types"; | ||
import { NavigationNode } from "./NavigationNode"; | ||
import { getChildren } from "./getChildren"; | ||
|
||
export function traverseDF(node: NavigationNode, visit: TraverserVisit<NavigationNode>): void { | ||
return dfs(node, visit, getChildren); | ||
} |
107 changes: 0 additions & 107 deletions
107
packages/fdr-sdk/src/navigation/versions/v1/traverseNavigation.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters