mirror of
https://github.com/nasa/openmct.git
synced 2025-02-12 13:45:52 +00:00
[Representation] Verify change before representing
An mct-representation may have a refresh triggered either by a key change or a domain object change; both will typically happen in the same digest cycle. Track what prior state was an abort refreshes if nothing will change.
This commit is contained in:
parent
04594ea536
commit
560454e7c2
@ -31,7 +31,6 @@ define(
|
|||||||
function () {
|
function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the mct-representation directive. This may be used to
|
* Defines the mct-representation directive. This may be used to
|
||||||
* present domain objects as HTML (with event wiring), with the
|
* present domain objects as HTML (with event wiring), with the
|
||||||
@ -96,6 +95,9 @@ define(
|
|||||||
}),
|
}),
|
||||||
toClear = [], // Properties to clear out of scope on change
|
toClear = [], // Properties to clear out of scope on change
|
||||||
counter = 0,
|
counter = 0,
|
||||||
|
couldRepresent = false,
|
||||||
|
lastId,
|
||||||
|
lastKey,
|
||||||
changeTemplate = templateLinker.link($scope, element);
|
changeTemplate = templateLinker.link($scope, element);
|
||||||
|
|
||||||
// Populate scope with any capabilities indicated by the
|
// Populate scope with any capabilities indicated by the
|
||||||
@ -141,6 +143,13 @@ define(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function unchanged(canRepresent, id, key) {
|
||||||
|
return canRepresent &&
|
||||||
|
couldRepresent &&
|
||||||
|
id === lastId &&
|
||||||
|
key === lastKey;
|
||||||
|
}
|
||||||
|
|
||||||
// General-purpose refresh mechanism; should set up the scope
|
// General-purpose refresh mechanism; should set up the scope
|
||||||
// as appropriate for current representation key and
|
// as appropriate for current representation key and
|
||||||
// domain object.
|
// domain object.
|
||||||
@ -149,7 +158,13 @@ define(
|
|||||||
representation = lookup($scope.key, domainObject),
|
representation = lookup($scope.key, domainObject),
|
||||||
path = representation && getPath(representation),
|
path = representation && getPath(representation),
|
||||||
uses = ((representation || {}).uses || []),
|
uses = ((representation || {}).uses || []),
|
||||||
canRepresent = !!(path && domainObject);
|
canRepresent = !!(path && domainObject),
|
||||||
|
id = domainObject && domainObject.getId(),
|
||||||
|
key = $scope.key;
|
||||||
|
|
||||||
|
if (unchanged(canRepresent, id, key)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Create an empty object named "representation", for this
|
// Create an empty object named "representation", for this
|
||||||
// representation to store local variables into.
|
// representation to store local variables into.
|
||||||
@ -173,6 +188,11 @@ define(
|
|||||||
delete $scope[property];
|
delete $scope[property];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// To allow simplified change detection next time around
|
||||||
|
couldRepresent = canRepresent;
|
||||||
|
lastId = id;
|
||||||
|
lastKey = key;
|
||||||
|
|
||||||
// Populate scope with fields associated with the current
|
// Populate scope with fields associated with the current
|
||||||
// domain object (if one has been passed in)
|
// domain object (if one has been passed in)
|
||||||
if (canRepresent) {
|
if (canRepresent) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user