Skip to content

Commit 22619a1

Browse files
committed
feat(config-files): switch to async data flow
1 parent 577c3b8 commit 22619a1

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

packages/config-files/src/loader.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { HttpClient } from '@angular/common/http';
22
import { forwardRef, inject, Injectable, Injector } from '@angular/core';
33
import { Exception } from '@angularity/core';
4-
import { catchError, map, Observable } from 'rxjs';
4+
import { catchError, map, Observable, switchMap } from 'rxjs';
55

66
import { ConfigFileDefinition } from './definition';
77

@@ -24,7 +24,8 @@ export abstract class ConfigFileLoader {
2424
export class ConfigFileNotFoundException extends Exception {}
2525

2626
/**
27-
* Implementation of {@link ConfigFileLoader} based on Angular's built-in {@link HttpClient}.
27+
* Implementation of {@link ConfigFileLoader}
28+
* based on Angular's built-in {@link HttpClient}.
2829
*/
2930
@Injectable({
3031
providedIn: 'root',
@@ -42,9 +43,9 @@ export class HttpClientConfigFileLoader implements ConfigFileLoader {
4243
if (!res) throw new ConfigFileNotFoundException(def.path);
4344
return res;
4445
}),
45-
map((raw) => {
46-
const parsed = parser.parse(raw);
47-
validator.validate(def.schema, parsed);
46+
switchMap(async (raw) => {
47+
const parsed = await parser.parse(raw);
48+
await validator.validate(def.schema, parsed);
4849
return parsed as T;
4950
}),
5051
);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Exception } from '@angularity/core';
22

33
export interface ConfigFileParser {
4-
parse(raw: string): object;
4+
parse(raw: string): Promise<object>;
55
}
66

77
export class ConfigFileParsingException extends Exception {}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Exception } from '@angularity/core';
22

33
export interface ConfigFileValidator<Schema> {
4-
validate(schema: Schema, parsed: object): void;
4+
validate(schema: Schema, parsed: object): Promise<void>;
55
}
66

77
export class ConfigFileValidationException extends Exception {}

0 commit comments

Comments
 (0)