Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
/**
* 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: Map<string, Set<string>>;
private readonly methodMap: ReadonlyMap<string, Set<string>>;

constructor() {
this.methodMap = new Map<string, Set<string>>();
constructor(methodMap?: ReadonlyMap<string, Set<string>>) {
this.methodMap = methodMap ?? new Map<string, Set<string>>();
}

public setPackageMethods(packageName: string, methods: Set<string>): void {
this.methodMap.set(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.forEach((value, key) => {
newMethodMap.set(key, new Set<string>(value));
});
Comment thread
robertbrignull marked this conversation as resolved.
Outdated
newMethodMap.set(packageName, methods);
return new InProgressMethods(newMethodMap);
}

public hasMethod(packageName: string, method: string): boolean {
Expand All @@ -20,12 +34,4 @@ export class InProgressMethods {
}
return false;
}

public static fromExisting(methods: InProgressMethods): InProgressMethods {
const newInProgressMethods = new InProgressMethods();
methods.methodMap.forEach((value, key) => {
newInProgressMethods.methodMap.set(key, new Set<string>(value));
});
return newInProgressMethods;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,12 @@ export function DataExtensionsEditor({
);
break;
case "setInProgressMethods":
setInProgressMethods((oldInProgressMethods) => {
const methods =
InProgressMethods.fromExisting(oldInProgressMethods);
methods.setPackageMethods(
setInProgressMethods((oldInProgressMethods) =>
oldInProgressMethods.setPackageMethods(
msg.packageName,
new Set(msg.inProgressMethods),
);
return methods;
});
),
);
break;
default:
assertNever(msg);
Expand Down