[Layout] Avoid infinite digest exception

Auto-expand tree nodes on a timeout, instead of immediately.
This is necessary in cases where auto-expansion several
layers deep occurs; if done immediately, each expansion
will trigger a new digest cycle, which at a certain depth
will appear to Angular as unstable.

Done in the context of WTD-535.
This commit is contained in:
Victor Woeltjen 2014-12-05 13:31:57 -08:00
parent 7dadc62f23
commit 7080ca585e
2 changed files with 15 additions and 6 deletions

View File

@ -17,7 +17,7 @@
{ {
"key": "TreeNodeController", "key": "TreeNodeController",
"implementation": "TreeNodeController.js", "implementation": "TreeNodeController.js",
"depends": [ "$scope", "navigationService" ] "depends": [ "$scope", "$timeout" ]
}, },
{ {
"key": "ActionGroupController", "key": "ActionGroupController",

View File

@ -29,7 +29,7 @@ define(
* expand-to-show-navigated-object behavior.) * expand-to-show-navigated-object behavior.)
* @constructor * @constructor
*/ */
function TreeNodeController($scope) { function TreeNodeController($scope, $timeout) {
var selectedObject = ($scope.ngModel || {}).selectedObject, var selectedObject = ($scope.ngModel || {}).selectedObject,
isSelected = false, isSelected = false,
hasBeenExpanded = false; hasBeenExpanded = false;
@ -90,6 +90,17 @@ define(
return false; // No context to judge by return false; // No context to judge by
} }
// Track that a node has been expanded, either by the
// user or automatically to show a selection.
function trackExpansion() {
if (!hasBeenExpanded) {
// Run on a timeout; if a lot of expansion needs to
// occur (e.g. if the selection is several nodes deep) we
// want this to be spread across multiple digest cycles.
$timeout(function () { hasBeenExpanded = true; }, 0);
}
}
// Consider the currently-navigated object and update // Consider the currently-navigated object and update
// parameters which support display. // parameters which support display.
function checkSelection() { function checkSelection() {
@ -107,7 +118,7 @@ define(
if (isOnSelectionPath(nodeObject, selectedObject) && if (isOnSelectionPath(nodeObject, selectedObject) &&
$scope.toggle !== undefined) { $scope.toggle !== undefined) {
$scope.toggle.setState(true); $scope.toggle.setState(true);
hasBeenExpanded = true; trackExpansion();
} }
} }
@ -128,9 +139,7 @@ define(
* to record that this has occurred, to support one-time * to record that this has occurred, to support one-time
* lazy loading of the node's subtree. * lazy loading of the node's subtree.
*/ */
trackExpansion: function () { trackExpansion: trackExpansion,
hasBeenExpanded = true;
},
/** /**
* Check if this not has ever been expanded. * Check if this not has ever been expanded.
* @returns true if it has been expanded * @returns true if it has been expanded