diff --git a/platform/commonUI/edit/src/EditRepresenter.js b/platform/commonUI/edit/src/EditRepresenter.js index bf3dfc721b..5e3f3a8606 100644 --- a/platform/commonUI/edit/src/EditRepresenter.js +++ b/platform/commonUI/edit/src/EditRepresenter.js @@ -76,7 +76,6 @@ define( key = (representation || {}).key; // Track the represented object domainObject = representedObject; - // Ensure existing watches are released destroy(); } diff --git a/platform/commonUI/edit/src/representers/EditToolbarRepresenter.js b/platform/commonUI/edit/src/representers/EditToolbarRepresenter.js index 8e4958d5df..63a4c9d3cd 100644 --- a/platform/commonUI/edit/src/representers/EditToolbarRepresenter.js +++ b/platform/commonUI/edit/src/representers/EditToolbarRepresenter.js @@ -42,6 +42,11 @@ define( toolbarObject.state = toolbar.getState(); } + // Get state (to watch it) + function getState() { + return toolbarObject.state; + } + // Update selection models to match changed toolbar state function updateState(state) { // Update underlying state based on toolbar changes @@ -52,8 +57,18 @@ define( 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 function represent(representation) { + // + initialize(); // Clear any existing selection scope.selection = []; // Get the newest toolbar definition from the view @@ -62,24 +77,19 @@ define( updateSelection([]); } - // Destroy; stop watching the parent for changes in - // toolbar state. + // Destroy; remove toolbar object from parent scope function destroy() { - if (unwatch) { - unwatch(); - unwatch = undefined; + // Clear exposed toolbar state (if any) + if (attrs.toolbar) { + 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) { - // Expose toolbar state under that name - scope.$parent[attrs.toolbar] = toolbarObject; // Detect and handle changes to state from the toolbar - unwatch = scope.$parent.$watchCollection( - attrs.toolbar + ".state", - updateState - ); + scope.$watchCollection(getState, updateState); // Watch for changes in the current selection state scope.$watchCollection("selection", updateSelection); }