Created
February 21, 2018 14:53
-
-
Save pier-oliviert/7964ac0afbd1a002aeeddef9f04253e8 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 Branch { | |
| constructor(nodes) { | |
| this.branches = [] | |
| this.nodes = [] | |
| _.compact(_.flatten([nodes])).map(node => { | |
| this.insertNode(node) | |
| }) | |
| this.dataset = {} | |
| } | |
| get root() { | |
| return _.first(this.nodes) | |
| } | |
| get leaf() { | |
| return _.last(this.nodes) | |
| } | |
| sliceBefore(node) { | |
| return this.slice(this.nodes.indexOf(node)) | |
| } | |
| sliceAfter(node) { | |
| return this.slice(this.nodes.indexOf(node) + 1) | |
| } | |
| slice(index) { | |
| const nodes = this.nodes.splice(index) | |
| if (nodes.length > 0) { | |
| const branch = new Branch(nodes) | |
| branch.branches = [...this.branches] | |
| this.branches = [branch] | |
| return branch | |
| } | |
| } | |
| insertNode(target) { | |
| } | |
| removeNode(node) { | |
| } | |
| insertBranch(branch) { | |
| } | |
| removeBranch(branch) { | |
| } | |
| get height() { | |
| return this.nodes.length | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment