Skip to content

Instantly share code, notes, and snippets.

@koenbok
Created September 12, 2016 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koenbok/5e90e3b95ac4c91c7b72eb9a2348c234 to your computer and use it in GitHub Desktop.
Save koenbok/5e90e3b95ac4c91c7b72eb9a2348c234 to your computer and use it in GitHub Desktop.
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