mirror of
https://github.com/flarum/core.git
synced 2025-08-03 15:07:53 +02:00
fix(regression): PostStreamState loadCount static member (#3420)
This commit is contained in:
@@ -5,11 +5,6 @@ import type Discussion from '../../common/models/Discussion';
|
|||||||
import type Post from '../../common/models/Post';
|
import type Post from '../../common/models/Post';
|
||||||
|
|
||||||
export default class PostStreamState {
|
export default class PostStreamState {
|
||||||
/**
|
|
||||||
* @see https://github.com/Microsoft/TypeScript/issues/3841#issuecomment-337560146
|
|
||||||
*/
|
|
||||||
['constructor']: typeof PostStreamState;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of posts to load per page.
|
* The number of posts to load per page.
|
||||||
*/
|
*/
|
||||||
@@ -178,8 +173,8 @@ export default class PostStreamState {
|
|||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
const start = this.sanitizeIndex(index - this.constructor.loadCount / 2);
|
const start = this.sanitizeIndex(index - PostStreamState.loadCount / 2);
|
||||||
const end = start + this.constructor.loadCount;
|
const end = start + PostStreamState.loadCount;
|
||||||
|
|
||||||
this.reset(start, end);
|
this.reset(start, end);
|
||||||
|
|
||||||
@@ -191,13 +186,13 @@ export default class PostStreamState {
|
|||||||
*/
|
*/
|
||||||
_loadNext() {
|
_loadNext() {
|
||||||
const start = this.visibleEnd;
|
const start = this.visibleEnd;
|
||||||
const end = (this.visibleEnd = this.sanitizeIndex(this.visibleEnd + this.constructor.loadCount));
|
const end = (this.visibleEnd = this.sanitizeIndex(this.visibleEnd + PostStreamState.loadCount));
|
||||||
|
|
||||||
// Unload the posts which are two pages back from the page we're currently
|
// Unload the posts which are two pages back from the page we're currently
|
||||||
// loading.
|
// loading.
|
||||||
const twoPagesAway = start - this.constructor.loadCount * 2;
|
const twoPagesAway = start - PostStreamState.loadCount * 2;
|
||||||
if (twoPagesAway > this.visibleStart && twoPagesAway >= 0) {
|
if (twoPagesAway > this.visibleStart && twoPagesAway >= 0) {
|
||||||
this.visibleStart = twoPagesAway + this.constructor.loadCount + 1;
|
this.visibleStart = twoPagesAway + PostStreamState.loadCount + 1;
|
||||||
|
|
||||||
if (this.loadPageTimeouts[twoPagesAway]) {
|
if (this.loadPageTimeouts[twoPagesAway]) {
|
||||||
clearTimeout(this.loadPageTimeouts[twoPagesAway]);
|
clearTimeout(this.loadPageTimeouts[twoPagesAway]);
|
||||||
@@ -214,11 +209,11 @@ export default class PostStreamState {
|
|||||||
*/
|
*/
|
||||||
_loadPrevious() {
|
_loadPrevious() {
|
||||||
const end = this.visibleStart;
|
const end = this.visibleStart;
|
||||||
const start = (this.visibleStart = this.sanitizeIndex(this.visibleStart - this.constructor.loadCount));
|
const start = (this.visibleStart = this.sanitizeIndex(this.visibleStart - PostStreamState.loadCount));
|
||||||
|
|
||||||
// Unload the posts which are two pages back from the page we're currently
|
// Unload the posts which are two pages back from the page we're currently
|
||||||
// loading.
|
// loading.
|
||||||
const twoPagesAway = start + this.constructor.loadCount * 2;
|
const twoPagesAway = start + PostStreamState.loadCount * 2;
|
||||||
if (twoPagesAway < this.visibleEnd && twoPagesAway <= this.count()) {
|
if (twoPagesAway < this.visibleEnd && twoPagesAway <= this.count()) {
|
||||||
this.visibleEnd = twoPagesAway;
|
this.visibleEnd = twoPagesAway;
|
||||||
|
|
||||||
@@ -302,7 +297,7 @@ export default class PostStreamState {
|
|||||||
*/
|
*/
|
||||||
reset(start?: number, end?: number) {
|
reset(start?: number, end?: number) {
|
||||||
this.visibleStart = start || 0;
|
this.visibleStart = start || 0;
|
||||||
this.visibleEnd = this.sanitizeIndex(end || this.constructor.loadCount);
|
this.visibleEnd = this.sanitizeIndex(end || PostStreamState.loadCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user