From c8931f8535c137f1b3f0d2360db9cf6d3e58cfe6 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 5 Aug 2016 16:30:55 -0700 Subject: [PATCH] [Tree] Simplify synchronization (#1100) Simplify synchronization of selection in tree with state passed-in, letting Angular deal with more of the specifics. Fixes #1008. --- platform/commonUI/general/bundle.js | 2 +- .../commonUI/general/src/directives/MCTTree.js | 15 ++++++--------- .../general/test/directives/MCTTreeSpec.js | 8 ++++---- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/platform/commonUI/general/bundle.js b/platform/commonUI/general/bundle.js index 1ec3c5a1f4..15ea3076a6 100644 --- a/platform/commonUI/general/bundle.js +++ b/platform/commonUI/general/bundle.js @@ -381,7 +381,7 @@ define([ { "key": "mctTree", "implementation": MCTTree, - "depends": ['$parse', 'gestureService'] + "depends": ['gestureService'] } ], "constants": [ diff --git a/platform/commonUI/general/src/directives/MCTTree.js b/platform/commonUI/general/src/directives/MCTTree.js index bb3bb3439e..987b733ba6 100644 --- a/platform/commonUI/general/src/directives/MCTTree.js +++ b/platform/commonUI/general/src/directives/MCTTree.js @@ -24,20 +24,17 @@ define([ 'angular', '../ui/TreeView' ], function (angular, TreeView) { - function MCTTree($parse, gestureService) { - function link(scope, element, attrs) { + function MCTTree(gestureService) { + function link(scope, element) { var treeView = new TreeView(gestureService), - expr = $parse(attrs.mctModel), unobserve = treeView.observe(function (domainObject) { - if (domainObject !== expr(scope.$parent)) { - expr.assign(scope.$parent, domainObject); - scope.$apply(); - } + scope.mctModel = domainObject; + scope.$apply(); }); element.append(angular.element(treeView.elements())); - scope.$parent.$watch(attrs.mctModel, treeView.value.bind(treeView)); + scope.$watch('mctModel', treeView.value.bind(treeView)); scope.$watch('mctObject', treeView.model.bind(treeView)); scope.$on('$destroy', unobserve); } @@ -45,7 +42,7 @@ define([ return { restrict: "E", link: link, - scope: { mctObject: "=" } + scope: { mctObject: "=", mctModel: "=" } }; } diff --git a/platform/commonUI/general/test/directives/MCTTreeSpec.js b/platform/commonUI/general/test/directives/MCTTreeSpec.js index 11921c2625..0cc64949c2 100644 --- a/platform/commonUI/general/test/directives/MCTTreeSpec.js +++ b/platform/commonUI/general/test/directives/MCTTreeSpec.js @@ -46,8 +46,8 @@ define([ expect(mctTree.restrict).toEqual("E"); }); - it("two-way binds to mctObject", function () { - expect(mctTree.scope).toEqual({ mctObject: "=" }); + it("two-way binds to mctObject and mctModel", function () { + expect(mctTree.scope).toEqual({ mctObject: "=", mctModel: "=" }); }); describe("link", function () { @@ -69,8 +69,8 @@ define([ }); it("watches for mct-model's expression in the parent", function () { - expect(mockScope.$parent.$watch).toHaveBeenCalledWith( - testAttrs.mctModel, + expect(mockScope.$watch).toHaveBeenCalledWith( + "mctModel", jasmine.any(Function) ); });