From d57a9f100ac11d9867584849eea517dbe15a12d9 Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov Date: Sun, 20 Sep 2020 01:06:46 -0400 Subject: [PATCH] Only call updateScrubberValues onupdate when necessary When the page is scrolled, goToIndex is called, or the page is loaded, various listeners result in the scrubber being updated with a new position and values. However, if goToNumber is called, the scrubber will not be updated. Accordingly, we add logic to the scrubber's onupdate to update itself, but only when needed, as indicated by this This saves us a LOT of unnecessary calls, and makes scrubber movement smoother. --- framework/core/js/src/forum/components/PostStream.js | 2 ++ .../js/src/forum/components/PostStreamScrubber.js | 5 ++++- .../core/js/src/forum/states/PostStreamState.js | 12 ++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/framework/core/js/src/forum/components/PostStream.js b/framework/core/js/src/forum/components/PostStream.js index dee970fd9..eef7d6b9c 100644 --- a/framework/core/js/src/forum/components/PostStream.js +++ b/framework/core/js/src/forum/components/PostStream.js @@ -353,6 +353,8 @@ export default class PostStream extends Component { return Promise.all([$container.promise(), this.stream.loadPromise]).then(() => { this.updateScrubber(); + this.stream.forceUpdateScrubber = true; + const index = $item.data('index'); m.redraw.sync(); diff --git a/framework/core/js/src/forum/components/PostStreamScrubber.js b/framework/core/js/src/forum/components/PostStreamScrubber.js index 93abaaecd..ef145809b 100644 --- a/framework/core/js/src/forum/components/PostStreamScrubber.js +++ b/framework/core/js/src/forum/components/PostStreamScrubber.js @@ -90,7 +90,10 @@ export default class PostStreamScrubber extends Component { } onupdate() { - this.stream.loadPromise.then(() => this.updateScrubberValues({ animate: true, forceHeightChange: true })); + if (this.stream.forceUpdateScrubber) { + this.stream.forceUpdateScrubber = false; + this.stream.loadPromise.then(() => this.updateScrubberValues({ animate: true, forceHeightChange: true })); + } } oncreate(vnode) { diff --git a/framework/core/js/src/forum/states/PostStreamState.js b/framework/core/js/src/forum/states/PostStreamState.js index 356bfa18d..355db56be 100644 --- a/framework/core/js/src/forum/states/PostStreamState.js +++ b/framework/core/js/src/forum/states/PostStreamState.js @@ -37,6 +37,18 @@ class PostStreamState { */ this.description = ''; + /** + * When the page is scrolled, goToIndex is called, or the page is loaded, + * various listeners result in the scrubber being updated with a new + * position and values. However, if goToNumber is called, the scrubber + * will not be updated. Accordingly, we add logic to the scrubber's + * onupdate to update itself, but only when needed, as indicated by this + * property. + * + * @type {Boolean} + */ + this.forceUpdateScrubber = false; + this.show(includedPosts); }