Skip to content

Commit

Permalink
Execute the handler for manual resize in a debounced timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
widmoser committed Jun 29, 2016
1 parent 244d40f commit 4632527
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 8 additions & 1 deletion dist/tileview.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,14 @@
lastScrollPosition = Number.NEGATIVE_INFINITY;
layout(true);
});
scope.$on('td.tileview.resize', resize);
var resizeTimeout;
scope.$on('td.tileview.resize', function () {
// this might be called within a $digest
if (resizeTimeout) {
$timeout.cancel(resizeTimeout);
}
resizeTimeout = $timeout(resize, 50, false);
});
angular.element($window).on('resize', onResize);
scope.$on('$destroy', function () {
angular.element($window).off('resize', onResize);
Expand Down
10 changes: 9 additions & 1 deletion src/tileview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,15 @@ declare const angular: any;
lastScrollPosition = Number.NEGATIVE_INFINITY;
layout(true);
});
scope.$on('td.tileview.resize', resize);

let resizeTimeout;
scope.$on('td.tileview.resize', () => {
// this might be called within a $digest
if (resizeTimeout) {
$timeout.cancel(resizeTimeout);
}
resizeTimeout = $timeout(resize, 50, false);
});

angular.element($window).on('resize', onResize);

Expand Down

0 comments on commit 4632527

Please sign in to comment.