diff --git a/platform/core/src/services/Topic.js b/platform/core/src/services/Topic.js index 74967a0b5f..2613af467b 100644 --- a/platform/core/src/services/Topic.js +++ b/platform/core/src/services/Topic.js @@ -67,6 +67,7 @@ define( listener(message); } catch (e) { $log.error(ERROR_PREFIX + e.message); + $log.error(e); } }); } diff --git a/platform/representation/src/MCTRepresentation.js b/platform/representation/src/MCTRepresentation.js index 1249440383..93b0a528da 100644 --- a/platform/representation/src/MCTRepresentation.js +++ b/platform/representation/src/MCTRepresentation.js @@ -90,7 +90,7 @@ define( couldRepresent = false, lastIdPath = [], lastKey, - statusListener, + mutationListener, changeTemplate = templateLinker.link($scope, element); // Populate scope with any capabilities indicated by the @@ -101,7 +101,16 @@ define( uses = ((representation || {}).uses || []), myCounter = counter; + if (mutationListener) { + mutationListener(); + mutationListener = undefined; + } + if (domainObject) { + mutationListener = domainObject + .getCapability('mutation') + .listen(refreshCapabilities); + // Update model $scope.model = domainObject.getModel(); @@ -236,17 +245,12 @@ define( // (to a different object) $scope.$watch("domainObject", refresh); - // Finally, also update when there is a new version of that - // same domain object; these changes should be tracked in the - // model's "modified" field, by the mutation capability. - $scope.$watch("domainObject.getModel().modified", refreshCapabilities); - // Make sure any resources allocated by representers also get // released. $scope.$on("$destroy", destroyRepresenters); $scope.$on("$destroy", function () { - if (statusListener) { - statusListener(); + if (mutationListener) { + mutationListener(); } }); diff --git a/platform/representation/test/MCTRepresentationSpec.js b/platform/representation/test/MCTRepresentationSpec.js index 0289764e35..519e0fdb56 100644 --- a/platform/representation/test/MCTRepresentationSpec.js +++ b/platform/representation/test/MCTRepresentationSpec.js @@ -36,7 +36,7 @@ define( testViews, testUrls, mockRepresenters, - mockStatusCapability, + mockMutationCapability, mockQ, mockLinker, mockLog, @@ -119,7 +119,8 @@ define( mockChangeTemplate = jasmine.createSpy('changeTemplate'); mockLog = jasmine.createSpyObj("$log", LOG_FUNCTIONS); - mockStatusCapability = jasmine.createSpyObj("statusCapability", ["listen"]); + mockMutationCapability = + jasmine.createSpyObj("mutation", ["listen"]); mockScope = jasmine.createSpyObj("scope", ["$watch", "$on"]); mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS); @@ -132,7 +133,7 @@ define( }); mockDomainObject.getCapability.andCallFake(function (c) { - return c === 'status' && mockStatusCapability; + return c === 'mutation' && mockMutationCapability; }); mctRepresentation = new MCTRepresentation( @@ -164,10 +165,6 @@ define( "domainObject", jasmine.any(Function) ); - expect(mockScope.$watch).toHaveBeenCalledWith( - "domainObject.getModel().modified", - jasmine.any(Function) - ); }); it("recognizes keys for representations", function () { @@ -272,10 +269,16 @@ define( ); mockDomainObject.getCapability.andCallFake(function (c) { - return c === 'context' && mockContext; + return { + context: mockContext, + mutation: mockMutationCapability + }[c]; }); mockLink.getCapability.andCallFake(function (c) { - return c === 'context' && mockContext2; + return { + context: mockContext2, + mutation: mockMutationCapability + }[c]; }); mockDomainObject.hasCapability.andCallFake(function (c) { return c === 'context'; @@ -299,6 +302,11 @@ define( mockScope.$watch.calls[0].args[1](); }); + it("listens for mutation of that object", function () { + expect(mockMutationCapability.listen) + .toHaveBeenCalledWith(jasmine.any(Function)); + }); + it("detects subsequent changes among linked instances", function () { var callCount = mockChangeTemplate.calls.length; diff --git a/src/api/objects/LegacyObjectAPIInterceptor.js b/src/api/objects/LegacyObjectAPIInterceptor.js index 88758710e4..9eb996ea00 100644 --- a/src/api/objects/LegacyObjectAPIInterceptor.js +++ b/src/api/objects/LegacyObjectAPIInterceptor.js @@ -62,7 +62,7 @@ define([ //Don't trigger self objectEventEmitter.off('mutation', handleMutation); - objectEventEmitter.emit(newStyleObject.key.identifier + ":*", newStyleObject); + objectEventEmitter.emit(newStyleObject.identifier.key + ":*", newStyleObject); objectEventEmitter.on('mutation', handleMutation); }.bind(this);