Skip to content

Instantly share code, notes, and snippets.

@pier-oliviert
Last active February 21, 2018 11:45
Show Gist options
  • Select an option

  • Save pier-oliviert/bb0ef2441d5b353db212338d8d89b56b to your computer and use it in GitHub Desktop.

Select an option

Save pier-oliviert/bb0ef2441d5b353db212338d8d89b56b to your computer and use it in GitHub Desktop.
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