From d3d94d67ea1ae974f3c6cd4b6d5540c1bf4ec45b Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 2 Sep 2015 09:11:46 -0700 Subject: [PATCH] [Composition] Use composition.add from LinkService --- .../src/capabilities/CompositionCapability.js | 5 ++--- platform/entanglement/src/services/LinkService.js | 15 ++++++--------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/platform/core/src/capabilities/CompositionCapability.js b/platform/core/src/capabilities/CompositionCapability.js index c96a060986..1bf7f790f1 100644 --- a/platform/core/src/capabilities/CompositionCapability.js +++ b/platform/core/src/capabilities/CompositionCapability.js @@ -63,8 +63,7 @@ define( */ CompositionCapability.prototype.add = function (domainObject, index) { var id = typeof domainObject === 'string' ? - domainObject : domainObject.getId(), - $q = this.$q; + domainObject : domainObject.getId(); function addIdToModel(model) { var composition = model.composition, @@ -73,7 +72,7 @@ define( // If no index has been specified already and the id is already // present, nothing to do. If the id is already at that index, // also nothing to do, so cancel mutation. - if ((isNaN(index) && oldIndex !== -1) || (index === oldIndex) { + if ((isNaN(index) && oldIndex !== -1) || (index === oldIndex)) { return false; } diff --git a/platform/entanglement/src/services/LinkService.js b/platform/entanglement/src/services/LinkService.js index 9fb38dd273..ae02675eeb 100644 --- a/platform/entanglement/src/services/LinkService.js +++ b/platform/entanglement/src/services/LinkService.js @@ -52,10 +52,13 @@ define( "composition", parentCandidate.getCapability('type'), object.getCapability('type') - ); + ) && parentCandidate.hasCapability('composition'); }; LinkService.prototype.perform = function (object, parentObject) { + // Note that this was checked-for explicitly during validate step + var composition = parentObject.getCapability('composition'); + function findChild(children) { var i; for (i = 0; i < children.length; i += 1) { @@ -65,16 +68,10 @@ define( } } - return parentObject.useCapability('mutation', function (model) { - if (model.composition.indexOf(object.getId()) === -1) { - model.composition.push(object.getId()); - } - }).then(function () { + return composition.add(object).then(function () { return parentObject.getCapability('persistence').persist(); }).then(function getObjectWithNewContext() { - return parentObject - .useCapability('composition') - .then(findChild); + return composition.invoke().then(findChild); }); };