From b81a1b2cb99ac325a1b6c9456f4111607c54af35 Mon Sep 17 00:00:00 2001 From: Boxuan Li Date: Wed, 24 Oct 2018 23:06:32 +0800 Subject: [PATCH] issue-store.js: Resolve promise directly at first time This resolves _fetchAllIssues promise directly before polling starts. The benefit is that users don't need to wait until they see pre-fetched cards. Closes https://github.com/coala/gh-board/issues/173 --- src/issue-store.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/issue-store.js b/src/issue-store.js index 773674d3..d9018885 100644 --- a/src/issue-store.js +++ b/src/issue-store.js @@ -123,6 +123,7 @@ const issueStore = new class IssueStore extends EventEmitter { } } }); + this.isInitialFetch = true; } off() { // EventEmitter has `.on` but no matching `.off` const slice = [].slice; @@ -359,10 +360,19 @@ const issueStore = new class IssueStore extends EventEmitter { _fetchAllIssues(repoInfos, progress, isForced) { // Start/keep polling if (!this.polling && isPollingEnabled) { - this.polling = setTimeout(() => { - this.polling = null; - this._fetchAllIssues(repoInfos, progress, true /*isForced*/); - }, getReloadTime()); + if (this.isInitialFetch) { + this.isInitialFetch = false; + this.polling = setTimeout(() => { + this.polling = null; + this._fetchAllIssues(repoInfos, progress, true); + }); + return Promise.resolve([]); + } else { + this.polling = setTimeout(() => { + this.polling = null; + this._fetchAllIssues(repoInfos, progress, true /*isForced*/); + }, getReloadTime()); + } } if (!isForced && cacheCards && cacheCardsRepoInfos === JSON.stringify(repoInfos)) { return Promise.resolve(cacheCards);