Skip to content

Commit

Permalink
chore: adds module doc blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
maraisr committed Mar 30, 2024
1 parent 98f1476 commit 02b3829
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
34 changes: 33 additions & 1 deletion cache/mod.ts
@@ -1,6 +1,38 @@
import * as dldr from '../mod.ts';
/**
* @module
*
* 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.
*
* @example
* ```ts
* async function loader(keys: string[]) {
* return keys.map(key => 'foo' + key);
* }
*
* const values = await Promise.all([
* load(loader, 'bar'),
* load(loader, 'bar'),
* load(loader, 'baz'),
* ]);
*
* expect(loader).toHaveBeenCalledWith(['bar', 'baz']);
* console.log(values); // ['foobar', 'foobar', 'foobaz']
*
* const values = await Promise.all([
* load(loader, 'bar'),
* load(loader, 'baz'),
* load(loader, 'zig'),
* ]);
*
* expect(loader).toHaveBeenCalledWith(['zig']); // bar baz have been cached
* console.log(values); // ['foobar', 'foobaz', 'foozig']
* ```
*/

import { identify } from 'object-identity';

import * as dldr from '../mod.ts';

export type MapLike<K, V> = {
get(key: K): V | undefined;
set(key: K, value: V): void;
Expand Down
22 changes: 22 additions & 0 deletions mod.ts
@@ -1,3 +1,25 @@
/**
* @module
*
* 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.
*
* @example
* ```ts
* async function loader(keys: string[]) {
* // expect keys to be ['bar', 'baz'] (deduped)
* return keys.map(key => 'foo' + key);
* }
*
* const values = await Promise.all([
* load(loader, 'bar'),
* load(loader, 'bar'),
* load(loader, 'baz'),
* ]);
*
* console.log(values); // ['foobar', 'foobar', 'foobaz']
* ```
*/

import { identify } from 'object-identity';

/**
Expand Down

0 comments on commit 02b3829

Please sign in to comment.