mirror of
https://github.com/flarum/framework.git
synced 2025-02-22 21:55:41 +08:00
Improve DiscussionListState refresh method (#2322)
- Ensure that the discussion list is cleared before it is updated with fetched results - Rename `clear` to `deferClear`, improve documentation to make its purpose clearer.
This commit is contained in:
parent
60714b7ac4
commit
40548d7c61
@ -77,17 +77,23 @@ export default class DiscussionListState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear and reload the discussion list.
|
* Clear and reload the discussion list. Passing the option `deferClear: true`
|
||||||
|
* will clear discussions only after new data has been received.
|
||||||
|
* This can be used to refresh discussions without loading animations.
|
||||||
*/
|
*/
|
||||||
refresh({ clear = true } = {}) {
|
refresh({ deferClear = false } = {}) {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
||||||
if (clear) {
|
if (!deferClear) {
|
||||||
this.clear();
|
this.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.loadResults().then(
|
return this.loadResults().then(
|
||||||
(results) => {
|
(results) => {
|
||||||
|
// This ensures that any changes made while waiting on this request
|
||||||
|
// are ignored. Otherwise, we could get duplicate discussions.
|
||||||
|
// We don't use `this.clear()` to avoid an unnecessary redraw.
|
||||||
|
this.discussions = [];
|
||||||
this.parseResults(results);
|
this.parseResults(results);
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user