mirror: A tiny/fast dataloader implementation
0

Configure Feed

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

chore: adds module doc blocks

Marais Rossouw (Mar 30, 2024, 7:17 PM +1000) 02b38294 98f14762

+55 -1
+33 -1
cache/mod.ts
··· 1 - import * as dldr from '../mod.ts'; 1 + /** 2 + * @module 3 + * 4 + * This module provides a simple API for batching operations, and caching their results. You create a {@link LoadFn loader} function, and then use the {@link load} function to load values for a given key. 5 + * 6 + * @example 7 + * ```ts 8 + * async function loader(keys: string[]) { 9 + * return keys.map(key => 'foo' + key); 10 + * } 11 + * 12 + * const values = await Promise.all([ 13 + * load(loader, 'bar'), 14 + * load(loader, 'bar'), 15 + * load(loader, 'baz'), 16 + * ]); 17 + * 18 + * expect(loader).toHaveBeenCalledWith(['bar', 'baz']); 19 + * console.log(values); // ['foobar', 'foobar', 'foobaz'] 20 + * 21 + * const values = await Promise.all([ 22 + * load(loader, 'bar'), 23 + * load(loader, 'baz'), 24 + * load(loader, 'zig'), 25 + * ]); 26 + * 27 + * expect(loader).toHaveBeenCalledWith(['zig']); // bar baz have been cached 28 + * console.log(values); // ['foobar', 'foobaz', 'foozig'] 29 + * ``` 30 + */ 31 + 2 32 import { identify } from 'object-identity'; 33 + 34 + import * as dldr from '../mod.ts'; 3 35 4 36 export type MapLike<K, V> = { 5 37 get(key: K): V | undefined;
+22
mod.ts
··· 1 + /** 2 + * @module 3 + * 4 + * This module provides a simple API for batching operations. You create a {@link LoadFn loader} function, and then use the {@link load} function to load values for a given key. 5 + * 6 + * @example 7 + * ```ts 8 + * async function loader(keys: string[]) { 9 + * // expect keys to be ['bar', 'baz'] (deduped) 10 + * return keys.map(key => 'foo' + key); 11 + * } 12 + * 13 + * const values = await Promise.all([ 14 + * load(loader, 'bar'), 15 + * load(loader, 'bar'), 16 + * load(loader, 'baz'), 17 + * ]); 18 + * 19 + * console.log(values); // ['foobar', 'foobar', 'foobaz'] 20 + * ``` 21 + */ 22 + 1 23 import { identify } from 'object-identity'; 2 24 3 25 /**