Skip to content

Commit

Permalink
refactor: rename vars && cleaner loop in invertGraph
Browse files Browse the repository at this point in the history
The invertGraph function in findEntryPoints should be easier to read.

A var was named 'k' so I renamed it to 'filePath' which is easier to
understand
  • Loading branch information
AnatoleLucet committed May 23, 2020
1 parent 16fc061 commit 27254ec
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/index/generateTrees/findEntryPoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { isTestFile } from "./shared/isTestFile";

const invertGraph = (graph: Graph) => {
const invertedGraph: Graph = {};
Object.keys(graph).forEach(k => {
graph[k].forEach(v => {
if (!(v in invertedGraph)) {
invertedGraph[v] = [];
Object.entries(graph).forEach(([filePath, imports]) => {
imports.forEach(importPath => {
if (!(importPath in invertedGraph)) {
invertedGraph[importPath] = [];
}

invertedGraph[v].push(k);
invertedGraph[importPath].push(filePath);
});
});

Expand All @@ -34,14 +34,14 @@ export function findEntryPoints(graph: Graph) {

const levelMap: Record<number, string[]> = {};

possibleEntryPoints.forEach(k => {
const n = k.split("/").length;
possibleEntryPoints.forEach(filePath => {
const n = filePath.split("/").length;

if (!(n in levelMap)) {
levelMap[n] = [];
}

levelMap[n].push(k);
levelMap[n].push(filePath);
});

for (let i = 1; i < 10; i++) {
Expand Down

0 comments on commit 27254ec

Please sign in to comment.