mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-30 04:18:28 +08:00
d1f8b500df
* perf: better async component * feat: useFetch * chore: code clean * chore: code clean * chore: fix lint * type: enhance
22 lines
479 B
TypeScript
22 lines
479 B
TypeScript
export default class FetchCache {
|
|
private cache: Map<string, PromiseLike<any>> = new Map();
|
|
|
|
get(key: string) {
|
|
return this.cache.get(key);
|
|
}
|
|
|
|
set(key: string, value: PromiseLike<any>) {
|
|
this.cache.set(key, value);
|
|
}
|
|
|
|
promise<T>(key: string, promiseFn: () => PromiseLike<T>): PromiseLike<T> {
|
|
const cached = this.get(key);
|
|
if (cached) {
|
|
return cached;
|
|
}
|
|
const promise = promiseFn();
|
|
this.set(key, promise);
|
|
return promise;
|
|
}
|
|
}
|