From e729a966c74c77951bfb22b6cb918102a6414674 Mon Sep 17 00:00:00 2001 From: slhale Date: Thu, 6 Aug 2015 10:12:34 -0700 Subject: [PATCH] [Search] Type checking Added type checking for arrays to indexItems. --- .../src/services/GenericSearchProvider.js | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/platform/search/src/services/GenericSearchProvider.js b/platform/search/src/services/GenericSearchProvider.js index f5fd54e094..3d8ac39251 100644 --- a/platform/search/src/services/GenericSearchProvider.js +++ b/platform/search/src/services/GenericSearchProvider.js @@ -122,20 +122,23 @@ define( // Helper function for getItems(). Indexes the tree. function indexItems(nodes) { - var i; - - for (i = 0; i < nodes.length; i += 1) { + console.log('nodes', nodes); + nodes.forEach(function (node) { // Index each item with the web worker - indexItem(nodes[i]); + indexItem(node); - if (nodes[i].hasCapability('composition')) { + if (node.hasCapability('composition')) { // This node has children - nodes[i].getCapability('composition').invoke().then(function (children) { - // Index the children - indexItems(children); + node.getCapability('composition').invoke().then(function (children) { + // Index the children + if (children.constructor === Array) { + indexItems(children); + } else { + indexItems([children]); + } }); } - } + }); } // Converts the filetree into a list