Fixed race condition in pager presenter

This commit is contained in:
Marcin Kurczewski 2014-10-20 19:37:48 +02:00
parent ea77a662ad
commit 25080fd977

View file

@ -52,7 +52,6 @@ App.Presenters.PagerPresenter = function(
} }
function reinit(params, loaded) { function reinit(params, loaded) {
window.clearInterval(scrollInterval);
if (forceClear) { if (forceClear) {
clearContent(); clearContent();
} }
@ -122,6 +121,7 @@ App.Presenters.PagerPresenter = function(
} }
function clearContent() { function clearContent() {
detachNextPageLoader();
updateCallback({entities: [], totalRecords: 0}, true); updateCallback({entities: [], totalRecords: 0}, true);
} }
@ -130,14 +130,15 @@ App.Presenters.PagerPresenter = function(
return; return;
} }
window.clearInterval(scrollInterval); detachNextPageLoader();
scrollInterval = window.setInterval(function() { scrollInterval = window.setInterval(function() {
var myScrollInterval = scrollInterval;
var baseLine = $target.offset().top + $target.innerHeight(); var baseLine = $target.offset().top + $target.innerHeight();
var scrollY = jQuery(window).scrollTop() + jQuery(window).height(); var scrollY = jQuery(window).scrollTop() + jQuery(window).height();
if (scrollY > baseLine) { if (scrollY > baseLine) {
pager.nextPage(); pager.nextPage();
syncUrlInplace(); syncUrlInplace();
window.clearInterval(scrollInterval); window.clearInterval(myScrollInterval);
} }
}, 100); }, 100);
} }