feat: discrimination

This commit is contained in:
TrèsAbhi committed 2026-03-20 20:40:45 -05:00
1 parent e7337145d2
commit 44711a58c7
2 files changed
+4 -4

No files matched your search

+3 -3
View File
@@ -165,8 +165,8 @@ export abstract class AbstractAPI {
}
}
export function Cache(
discriminator: (...args: unknown[]) => string = () => "",
export function Cache<Arguments extends unknown[]>(
discriminator: (...args: Arguments) => string = () => "",
) {
const cache = new WeakMap<object, Map<string, unknown>>();
@@ -177,7 +177,7 @@ export function Cache(
) {
const original = descriptor.value;
descriptor.value = async function (...args: unknown[]) {
descriptor.value = async function (...args: Arguments) {
const key = discriminator(...args);
const thisCache = cache.get(this) ?? new Map<string, unknown>();
+1 -1
View File
@@ -168,7 +168,7 @@ export class ServerAPI extends AbstractAPI {
return data;
}
@Cache((id) => id)
@Cache<[string]>((id) => id)
async tank(id: string) {
const tankList = await this.tankList();
const tankListEntry = tankList.list.find((tank) => tank.id === id);