1
0
mirror of https://github.com/flarum/core.git synced 2025-07-19 07:41:22 +02: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:
Wadim Kalmykov
2020-10-03 05:03:44 +07:00
committed by GitHub
parent 81435a5ca0
commit 0232ec0edd

View File

@@ -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);
}, },
() => { () => {