[Composition] Use composition.add from LinkService

This commit is contained in:
Victor Woeltjen
2015-09-02 09:11:46 -07:00
parent b9d8b124ff
commit d3d94d67ea
2 changed files with 8 additions and 12 deletions

View File

@ -63,8 +63,7 @@ define(
*/ */
CompositionCapability.prototype.add = function (domainObject, index) { CompositionCapability.prototype.add = function (domainObject, index) {
var id = typeof domainObject === 'string' ? var id = typeof domainObject === 'string' ?
domainObject : domainObject.getId(), domainObject : domainObject.getId();
$q = this.$q;
function addIdToModel(model) { function addIdToModel(model) {
var composition = model.composition, var composition = model.composition,
@ -73,7 +72,7 @@ define(
// If no index has been specified already and the id is already // If no index has been specified already and the id is already
// present, nothing to do. If the id is already at that index, // present, nothing to do. If the id is already at that index,
// also nothing to do, so cancel mutation. // also nothing to do, so cancel mutation.
if ((isNaN(index) && oldIndex !== -1) || (index === oldIndex) { if ((isNaN(index) && oldIndex !== -1) || (index === oldIndex)) {
return false; return false;
} }

View File

@ -52,10 +52,13 @@ define(
"composition", "composition",
parentCandidate.getCapability('type'), parentCandidate.getCapability('type'),
object.getCapability('type') object.getCapability('type')
); ) && parentCandidate.hasCapability('composition');
}; };
LinkService.prototype.perform = function (object, parentObject) { LinkService.prototype.perform = function (object, parentObject) {
// Note that this was checked-for explicitly during validate step
var composition = parentObject.getCapability('composition');
function findChild(children) { function findChild(children) {
var i; var i;
for (i = 0; i < children.length; i += 1) { for (i = 0; i < children.length; i += 1) {
@ -65,16 +68,10 @@ define(
} }
} }
return parentObject.useCapability('mutation', function (model) { return composition.add(object).then(function () {
if (model.composition.indexOf(object.getId()) === -1) {
model.composition.push(object.getId());
}
}).then(function () {
return parentObject.getCapability('persistence').persist(); return parentObject.getCapability('persistence').persist();
}).then(function getObjectWithNewContext() { }).then(function getObjectWithNewContext() {
return parentObject return composition.invoke().then(findChild);
.useCapability('composition')
.then(findChild);
}); });
}; };