client/paging: fix endless pager issues

This commit is contained in:
rr- 2016-04-17 09:24:05 +02:00
parent 0bc45e9c45
commit a197368bc5
2 changed files with 7 additions and 1 deletions

View File

@ -22,6 +22,7 @@ class PageController {
} }
run(ctx) { run(ctx) {
this.pageView.unrender();
this.pageView.render(ctx); this.pageView.render(ctx);
} }

View File

@ -17,6 +17,7 @@ class EndlessPageView {
const pagesHolder = source.querySelector('.pages-holder'); const pagesHolder = source.querySelector('.pages-holder');
views.listenToMessages(target); views.listenToMessages(target);
views.showView(target, source); views.showView(target, source);
this.active = true;
let headerRendererCtx = ctx; let headerRendererCtx = ctx;
headerRendererCtx.target = pageHeaderHolder; headerRendererCtx.target = pageHeaderHolder;
@ -90,6 +91,7 @@ class EndlessPageView {
} }
unrender() { unrender() {
this.active = false;
window.removeEventListener('scroll', this.updater, true); window.removeEventListener('scroll', this.updater, true);
} }
@ -104,6 +106,9 @@ class EndlessPageView {
} }
ctx.requestPage(pageNumber).then(response => { ctx.requestPage(pageNumber).then(response => {
if (!this.active) {
return;
}
this.totalPages = Math.ceil(response.total / response.pageSize); this.totalPages = Math.ceil(response.total / response.pageSize);
if (response.total) { if (response.total) {
const pageNode = this.pageTemplate({ const pageNode = this.pageTemplate({
@ -132,7 +137,7 @@ class EndlessPageView {
} }
this.fetching = false; this.fetching = false;
this.updater(); window.setTimeout(() => { this.updater(); }, 10);
if (response.total <= (pageNumber - 1) * response.pageSize) { if (response.total <= (pageNumber - 1) * response.pageSize) {
events.notify(events.Info, 'No data to show'); events.notify(events.Info, 'No data to show');