Skip to content

Commit

Permalink
Add 'child.getByIdDeep'.
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewWid committed Apr 12, 2019
1 parent d8f3100 commit c44e75e
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/systems/child/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ module.exports = (_game, _obj) => {
getAll: () => {
return _obj.children;
},
// getByIdDeep: (query, curr = _obj) => {
// if (query === curr._id) {
// return curr;
// }
// for (let i = 0, n = curr.children.length; i < n; i++) {
// if (curr.child.getByIdDeep(query, curr.children[i]) !== false) {
// return curr;
// }
// }
// },
// Get all children, including children of children, with recursion
getByIdDeep: (query, curr = _obj) => {
if (query === curr._id) {
return curr;
}
for (let i = 0, n = curr.children.length; i < n; i++) {
const result = _obj.child.getByIdDeep(query, curr.children[i]);

if (result !== false) {
return result;
}
}
return false;
},
// TODO:
// Add an accumulator object for accumulating values on each level of children
getAllDeep: (returnedChildren = []) => {
Expand Down

0 comments on commit c44e75e

Please sign in to comment.