Skip to content

Instantly share code, notes, and snippets.

@pier-oliviert
Last active February 21, 2018 12:14
Show Gist options
  • Save pier-oliviert/442e96083bcfadcd9367de8a56e0ba4f to your computer and use it in GitHub Desktop.
Save pier-oliviert/442e96083bcfadcd9367de8a56e0ba4f to your computer and use it in GitHub Desktop.
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