mirror of
https://github.com/nasa/openmct.git
synced 2025-05-28 21:24:20 +00:00
[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.
This commit is contained in:
parent
a2eabc1b08
commit
168a805e8e
@ -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);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user