mirror of
https://github.com/nasa/openmct.git
synced 2025-01-31 16:36:13 +00:00
[Representation] Minimize scope reuse
When switching among domain objects and/or views, avoid reusing the same information is scope. The wrong information in scope can cause various failures in views, such as WTD-1182.
This commit is contained in:
parent
f74199e60f
commit
9b6d8cf1ec
@ -69,6 +69,9 @@ define(
|
||||
function lookupPanels(ids) {
|
||||
var configuration = $scope.configuration || {};
|
||||
|
||||
// Ensure ids is array-like
|
||||
ids = ids || [];
|
||||
|
||||
// Pull panel positions from configuration
|
||||
rawPositions = shallowCopy(configuration.panels || {}, ids);
|
||||
|
||||
|
@ -72,15 +72,18 @@ define(
|
||||
|
||||
function link($scope, element, attrs) {
|
||||
var activeRepresenters = representers.map(function (Representer) {
|
||||
return new Representer($scope, element, attrs);
|
||||
});
|
||||
return new Representer($scope, element, attrs);
|
||||
}),
|
||||
toClear = [], // Properties to clear out of scope on change
|
||||
counter = 0;
|
||||
|
||||
// Populate scope with any capabilities indicated by the
|
||||
// representation's extension definition
|
||||
function refreshCapabilities() {
|
||||
var domainObject = $scope.domainObject,
|
||||
representation = lookup($scope.key, domainObject),
|
||||
uses = ((representation || {}).uses || []);
|
||||
uses = ((representation || {}).uses || []),
|
||||
myCounter = counter;
|
||||
|
||||
if (domainObject) {
|
||||
// Update model
|
||||
@ -94,10 +97,16 @@ define(
|
||||
" for representation ",
|
||||
$scope.key
|
||||
].join(""));
|
||||
|
||||
$q.when(
|
||||
domainObject.useCapability(used)
|
||||
).then(function (c) {
|
||||
$scope[used] = c;
|
||||
// Avoid clobbering capabilities from
|
||||
// subsequent representations;
|
||||
// Angular reuses scopes.
|
||||
if (counter === myCounter) {
|
||||
$scope[used] = c;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -109,8 +118,7 @@ define(
|
||||
function refresh() {
|
||||
var domainObject = $scope.domainObject,
|
||||
representation = lookup($scope.key, domainObject),
|
||||
uses = ((representation || {}).uses || []),
|
||||
gestureKeys = ((representation || {}).gestures || []);
|
||||
uses = ((representation || {}).uses || []);
|
||||
|
||||
// Create an empty object named "representation", for this
|
||||
// representation to store local variables into.
|
||||
@ -131,9 +139,19 @@ define(
|
||||
$log.warn("No representation found for " + $scope.key);
|
||||
}
|
||||
|
||||
// Clear out the scope from the last representation
|
||||
toClear.forEach(function (property) {
|
||||
delete $scope[property];
|
||||
});
|
||||
|
||||
// Populate scope with fields associated with the current
|
||||
// domain object (if one has been passed in)
|
||||
if (domainObject) {
|
||||
// Track how many representations we've made in this scope,
|
||||
// to ensure that the correct representations are matched to
|
||||
// the correct object/key pairs.
|
||||
counter += 1;
|
||||
|
||||
// Initialize any capabilities
|
||||
refreshCapabilities();
|
||||
|
||||
@ -147,6 +165,10 @@ define(
|
||||
activeRepresenters.forEach(function (representer) {
|
||||
representer.represent(representation, domainObject);
|
||||
});
|
||||
|
||||
// Track which properties we want to clear from scope
|
||||
// next change object/key pair changes
|
||||
toClear = uses.concat(['model']);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user