From 7e25a9b1b5d8278e8122b793adc6a657931f7f4f Mon Sep 17 00:00:00 2001 From: Christopher Svanefalk Date: Wed, 23 Nov 2016 23:13:43 +0100 Subject: [PATCH] feat(core): Reduce digest triggers when using $timeout Angular's $timeout takes a boolean 3rd parameter which causes the wrapped function to not run inside $apply. Since $timeout is used extensively in scope, this parameter has been passed where possible in order to improve performance, since the grid otherwise triggers a large number of digests while functioning normally. See issue: https://github.com/angular-ui/ui-grid/issues/5007 --- src/js/core/directives/ui-grid.js | 2 +- src/js/core/factories/Grid.js | 4 ++-- src/js/core/services/ui-grid-util.js | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/js/core/directives/ui-grid.js b/src/js/core/directives/ui-grid.js index d5dbfd0ecd..db24a162b2 100644 --- a/src/js/core/directives/ui-grid.js +++ b/src/js/core/directives/ui-grid.js @@ -241,7 +241,7 @@ function uiGridDirective($compile, $templateCache, $timeout, $window, gridUtil, sizeChecks++; } else { - $timeout(init); + $timeout(init, 0, false); } } diff --git a/src/js/core/factories/Grid.js b/src/js/core/factories/Grid.js index ea3fd662f3..b0438179f4 100644 --- a/src/js/core/factories/Grid.js +++ b/src/js/core/factories/Grid.js @@ -2244,13 +2244,13 @@ angular.module('ui.grid') } p.resolve(); - }); + }, 0, false); } else { // Timeout still needs to be here to trigger digest after styles have been rebuilt $timeout(function() { p.resolve(); - }); + }, 0, false); } return p.promise; diff --git a/src/js/core/services/ui-grid-util.js b/src/js/core/services/ui-grid-util.js index 1124e7709c..270cb30b25 100644 --- a/src/js/core/services/ui-grid-util.js +++ b/src/js/core/services/ui-grid-util.js @@ -831,7 +831,7 @@ module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateC } else { s.logWarn('[focus.byId] Element id ' + elementID + ' was not found.'); } - }); + }, 0, false); this.queue.push(promise); return promise; }, @@ -856,7 +856,7 @@ module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateC if (element){ element[0].focus(); } - }); + }, 0, false); this.queue.push(promise); return promise; }, @@ -886,8 +886,8 @@ module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateC }; this._purgeQueue(); if (aSync){ //Do this asynchronysly - var promise = $timeout(focusBySelector); - this.queue.push($timeout(focusBySelector)); + var promise = $timeout(focusBySelector, 0, false); + this.queue.push($timeout(focusBySelector), 0, false); return promise; } else { return focusBySelector();