-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert InProgressMethods to an interface (#2970)
- Loading branch information
Showing
8 changed files
with
44 additions
and
43 deletions.
There are no files selected for viewing
48 changes: 21 additions & 27 deletions
48
extensions/ql-vscode/src/model-editor/shared/in-progress-methods.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,28 @@ | ||
/** | ||
* 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. | ||
* An interface to help keep track of which methods are in progress for each package. | ||
*/ | ||
export class InProgressMethods { | ||
// A map of in-progress method signatures for each package. | ||
private readonly methodMap: ReadonlyMap<string, Set<string>>; | ||
export type InProgressMethods = Record<string, string[]>; | ||
|
||
constructor(methodMap?: ReadonlyMap<string, Set<string>>) { | ||
this.methodMap = methodMap ?? new Map<string, Set<string>>(); | ||
} | ||
export function setPackageInProgressMethods( | ||
inProgressMethods: InProgressMethods, | ||
packageName: string, | ||
methods: string[], | ||
): InProgressMethods { | ||
return { | ||
...inProgressMethods, | ||
[packageName]: methods, | ||
}; | ||
} | ||
|
||
/** | ||
* 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); | ||
export function hasInProgressMethod( | ||
inProgressMethods: InProgressMethods, | ||
packageName: string, | ||
method: string, | ||
): boolean { | ||
const methods = inProgressMethods[packageName]; | ||
if (methods) { | ||
return methods.includes(method); | ||
} | ||
|
||
public hasMethod(packageName: string, method: string): boolean { | ||
const methods = this.methodMap.get(packageName); | ||
if (methods) { | ||
return methods.has(method); | ||
} | ||
return false; | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters