Last active
February 21, 2018 11:45
-
-
Save pier-oliviert/bb0ef2441d5b353db212338d8d89b56b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Linker { | |
| constructor(nodes) { | |
| this.cache = this.create(nodes) | |
| } | |
| process(edges) { | |
| const nodes = this.link(this.findRootEdges(edges)) | |
| Object.freeze(nodes) | |
| Object.defineProperty(this, "nodes", { | |
| value: nodes | |
| }) | |
| } | |
| link(edges) { | |
| return edges.map(edge => { | |
| edge.source = this.cache[edge.source.toString()] | |
| edge.target = this.cache[edge.target.toString()] | |
| this.link(this.findEdgesForSource(edge.target)) | |
| return edge | |
| }) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment