dependency-graph icon indicating copy to clipboard operation
dependency-graph copied to clipboard

Expose CheckCycle API

Open Niels-Be opened this issue 6 years ago • 0 comments

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.

  1. First of all it modifies the internal circular property temporary. (not exposed to Typescript)
  2. It does unnecessary work, since the result of overallOrder() is not used.
  3. Relying on exceptions is not clean code.
  4. 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.

Niels-Be avatar Jul 17 '18 14:07 Niels-Be