[Search] Move reindex function
Move function used to listen for mutation changes (to trigger reindexing) up in scope, to avoid retaining references to domain objects via closure. nasa/openmctweb#141 Also, includes misc. whitespace normalization (provided by code editor.)
This commit is contained in:
@@ -113,6 +113,23 @@ define(
|
|||||||
|
|
||||||
// Helper function for getItems(). Indexes the tree.
|
// Helper function for getItems(). Indexes the tree.
|
||||||
function indexItems(nodes) {
|
function indexItems(nodes) {
|
||||||
|
function handleMutation(model) {
|
||||||
|
if (model && model.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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nodes.forEach(function (node) {
|
nodes.forEach(function (node) {
|
||||||
var id = node && node.getId && node.getId();
|
var id = node && node.getId && node.getId();
|
||||||
|
|
||||||
@@ -146,22 +163,7 @@ define(
|
|||||||
|
|
||||||
// Watch for changes to this item, in case it gets new children
|
// Watch for changes to this item, in case it gets new children
|
||||||
if (node && node.hasCapability && node.hasCapability('mutation')) {
|
if (node && node.hasCapability && node.hasCapability('mutation')) {
|
||||||
node.getCapability('mutation').listen(function (listener) {
|
node.getCapability('mutation').listen(handleMutation);
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user