mirror of
https://github.com/flarum/framework.git
synced 2025-02-07 18:33:01 +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
81435a5ca0
commit
0232ec0edd
|
@ -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;
|
||||
|
||||
if (clear) {
|
||||
if (!deferClear) {
|
||||
this.clear();
|
||||
}
|
||||
|
||||
return this.loadResults().then(
|
||||
(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);
|
||||
},
|
||||
() => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user