jriecken / dependency-graph

A simple dependency graph for Node.js
http://jriecken.github.io/dependency-graph/
MIT License
330 stars 49 forks source link

Overall order based on a single node #22

Closed gakimball closed 6 years ago

gakimball commented 6 years ago

I love this library! I was really happy to search for a specific problem on npm and then find the solution.

I'm mostly using it for the overallOrder() method, to get the proper order to execute a series of tasks in order to satisfy dependencies.

I'm now wondering if there's a way to get an order output based on a single node. Let's say I have a simple dependency graph like this:

So if you call overallOrder(), you'd get ['one', 'two', 'three']. What I'd also like to do is calculate an order given a single node as a baseline. So the order based just on two would be ['two', 'three']. Obviously two is first because it's the baseline, and then its dependents are positioned after. The order based on three would just be ['three'] because the node three has no dependents.

I don't see anything in the existing API that could accomplish this, so I'm wondering if you can think of a workaround. Unless I'm missing something! Thanks for your time :)

gakimball commented 6 years ago

Wow, apparently I didn't look close enough! I think this is what dependantsOf() is for.