-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathin-progress-methods.ts
More file actions
34 lines (31 loc) · 1.04 KB
/
in-progress-methods.ts
File metadata and controls
34 lines (31 loc) · 1.04 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
/**
* A class that keeps track of which methods are in progress for each package.
*
* This class is immutable and therefore is safe to be used in a react useState hook.
*/
export class InProgressMethods {
// A map of in-progress method signatures for each package.
private readonly methodMap: ReadonlyMap<string, Set<string>>;
constructor(methodMap?: ReadonlyMap<string, Set<string>>) {
this.methodMap = methodMap ?? new Map<string, Set<string>>();
}
/**
* Sets the in-progress methods for the given package.
* Returns a new InProgressMethods instance.
*/
public setPackageMethods(
packageName: string,
methods: Set<string>,
): InProgressMethods {
const newMethodMap = new Map<string, Set<string>>(this.methodMap);
newMethodMap.set(packageName, methods);
return new InProgressMethods(newMethodMap);
}
public hasMethod(packageName: string, method: string): boolean {
const methods = this.methodMap.get(packageName);
if (methods) {
return methods.has(method);
}
return false;
}
}