Skip to content

Commit 18617ad

Browse files
committed
fix: turn shouldFollow arguments into a single object argument
1 parent 874971c commit 18617ad

6 files changed

Lines changed: 15 additions & 14 deletions

File tree

src/algorithms/depthFirstSearch/depthFirstSearch.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('depthFirstSearch', () => {
1212
graph.addEdge('b', 'e', undefined, { type: 'foo' });
1313

1414
const nodes = depthFirstSearch(graph, {
15-
shouldFollow: (source, target, graph) =>
15+
shouldFollow: ({ source, target, graph }) =>
1616
graph.getEdgeProperties(source, target).type === 'foo',
1717
});
1818

src/algorithms/depthFirstSearch/depthFirstVisit.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export function depthFirstVisit<Node, LinkProps>(
2222
visiting.add(node);
2323

2424
graph.adjacent(node)?.forEach((n) => {
25-
const follow = shouldFollow === undefined || shouldFollow(node, n, graph);
25+
const follow =
26+
shouldFollow === undefined || shouldFollow({ source: node, target: n, graph });
2627
if (!follow) return;
2728

2829
depthFirstVisit(graph, nodeList, visited, visiting, n, opts);

src/algorithms/depthFirstSearch/types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ export type DepthFirstSearchOptions<Node, LinkProps> = {
2727
* @param graph the graph instance being explored
2828
* @returns boolean
2929
*/
30-
shouldFollow?: (
31-
source: NoInfer<Node>,
32-
target: NoInfer<Node>,
33-
graph: Graph<Node, LinkProps>,
34-
) => boolean;
30+
shouldFollow?: (args: {
31+
source: NoInfer<Node>;
32+
target: NoInfer<Node>;
33+
graph: Graph<Node, LinkProps>;
34+
}) => boolean;
3535
};

src/algorithms/topologicalSort/topologicalSort.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe('topologicalSort', () => {
8181
const sorted = topologicalSort(graph, {
8282
sourceNodes: ['a'],
8383
includeSourceNodes: true,
84-
shouldFollow: (source, target) =>
84+
shouldFollow: ({ source, target }) =>
8585
graph.getEdgeProperties(source, target).type === 'foo',
8686
});
8787

src/algorithms/topologicalSort/topologicalSort.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ export type TopologicalSortOptions<Node, LinkProps> = {
2828
* @param graph the graph instance being explored
2929
* @returns boolean
3030
*/
31-
shouldFollow?: (
32-
source: NoInfer<Node>,
33-
target: NoInfer<Node>,
34-
graph: Graph<Node, LinkProps>,
35-
) => boolean;
31+
shouldFollow?: (args: {
32+
source: NoInfer<Node>;
33+
target: NoInfer<Node>;
34+
graph: Graph<Node, LinkProps>;
35+
}) => boolean;
3636
};
3737

3838
export function topologicalSort<Node, LinkProps>(

src/utils/hasCycle.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('hasCycle', () => {
5252

5353
expect(
5454
hasCycle(graph, {
55-
shouldFollow: (source, target) =>
55+
shouldFollow: ({ source, target }) =>
5656
graph.getEdgeProperties(source, target) === 'foo',
5757
}),
5858
).toBe(false);

0 commit comments

Comments
 (0)