Skip to content

Commit

Permalink
Renamed getChildNodes and hasChildNodes to getChildren and hasChildre…
Browse files Browse the repository at this point in the history
…n, respectively
  • Loading branch information
cheton committed Apr 3, 2016
1 parent 5d117b7 commit 2d41960
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
24 changes: 12 additions & 12 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,11 @@ class Node {

this.children = this.children || [];
}
// Gets the parent node.
// @return {object} The parent node.
getParent() {
return this.parent;
}
// Gets the child nodes.
// @return {array} An array of child nodes.
getChildNodes() {
// @return {array} Returns an array of child nodes.
getChildren() {
return this.children;
}
// Checks if this node has children.
// @return {boolean} true if the node has child nodes; otherwise, false.
hasChildNodes() {
return this.children.length > 0;
}
// Gets the first child node.
// @return {object} Returns the first child node on success, null otherwise.
getFirstChild() {
Expand All @@ -48,6 +38,11 @@ class Node {
}
return node;
}
// Gets the parent node.
// @return {object} Returns the parent node.
getParent() {
return this.parent;
}
// Gets previous sibling node.
// @return {object} Returns the previous sibling node on success, null otherwise.
getPreviousSibling() {
Expand All @@ -60,6 +55,11 @@ class Node {
}
return node;
}
// Checks whether this node has children.
// @return {boolean} Returns true if the node has children, false otherwise.
hasChildren() {
return this.children.length > 0;
}
}

// IE8 compatibility output
Expand Down
18 changes: 9 additions & 9 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,15 +614,15 @@ test('[node] getChildren/getParent/getFirstChild/getPreviousSibling/getNextSibli
const alpha = _.find(nodes, node => node.id === 'alpha');
const bravo = _.find(nodes, node => node.id === 'bravo');

// hasChildNodes
t.same(root.hasChildNodes(), true);
t.same(alpha.hasChildNodes(), false);
t.same(bravo.hasChildNodes(), true);

// getChildNodes
t.same(root.getChildNodes().length, 2);
t.same(root.getChildNodes()[0], alpha);
t.same(root.getChildNodes()[1], bravo);
// hasChildren
t.same(root.hasChildren(), true);
t.same(alpha.hasChildren(), false);
t.same(bravo.hasChildren(), true);

// getChildren
t.same(root.getChildren().length, 2);
t.same(root.getChildren()[0], alpha);
t.same(root.getChildren()[1], bravo);

// getParent
t.same(alpha.getParent(), root);
Expand Down

0 comments on commit 2d41960

Please sign in to comment.