mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
feat: discrimination
This commit is contained in:
1 parent
e7337145d2
commit
44711a58c7
2 files changed
+4
-4
No files matched your search
@@ -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>();
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user