forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfallback-registry.ts
More file actions
44 lines (40 loc) · 1.32 KB
/
fallback-registry.ts
File metadata and controls
44 lines (40 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { JsonValue } from '@angular-devkit/core';
import { Observable, concatMap, first, from } from 'rxjs';
import { JobHandler, JobName, Registry } from './api';
/**
* A simple job registry that keep a map of JobName => JobHandler internally.
*/
export class FallbackRegistry<
MinimumArgumentValueT extends JsonValue = JsonValue,
MinimumInputValueT extends JsonValue = JsonValue,
MinimumOutputValueT extends JsonValue = JsonValue,
> implements Registry<MinimumArgumentValueT, MinimumInputValueT, MinimumOutputValueT>
{
constructor(
protected _fallbacks: Registry<
MinimumArgumentValueT,
MinimumInputValueT,
MinimumOutputValueT
>[] = [],
) {}
addFallback(registry: Registry): void {
this._fallbacks.push(registry);
}
get<
A extends MinimumArgumentValueT = MinimumArgumentValueT,
I extends MinimumInputValueT = MinimumInputValueT,
O extends MinimumOutputValueT = MinimumOutputValueT,
>(name: JobName): Observable<JobHandler<A, I, O> | null> {
return from(this._fallbacks).pipe(
concatMap((fb) => fb.get<A, I, O>(name)),
first((x) => x !== null, null),
);
}
}