UNPKG

1.28 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.dev/license
7 */
8import { JsonValue } from '@angular-devkit/core';
9import { JobDescription, JobHandler, JobName } from './api';
10import { Readwrite } from './types';
11/**
12 * A JobDispatcher can be used to dispatch between multiple jobs.
13 */
14export interface JobDispatcher<A extends JsonValue, I extends JsonValue, O extends JsonValue> extends JobHandler<A, I, O> {
15 /**
16 * Set the default job if all conditionals failed.
17 * @param name The default name if all conditions are false.
18 */
19 setDefaultJob(name: JobName | null | JobHandler<JsonValue, JsonValue, JsonValue>): void;
20 /**
21 * Add a conditional job that will be selected if the input fits a predicate.
22 * @param predicate
23 * @param name
24 */
25 addConditionalJob(predicate: (args: A) => boolean, name: string): void;
26}
27/**
28 * OnReady a dispatcher that can dispatch to a sub job, depending on conditions.
29 * @param options
30 */
31export declare function createDispatcher<A extends JsonValue, I extends JsonValue, O extends JsonValue>(options?: Partial<Readwrite<JobDescription>>): JobDispatcher<A, I, O>;