From a197368bc54d0dab3db50cd8e05d15efebd58796 Mon Sep 17 00:00:00 2001 From: rr- Date: Sun, 17 Apr 2016 09:24:05 +0200 Subject: [PATCH] client/paging: fix endless pager issues --- client/js/controllers/page_controller.js | 1 + client/js/views/endless_page_view.js | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/client/js/controllers/page_controller.js b/client/js/controllers/page_controller.js index af1f8f2f..8c75c83b 100644 --- a/client/js/controllers/page_controller.js +++ b/client/js/controllers/page_controller.js @@ -22,6 +22,7 @@ class PageController { } run(ctx) { + this.pageView.unrender(); this.pageView.render(ctx); } diff --git a/client/js/views/endless_page_view.js b/client/js/views/endless_page_view.js index 84cc283f..2b00fe80 100644 --- a/client/js/views/endless_page_view.js +++ b/client/js/views/endless_page_view.js @@ -17,6 +17,7 @@ class EndlessPageView { const pagesHolder = source.querySelector('.pages-holder'); views.listenToMessages(target); views.showView(target, source); + this.active = true; let headerRendererCtx = ctx; headerRendererCtx.target = pageHeaderHolder; @@ -90,6 +91,7 @@ class EndlessPageView { } unrender() { + this.active = false; window.removeEventListener('scroll', this.updater, true); } @@ -104,6 +106,9 @@ class EndlessPageView { } ctx.requestPage(pageNumber).then(response => { + if (!this.active) { + return; + } this.totalPages = Math.ceil(response.total / response.pageSize); if (response.total) { const pageNode = this.pageTemplate({ @@ -132,7 +137,7 @@ class EndlessPageView { } this.fetching = false; - this.updater(); + window.setTimeout(() => { this.updater(); }, 10); if (response.total <= (pageNumber - 1) * response.pageSize) { events.notify(events.Info, 'No data to show');