Last active
February 21, 2018 12:14
-
-
Save pier-oliviert/442e96083bcfadcd9367de8a56e0ba4f to your computer and use it in GitHub Desktop.
This file contains 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, edges) { | |
this.cache = new Cache(nodes, edges) | |
} | |
process(edges) { | |
const nodes = this.link(this.findRootEdges(edges)) | |
Object.defineProperty(this, "nodes", { | |
value: Object.freeze(nodes) | |
}) | |
} | |
link(edges) { | |
return edges.map(edge => { | |
edge.source = this.cache.node(edge.source.toString()) | |
edge.target = this.cache.node(edge.target.toString()) | |
this.link(this.cache.edgeFromSource(edge.target.id.toString())) | |
return edge | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment