From ee2d7efae2d4d46a6d22be7951b374b55bf42a91 Mon Sep 17 00:00:00 2001 From: slhale Date: Thu, 6 Aug 2015 15:01:17 -0700 Subject: [PATCH] [Search] Index checks for changes When indexing items initially, the generic provider listens for mutations in case an item's composition changes, so it can then index the new children. --- .../src/services/GenericSearchProvider.js | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/platform/search/src/services/GenericSearchProvider.js b/platform/search/src/services/GenericSearchProvider.js index 5c1b724c2b..068f304321 100644 --- a/platform/search/src/services/GenericSearchProvider.js +++ b/platform/search/src/services/GenericSearchProvider.js @@ -124,14 +124,15 @@ define( // Helper function for getItems(). Indexes the tree. function indexItems(nodes) { nodes.forEach(function (node) { - var id = node.getId(); + var id = node && node.getId && node.getId(); + // If we have not yet indexed this item, index it if (!indexed[id]) { // Index each item with the web worker indexItem(node); indexed[id] = true; - - if (node.hasCapability('composition')) { + + if (node.hasCapability && node.hasCapability('composition')) { // This node has children node.getCapability('composition').invoke().then(function (children) { // Index the children @@ -143,6 +144,26 @@ define( }); } } + + // Watch for changes to this item, in case it gets new children + if (node && node.hasCapability && node.hasCapability('mutation')) { + node.getCapability('mutation').listen(function (listener) { + if (listener && listener.composition) { + // If the node was mutated to have children, get the child domain objects + objectService.getObjects(listener.composition).then(function (objectsById) { + var objects = [], + id; + + // Get each of the domain objects in objectsById + for (id in objectsById) { + objects.push(objectsById[id]); + } + + indexItems(objects); + }); + } + }); + } }); }