mirror: A tiny/fast dataloader implementation
0

Configure Feed

Select the types of activity you want to include in your feed.

chore: import types as namespace

Marais Rossouw (Oct 19, 2023, 11:19 AM +1000) bbc3d461 30c0ab48

+5 -9
+5 -9
src/cache.ts
··· 1 - import { load as _load, type LoadFn } from 'dldr'; 1 + import * as dldr from 'dldr'; 2 2 import type { MapLike } from 'dldr/cache'; 3 3 import { identify } from 'object-identity'; 4 4 5 - const container = new WeakMap<LoadFn<any, any>, Map<string, Promise<any>>>(); 5 + const container = new WeakMap<dldr.LoadFn<any, any>, Map<string, Promise<any>>>(); 6 6 export function load<T, K = string>( 7 - loadFn: LoadFn<T, K>, 7 + loadFn: dldr.LoadFn<T, K>, 8 8 cache: MapLike<string, Promise<T>> | undefined, 9 9 key: K, 10 10 identity = identify(key), ··· 12 12 cache ||= container.get(loadFn); 13 13 if (!cache) container.set(loadFn, (cache = new Map())); 14 14 if (cache.has(identity)) return Promise.resolve(cache.get(identity)!); 15 - // @ts-expect-error 16 - const prom = _load(loadFn, key, identity); 15 + const prom = dldr.load(loadFn, key, identity); 17 16 cache.set(identity, prom); 18 17 prom.catch(() => cache!.delete(identity)); 19 18 return prom; 20 19 } 21 20 22 - export function factory<T, K = string>( 23 - loadFn: LoadFn<T, K>, 24 - cache?: MapLike<string, Promise<T>> | undefined, 25 - ): (key: K, identity?: string | undefined) => Promise<T> { 21 + export function factory<T, K = string>(loadFn: dldr.LoadFn<T, K>, cache?: MapLike<string, Promise<T>> | undefined) { 26 22 return function (key: K, identity?: string | undefined) { 27 23 return load(loadFn, cache, key, identity); 28 24 };