|
1 | 1 | /** |
2 | | - * A class that keeps track of which methods are in progress for each package. |
3 | | - * |
4 | | - * This class is immutable and therefore is safe to be used in a React useState hook. |
| 2 | + * An interface to help keep track of which methods are in progress for each package. |
5 | 3 | */ |
6 | | -export class InProgressMethods { |
7 | | - // A map of in-progress method signatures for each package. |
8 | | - private readonly methodMap: ReadonlyMap<string, Set<string>>; |
| 4 | +export type InProgressMethods = Record<string, string[]>; |
9 | 5 |
|
10 | | - constructor(methodMap?: ReadonlyMap<string, Set<string>>) { |
11 | | - this.methodMap = methodMap ?? new Map<string, Set<string>>(); |
12 | | - } |
| 6 | +export function setPackageInProgressMethods( |
| 7 | + inProgressMethods: InProgressMethods, |
| 8 | + packageName: string, |
| 9 | + methods: string[], |
| 10 | +): InProgressMethods { |
| 11 | + return { |
| 12 | + ...inProgressMethods, |
| 13 | + [packageName]: methods, |
| 14 | + }; |
| 15 | +} |
13 | 16 |
|
14 | | - /** |
15 | | - * Sets the in-progress methods for the given package. |
16 | | - * Returns a new InProgressMethods instance. |
17 | | - */ |
18 | | - public setPackageMethods( |
19 | | - packageName: string, |
20 | | - methods: Set<string>, |
21 | | - ): InProgressMethods { |
22 | | - const newMethodMap = new Map<string, Set<string>>(this.methodMap); |
23 | | - newMethodMap.set(packageName, methods); |
24 | | - return new InProgressMethods(newMethodMap); |
| 17 | +export function hasInProgressMethod( |
| 18 | + inProgressMethods: InProgressMethods, |
| 19 | + packageName: string, |
| 20 | + method: string, |
| 21 | +): boolean { |
| 22 | + const methods = inProgressMethods[packageName]; |
| 23 | + if (methods) { |
| 24 | + return methods.includes(method); |
25 | 25 | } |
26 | 26 |
|
27 | | - public hasMethod(packageName: string, method: string): boolean { |
28 | | - const methods = this.methodMap.get(packageName); |
29 | | - if (methods) { |
30 | | - return methods.has(method); |
31 | | - } |
32 | | - return false; |
33 | | - } |
| 27 | + return false; |
34 | 28 | } |
0 commit comments