UNPKG

2.04 kBPlain TextView Raw
1/**
2 * -------------------------------------------------------------------------------------------
3 * Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
4 * See License in the project root for license information.
5 * -------------------------------------------------------------------------------------------
6 */
7
8/**
9 * @module MiddlewareControl
10 */
11
12import { MiddlewareOptions } from "./options/IMiddlewareOptions";
13
14/**
15 * @class
16 * Class representing MiddlewareControl
17 */
18export class MiddlewareControl {
19 /**
20 * @private
21 * A member holding map of MiddlewareOptions
22 */
23 private middlewareOptions: Map<Function, MiddlewareOptions>;
24
25 /**
26 * @public
27 * @constructor
28 * Creates an instance of MiddlewareControl
29 * @param {MiddlewareOptions[]} [middlewareOptions = []] - The array of middlewareOptions
30 * @returns The instance of MiddlewareControl
31 */
32 public constructor(middlewareOptions: MiddlewareOptions[] = []) {
33 this.middlewareOptions = new Map<Function, MiddlewareOptions>();
34 for (const option of middlewareOptions) {
35 const fn = option.constructor;
36 this.middlewareOptions.set(fn, option);
37 }
38 }
39
40 /**
41 * @public
42 * To get the middleware option using the class of the option
43 * @param {Function} fn - The class of the strongly typed option class
44 * @returns The middleware option
45 * @example
46 * // if you wanted to return the middleware option associated with this class (MiddlewareControl)
47 * // call this function like this:
48 * getMiddlewareOptions(MiddlewareControl)
49 */
50 public getMiddlewareOptions(fn: Function): MiddlewareOptions {
51 return this.middlewareOptions.get(fn);
52 }
53
54 /**
55 * @public
56 * To set the middleware options using the class of the option
57 * @param {Function} fn - The class of the strongly typed option class
58 * @param {MiddlewareOptions} option - The strongly typed middleware option
59 * @returns nothing
60 */
61 public setMiddlewareOptions(fn: Function, option: MiddlewareOptions): void {
62 this.middlewareOptions.set(fn, option);
63 }
64}