mirror of
https://github.com/nasa/openmct.git
synced 2025-06-06 01:11:41 +00:00
[Composition] Return newly-contextualized object
After adding to composition, return the newly-contextualized object; this is regularly used by other services.
This commit is contained in:
parent
ba6e542d08
commit
b1238b0c96
@ -97,17 +97,7 @@ define(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return parentPersistence.persist().then(function () {
|
return parentPersistence.persist().then(function () {
|
||||||
// Locate and return new Object in context of parent.
|
return result;
|
||||||
return parent
|
|
||||||
.useCapability('composition')
|
|
||||||
.then(function (children) {
|
|
||||||
var i;
|
|
||||||
for (i = 0; i < children.length; i += 1) {
|
|
||||||
if (children[i].getId() === id) {
|
|
||||||
return children[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -59,12 +59,28 @@ define(
|
|||||||
* @param {DomainObject|string} domainObject the domain object to add,
|
* @param {DomainObject|string} domainObject the domain object to add,
|
||||||
* or simply its identifier
|
* or simply its identifier
|
||||||
* @param {number} [index] the index at which to add the object
|
* @param {number} [index] the index at which to add the object
|
||||||
* @returns {Promise.<boolean>} the mutation result
|
* @returns {Promise.<DomainObject>} a promise for the added object
|
||||||
|
* in its new context
|
||||||
*/
|
*/
|
||||||
CompositionCapability.prototype.add = function (domainObject, index) {
|
CompositionCapability.prototype.add = function (domainObject, index) {
|
||||||
var id = typeof domainObject === 'string' ?
|
var self = this,
|
||||||
|
id = typeof domainObject === 'string' ?
|
||||||
domainObject : domainObject.getId();
|
domainObject : domainObject.getId();
|
||||||
|
|
||||||
|
// Find the object with the above id, used to contextualize
|
||||||
|
function findObject(objects) {
|
||||||
|
var i;
|
||||||
|
for (i = 0; i < objects.length; i += 1) {
|
||||||
|
if (objects[i].getId() === id) {
|
||||||
|
return objects[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function contextualize(mutationResult) {
|
||||||
|
return mutationResult && self.invoke().then(findObject);
|
||||||
|
}
|
||||||
|
|
||||||
function addIdToModel(model) {
|
function addIdToModel(model) {
|
||||||
var composition = model.composition,
|
var composition = model.composition,
|
||||||
oldIndex = composition.indexOf(id);
|
oldIndex = composition.indexOf(id);
|
||||||
@ -90,7 +106,8 @@ define(
|
|||||||
model.composition.splice(index, 0, id);
|
model.composition.splice(index, 0, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.domainObject.useCapability('mutation', addIdToModel);
|
return this.domainObject.useCapability('mutation', addIdToModel)
|
||||||
|
.then(contextualize);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,10 +68,10 @@ define(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return composition.add(object).then(function () {
|
return composition.add(object).then(function (result) {
|
||||||
return parentObject.getCapability('persistence').persist();
|
return parentObject.getCapability('persistence')
|
||||||
}).then(function getObjectWithNewContext() {
|
.persist()
|
||||||
return composition.invoke().then(findChild);
|
.then(function () { return result; });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user