Skip to content
This repository was archived by the owner on Mar 16, 2021. It is now read-only.

Commit

Permalink
[feat] add function to return the children of a node
Browse files Browse the repository at this point in the history
  • Loading branch information
cedoor committed Aug 14, 2018
1 parent afea4d5 commit b0a2209
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/map/handlers/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,29 @@ export default class Nodes {
}
};

/**
* Return the children of the node.
* @param {string} id
* @returns {ExportNodeProperties[]}
*/
public nodeChildren = (id?: string): ExportNodeProperties[] => {
if (id && typeof id !== "string") {
Log.error("The node id must be a string", "type");
}

let node: Node = id ? this.getNode(id) : this.selectedNode;

if (node === undefined) {
Log.error("There are no nodes with id \"" + id + "\"");
}

return this.nodes.values().filter((n: Node) => {
return n.parent && n.parent.id === node.id;
}).map((n: Node) => {
return this.getNodeProperties(n);
});
};

/**
* Return the export properties of the node.
* @param {Node} node
Expand Down
2 changes: 2 additions & 0 deletions src/map/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export default class Map {
addNode: this.nodes.addNode,
selectNode: this.nodes.selectNode,
deselectNode: this.nodes.deselectNode,
nodeChildren: this.nodes.nodeChildren,
updateNode: this.nodes.updateNode,
removeNode: this.nodes.removeNode,
copyNode: this.copyPaste.copy,
Expand All @@ -127,6 +128,7 @@ export interface MmpInstance {
addNode: Function;
selectNode: Function;
deselectNode: Function;
nodeChildren: Function;
updateNode: Function;
removeNode: Function;
copyNode: Function;
Expand Down

0 comments on commit b0a2209

Please # to comment.