Created
September 12, 2016 20:48
-
-
Save koenbok/5e90e3b95ac4c91c7b72eb9a2348c234 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
interface Node { | |
id: string | |
type: string | |
children: List<Node> | |
} | |
class Tree { | |
// Create and remove (updates root) | |
create(type: string, parent: string|null|Node= null, attributes: any = {}): Node {} | |
remove(node: Node) {} | |
// Getters | |
get(id: string): Node {} | |
getRoot(): Node {} | |
getChildren(node: Node): List<Node> {} | |
getParent(node: Node): Node {} | |
// Setters (updates root) | |
setParent(node: Node, parent: Node|null) {} | |
setAttributes(node: Node, attributes: any) {} | |
setAttribute(node: Node, name: string, value: any) {} | |
// Utilities | |
visitAncestors(node: Node, visitor: (node: Node, stop: () => void) => boolean) Node[] {} | |
visitDescendants(node: Node, visitor: (node: Node, stop: () => void) => boolean) Node[] {} | |
visitSiblings(node: Node, visitor: (node: Node, stop: () => void) => boolean) Node[] {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment