Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 07194ca

Browse files
author
Marcel Gerber
committed
Use deferreds
1 parent 36114f3 commit 07194ca

1 file changed

Lines changed: 50 additions & 47 deletions

File tree

src/help/HelpCommandHandlers.js

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -93,63 +93,66 @@ define(function (require, exports, module) {
9393

9494
$spinner.addClass("spin");
9595

96-
function loadContributorsPage(url, page) {
97-
var contributors;
98-
96+
function loadContributors(rawUrl, page, contributors, deferred) {
97+
deferred = deferred || $.Deferred();
98+
contributors = contributors || [];
99+
var url = rawUrl;
99100
if (page) {
100-
url = StringUtils.format(url, CONTRIBUTORS_PER_PAGE, page);
101+
url = StringUtils.format(rawUrl, CONTRIBUTORS_PER_PAGE, page);
101102
}
103+
102104
$.ajax({
103105
url: url,
104-
async: false,
105106
dataType: "json",
106-
cache: false,
107-
complete: function (data) {
108-
contributors = (data && data.responseJSON) || [];
109-
}
110-
});
111-
return contributors;
107+
cache: false
108+
})
109+
.done(function (response) {
110+
var data = response || [];
111+
contributors = contributors.concat(data);
112+
if (page && data.length === CONTRIBUTORS_PER_PAGE) {
113+
loadContributors(rawUrl, page + 1, contributors, deferred);
114+
} else {
115+
deferred.resolve(contributors);
116+
}
117+
})
118+
.fail(function () {
119+
deferred.reject(contributors);
120+
});
121+
return deferred;
112122
}
113123

114-
// Get all the project contributors
115-
do {
116-
data = loadContributorsPage(contributorsUrl, page);
117-
allContributors = allContributors.concat(data);
118-
if (page) {
119-
page++;
120-
}
121-
} while (page && data.length === CONTRIBUTORS_PER_PAGE);
124+
loadContributors(contributorsUrl, page) // Load the contributors
125+
.done(function (allContributors) {
126+
// Populate the contributors data
127+
var totalContributors = allContributors.length,
128+
contributorsCount = 0;
122129

123-
if (allContributors.length) {
124-
// Populate the contributors data
125-
var totalContributors = allContributors.length,
126-
contributorsCount = 0;
127-
128-
allContributors.forEach(function (contributor) {
129-
// remove any UrlParams delivered via the GitHub API
130-
contributor.avatar_url = contributor.avatar_url.split("?")[0];
131-
});
130+
allContributors.forEach(function (contributor) {
131+
// remove any UrlParams delivered via the GitHub API
132+
contributor.avatar_url = contributor.avatar_url.split("?")[0];
133+
});
134+
135+
$contributors.html(Mustache.render(ContributorsTemplate, allContributors));
132136

133-
$contributors.html(Mustache.render(ContributorsTemplate, allContributors));
134-
135-
// This is used to create an opacity transition when each image is loaded
136-
$contributors.find("img").one("load", function () {
137-
$(this).css("opacity", 1);
138-
139-
// Count the contributors loaded and hide the spinner once all are loaded
140-
contributorsCount++;
141-
if (contributorsCount >= totalContributors) {
142-
$spinner.removeClass("spin");
143-
}
144-
}).each(function () {
145-
if (this.complete) {
146-
$(this).trigger("load");
147-
}
137+
// This is used to create an opacity transition when each image is loaded
138+
$contributors.find("img").one("load", function () {
139+
$(this).css("opacity", 1);
140+
141+
// Count the contributors loaded and hide the spinner once all are loaded
142+
contributorsCount++;
143+
if (contributorsCount >= totalContributors) {
144+
$spinner.removeClass("spin");
145+
}
146+
}).each(function () {
147+
if (this.complete) {
148+
$(this).trigger("load");
149+
}
150+
});
151+
})
152+
.fail(function () {
153+
$spinner.removeClass("spin");
154+
$contributors.html(Mustache.render("<p class='dialog-message'>{{ABOUT_TEXT_LINE6}}</p>", Strings));
148155
});
149-
} else {
150-
$spinner.removeClass("spin");
151-
$contributors.html(Mustache.render("<p class='dialog-message'>{{ABOUT_TEXT_LINE6}}</p>", Strings));
152-
}
153156
}
154157

155158
// Read "build number" SHAs off disk immediately at APP_READY, instead

0 commit comments

Comments
 (0)