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.
This commit is contained in:
Alexander Skvortsov 2020-09-20 01:06:46 -04:00
parent 8640ce83b5
commit d57a9f100a
3 changed files with 18 additions and 1 deletions

View File

@ -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();

View File

@ -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) {

View File

@ -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);
}