forked from mystiq/hydrogen-web
await in loop --> Promise.all()
This commit is contained in:
parent
9bdf9c500b
commit
b29287c47e
2 changed files with 7 additions and 4 deletions
|
@ -35,7 +35,7 @@ export class ThemeBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
async populateDerivedTheme(manifest: ThemeManifest, log: ILogItem): Promise<void> {
|
async populateDerivedTheme(manifest: ThemeManifest, log: ILogItem): Promise<void> {
|
||||||
await log.wrap("ThemeBuilder.populateThemeMap", async (l) => {
|
await log.wrap("ThemeBuilder.populateThemeMap", async () => {
|
||||||
const {manifest: baseManifest, location} = this._idToManifest.get(manifest.extends!)!;
|
const {manifest: baseManifest, location} = this._idToManifest.get(manifest.extends!)!;
|
||||||
const {cssLocation, derivedVariables, icons} = this._getSourceData(baseManifest, location, log);
|
const {cssLocation, derivedVariables, icons} = this._getSourceData(baseManifest, location, log);
|
||||||
const themeName = manifest.name;
|
const themeName = manifest.name;
|
||||||
|
|
|
@ -60,11 +60,13 @@ export class ThemeLoader {
|
||||||
);
|
);
|
||||||
results.forEach(({ body }, i) => idToManifest.set(body.id, { manifest: body, location: manifestLocations[i] }));
|
results.forEach(({ body }, i) => idToManifest.set(body.id, { manifest: body, location: manifestLocations[i] }));
|
||||||
this._themeBuilder = new ThemeBuilder(this._platform, idToManifest, this.preferredColorScheme);
|
this._themeBuilder = new ThemeBuilder(this._platform, idToManifest, this.preferredColorScheme);
|
||||||
|
const runtimeThemePromises: Promise<void>[] = [];
|
||||||
for (let i = 0; i < results.length; ++i) {
|
for (let i = 0; i < results.length; ++i) {
|
||||||
const { body } = results[i];
|
const { body } = results[i];
|
||||||
try {
|
try {
|
||||||
if (body.extends) {
|
if (body.extends) {
|
||||||
await this._themeBuilder.populateDerivedTheme(body, log);
|
const promise = this._themeBuilder.populateDerivedTheme(body, log);
|
||||||
|
runtimeThemePromises.push(promise);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this._populateThemeMap(body, manifestLocations[i], log);
|
this._populateThemeMap(body, manifestLocations[i], log);
|
||||||
|
@ -74,8 +76,9 @@ export class ThemeLoader {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
await Promise.all(runtimeThemePromises);
|
||||||
Object.assign(this._themeMapping, this._themeBuilder.themeMapping);
|
Object.assign(this._themeMapping, this._themeBuilder.themeMapping);
|
||||||
//Add the default-theme as an additional option to the mapping
|
// Add the default-theme as an additional option to the mapping
|
||||||
const defaultThemeId = this.getDefaultTheme();
|
const defaultThemeId = this.getDefaultTheme();
|
||||||
if (defaultThemeId) {
|
if (defaultThemeId) {
|
||||||
const themeDetails = this._findThemeDetailsFromId(defaultThemeId);
|
const themeDetails = this._findThemeDetailsFromId(defaultThemeId);
|
||||||
|
@ -94,7 +97,7 @@ export class ThemeLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
private _populateThemeMap(manifest: ThemeManifest, manifestLocation: string, log: ILogItem) {
|
private _populateThemeMap(manifest: ThemeManifest, manifestLocation: string, log: ILogItem) {
|
||||||
log.wrap("populateThemeMap", (l) => {
|
log.wrap("populateThemeMap", () => {
|
||||||
/*
|
/*
|
||||||
After build has finished, the source section of each theme manifest
|
After build has finished, the source section of each theme manifest
|
||||||
contains `built-assets` which is a mapping from the theme-id to
|
contains `built-assets` which is a mapping from the theme-id to
|
||||||
|
|
Loading…
Reference in a new issue