From 40548d7c61eaea5792bd64f563a77aae36720981 Mon Sep 17 00:00:00 2001 From: Wadim Kalmykov <36057469+w-4@users.noreply.github.com> Date: Sat, 3 Oct 2020 05:03:44 +0700 Subject: [PATCH] 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. --- js/src/forum/states/DiscussionListState.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/js/src/forum/states/DiscussionListState.js b/js/src/forum/states/DiscussionListState.js index 787560507..57f4396a8 100644 --- a/js/src/forum/states/DiscussionListState.js +++ b/js/src/forum/states/DiscussionListState.js @@ -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); }, () => {