dependency-graph
dependency-graph copied to clipboard
Expose CheckCycle API
Hello,
In my use case I construct a graph to validate a user input. When the input changes I modify the graph accordingly. One of the validations is to check for cycles in the graph.
My current solutions is:
function checkCycle() {
this.graph.circular = false;
let res = null;
try {
this.graph.overallOrder();
} catch(e) {
res = e.message;
}
this.graph.circular = true;
return res;
}
But I this is bad in multiple ways.
- First of all it modifies the internal circular property temporary. (not exposed to Typescript)
- It does unnecessary work, since the result of
overallOrder()
is not used. - Relying on exceptions is not clean code.
- This might suppress other errors.
In my opinion checking for cycles is a general use case and it would be nice if the library can expose it as a function.