Skip to content

Commit

Permalink
Refactor out function to call digest only when safe
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmcgrath committed Nov 15, 2013
1 parent c364028 commit 7745223
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/directives/ng-viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ ngGridDirectives.directive('ngViewport', [function() {
var isMouseWheelActive;
var prevScollLeft;
var prevScollTop = 0;
var ensureDigest = function() {
if (!$scope.$root.$$phase) {
$scope.$digest();
}
};
elm.bind('scroll', function(evt) {
var scrollLeft = evt.target.scrollLeft,
scrollTop = evt.target.scrollTop;
Expand All @@ -11,9 +16,7 @@ ngGridDirectives.directive('ngViewport', [function() {
}
$scope.adjustScrollLeft(scrollLeft);
$scope.adjustScrollTop(scrollTop);
if (!$scope.$root.$$phase) {
$scope.$digest();
}
ensureDigest();
prevScollLeft = scrollLeft;
prevScollTop = scrollTop;
isMouseWheelActive = false;
Expand Down

0 comments on commit 7745223

Please sign in to comment.