[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",
"implementation": "TreeNodeController.js",
"depends": [ "$scope", "navigationService" ]
"depends": [ "$scope", "$timeout" ]
},
{
"key": "ActionGroupController",

View File

@ -29,7 +29,7 @@ define(
* expand-to-show-navigated-object behavior.)
* @constructor
*/
function TreeNodeController($scope) {
function TreeNodeController($scope, $timeout) {
var selectedObject = ($scope.ngModel || {}).selectedObject,
isSelected = false,
hasBeenExpanded = false;
@ -90,6 +90,17 @@ define(
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
// parameters which support display.
function checkSelection() {
@ -107,7 +118,7 @@ define(
if (isOnSelectionPath(nodeObject, selectedObject) &&
$scope.toggle !== undefined) {
$scope.toggle.setState(true);
hasBeenExpanded = true;
trackExpansion();
}
}
@ -128,9 +139,7 @@ define(
* to record that this has occurred, to support one-time
* lazy loading of the node's subtree.
*/
trackExpansion: function () {
hasBeenExpanded = true;
},
trackExpansion: trackExpansion,
/**
* Check if this not has ever been expanded.
* @returns true if it has been expanded