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 60714b7ac4
commit 40548d7c61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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