mirror of
https://github.com/nasa/openmct.git
synced 2025-05-29 21:54:20 +00:00
[Edit] Fix state-watching
Repair/simplify state-watching in representer for toolbar in edit mode; avoids issue where destroy calls detach watches for state change in toolbar prematurely. WTD-881.
This commit is contained in:
parent
182d02599d
commit
c183f08886
@ -76,7 +76,6 @@ define(
|
|||||||
key = (representation || {}).key;
|
key = (representation || {}).key;
|
||||||
// Track the represented object
|
// Track the represented object
|
||||||
domainObject = representedObject;
|
domainObject = representedObject;
|
||||||
|
|
||||||
// Ensure existing watches are released
|
// Ensure existing watches are released
|
||||||
destroy();
|
destroy();
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,11 @@ define(
|
|||||||
toolbarObject.state = toolbar.getState();
|
toolbarObject.state = toolbar.getState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get state (to watch it)
|
||||||
|
function getState() {
|
||||||
|
return toolbarObject.state;
|
||||||
|
}
|
||||||
|
|
||||||
// Update selection models to match changed toolbar state
|
// Update selection models to match changed toolbar state
|
||||||
function updateState(state) {
|
function updateState(state) {
|
||||||
// Update underlying state based on toolbar changes
|
// Update underlying state based on toolbar changes
|
||||||
@ -52,8 +57,18 @@ define(
|
|||||||
commit("Changes from toolbar.");
|
commit("Changes from toolbar.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initialize() {
|
||||||
|
// If we have been asked to expose toolbar state...
|
||||||
|
if (attrs.toolbar) {
|
||||||
|
// Expose toolbar state under that name
|
||||||
|
scope.$parent[attrs.toolbar] = toolbarObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Represent a domain object using this definition
|
// Represent a domain object using this definition
|
||||||
function represent(representation) {
|
function represent(representation) {
|
||||||
|
//
|
||||||
|
initialize();
|
||||||
// Clear any existing selection
|
// Clear any existing selection
|
||||||
scope.selection = [];
|
scope.selection = [];
|
||||||
// Get the newest toolbar definition from the view
|
// Get the newest toolbar definition from the view
|
||||||
@ -62,24 +77,19 @@ define(
|
|||||||
updateSelection([]);
|
updateSelection([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy; stop watching the parent for changes in
|
// Destroy; remove toolbar object from parent scope
|
||||||
// toolbar state.
|
|
||||||
function destroy() {
|
function destroy() {
|
||||||
if (unwatch) {
|
// Clear exposed toolbar state (if any)
|
||||||
unwatch();
|
if (attrs.toolbar) {
|
||||||
unwatch = undefined;
|
delete scope.$parent[attrs.toolbar];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have been asked to expose toolbar state...
|
// If this representation exposes a toolbar, set up watches
|
||||||
|
// to synchronize with it.
|
||||||
if (attrs.toolbar) {
|
if (attrs.toolbar) {
|
||||||
// Expose toolbar state under that name
|
|
||||||
scope.$parent[attrs.toolbar] = toolbarObject;
|
|
||||||
// Detect and handle changes to state from the toolbar
|
// Detect and handle changes to state from the toolbar
|
||||||
unwatch = scope.$parent.$watchCollection(
|
scope.$watchCollection(getState, updateState);
|
||||||
attrs.toolbar + ".state",
|
|
||||||
updateState
|
|
||||||
);
|
|
||||||
// Watch for changes in the current selection state
|
// Watch for changes in the current selection state
|
||||||
scope.$watchCollection("selection", updateSelection);
|
scope.$watchCollection("selection", updateSelection);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user