mirror of
https://github.com/nasa/openmct.git
synced 2025-02-20 01:16:46 +00:00
[Views] Update representations on mutation (#1312)
* [Core] Log errors from topic Log full error (including stack trace) when catching errors from the topic service. Aids debugging of #1303 (and should aid in future debugging of any similar issues.) * [API] Fix identifier usage in handleMutation To address console errors observed in the context of #1303 * [Views] Listen to mutation Listen for mutation instead of watching modified timestamp; more reliable due to recent API changes. Fixes #1303. * [Views] Update spec for mct-representation ...to reflect changes for #1303
This commit is contained in:
parent
547696d797
commit
9578fb0cd8
@ -67,6 +67,7 @@ define(
|
||||
listener(message);
|
||||
} catch (e) {
|
||||
$log.error(ERROR_PREFIX + e.message);
|
||||
$log.error(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user