Commit daf2ef89 authored by Robert Knight's avatar Robert Knight

Eliminate some variables following Promise-chain removal

Following the elimination of Promise chains, the load() method
can be shortened by eliminating some variables.
parent 29ea4c0a
...@@ -189,21 +189,11 @@ function groups( ...@@ -189,21 +189,11 @@ function groups(
} }
documentUri = uri; documentUri = uri;
const profileGroupsApi = api.profile.groups.read({
expand: params.expand,
});
const listGroupsApi = api.groups.list(params);
let groupApiRequests = [
profileGroupsApi,
listGroupsApi,
auth.tokenGetter(),
];
// If there is a direct-linked annotation, fetch the annotation to see // If there is a direct-linked annotation, fetch the annotation to see
// if there needs to be a second API request to fetch its group since // if there needs to be a second API request to fetch its group since
// the group may not be in the results returned by group.list, // the group may not be in the results returned by group.list,
// profile.groups, or the direct-linked group. // profile.groups, or the direct-linked group.
let directLinkedAnnApi = Promise.resolve(null); let directLinkedAnnApi = null;
if (directLinkedAnnId) { if (directLinkedAnnId) {
directLinkedAnnApi = api.annotation directLinkedAnnApi = api.annotation
.get({ id: directLinkedAnnId }) .get({ id: directLinkedAnnId })
...@@ -212,12 +202,11 @@ function groups( ...@@ -212,12 +202,11 @@ function groups(
return null; return null;
}); });
} }
groupApiRequests = groupApiRequests.concat(directLinkedAnnApi);
// If there is a direct-linked group, add an API request to get that // If there is a direct-linked group, add an API request to get that
// particular group since it may not be in the results returned by // particular group since it may not be in the results returned by
// group.list or profile.groups. // group.list or profile.groups.
let directLinkedGroupApi = Promise.resolve(null); let directLinkedGroupApi = null;
if (directLinkedGroupId) { if (directLinkedGroupId) {
directLinkedGroupApi = fetchGroup({ directLinkedGroupApi = fetchGroup({
id: directLinkedGroupId, id: directLinkedGroupId,
...@@ -232,14 +221,20 @@ function groups( ...@@ -232,14 +221,20 @@ function groups(
return group; return group;
}); });
} }
groupApiRequests = groupApiRequests.concat(directLinkedGroupApi);
let [ let [
myGroups, myGroups,
featuredGroups, featuredGroups,
token, token,
directLinkedAnn, directLinkedAnn,
directLinkedGroup, directLinkedGroup,
] = await Promise.all(groupApiRequests); ] = await Promise.all([
api.profile.groups.read({ expand: params.expand }),
api.groups.list(params),
auth.tokenGetter(),
directLinkedAnnApi,
directLinkedGroupApi,
]);
// Step 3. Add the direct-linked group to the list of featured groups, // Step 3. Add the direct-linked group to the list of featured groups,
// and if there was a direct-linked annotation, fetch its group if we // and if there was a direct-linked annotation, fetch its group if we
...@@ -247,7 +242,7 @@ function groups( ...@@ -247,7 +242,7 @@ function groups(
// If there is a direct-linked group, add it to the featured groups list. // If there is a direct-linked group, add it to the featured groups list.
featuredGroups = featuredGroups =
directLinkedGroup !== null && directLinkedGroup &&
!featuredGroups.some(g => g.id === directLinkedGroup.id) !featuredGroups.some(g => g.id === directLinkedGroup.id)
? featuredGroups.concat([directLinkedGroup]) ? featuredGroups.concat([directLinkedGroup])
: featuredGroups; : featuredGroups;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment