react-obsidian
Version:
Dependency injection framework for React and React Native applications
31 lines (25 loc) • 786 B
text/typescript
export class VisitedNodes {
private visitedNodes = new Set<`${string}.${string}`>();
private visitPath: string[] = [];
public visit(graphName: string, dependencyName: string): boolean {
this.visitPath.push(dependencyName);
if (this.canVisit(graphName, dependencyName)) {
this.visitedNodes.add(`${graphName}.${dependencyName}`);
return true;
}
return false;
}
public canVisit(graphName: string, dependencyName: string) {
return !this.visitedNodes.has(`${graphName}.${dependencyName}`);
}
public isCircularPath(): boolean {
return this.visitedNodes.size < this.visitPath.length;
}
public getNodes(): string[] {
return this.visitPath;
}
public clear() {
this.visitedNodes.clear();
this.visitPath.length = 0;
}
}