From a72f193e97a5730f3df105fca31e08c8fd2ba01a Mon Sep 17 00:00:00 2001 From: Henry Date: Mon, 18 Apr 2016 09:15:25 -0700 Subject: [PATCH] Register listener for status change --- .../representation/src/MCTRepresentation.js | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/platform/representation/src/MCTRepresentation.js b/platform/representation/src/MCTRepresentation.js index c80f456222..bd95c95238 100644 --- a/platform/representation/src/MCTRepresentation.js +++ b/platform/representation/src/MCTRepresentation.js @@ -57,7 +57,7 @@ define( function MCTRepresentation(representations, views, representers, $q, templateLinker, $log) { var representationMap = {}, gestureMap = {}, - domainObjectListener; + listeners = 0; // Assemble all representations and views // The distinction between views and representations is @@ -95,6 +95,7 @@ define( couldEdit = false, lastIdPath = [], lastKey, + statusListener, changeTemplate = templateLinker.link($scope, element); // Populate scope with any capabilities indicated by the @@ -179,8 +180,6 @@ define( return; } - console.log("changed"); - // Create an empty object named "representation", for this // representation to store local variables into. $scope.representation = {}; @@ -243,16 +242,18 @@ define( // Also update when the represented domain object changes // (to a different object) - //$scope.$watch("domainObject", refresh); - - $scope.$watch("domainObject", function (domainObject) { - if (domainObjectListener) { - domainObjectListener(); + $scope.$watch("domainObject", refresh); + $scope.$watch("domainObject", function(domainObject) { + if (domainObject){ + if (statusListener) { + statusListener(); + listeners--; + console.log("directive listeners " + listeners); + } + statusListener = domainObject.getCapability("status").listen(refresh); + listeners++; + console.log("directive listeners " + listeners); } - if (domainObject) { - domainObjectListener = domainObject.getCapability('status').listen(refresh); - } - refresh(); }); // Finally, also update when there is a new version of that @@ -263,6 +264,13 @@ define( // Make sure any resources allocated by representers also get // released. $scope.$on("$destroy", destroyRepresenters); + $scope.$on("$destroy", function () { + if (statusListener) { + statusListener(); + listeners--; + console.log("directive listeners " + listeners); + } + }); // Do one initial refresh, so that we don't need another // digest iteration just to populate the scope. Failure to