Skip to content

Commit

Permalink
Updated collects docs
Browse files Browse the repository at this point in the history
Refs: #221
  • Loading branch information
axbuglak authored Dec 17, 2024
1 parent d2368a4 commit 0521125
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,25 @@ Async collection is an utility to collect needed keys and signalize on done.
- `options.exact?: boolean`
- `options.timeout?: number`
- `options.reassign?: boolean`
- `options.defaults?: object`
- `options.validate?: (data: Record<string, unknown>) => unknown`
- `set(key: string, value: unknown)`
- `wait(key: string, fn: AsyncFunction | Promise<unknown>, ...args?: Array<unknown>)`
- `take(key: string, fn: Function, ...args?: Array<unknown>)`
- `collect(sources: Record<string, Collector>)`
- `fail(error: Error)`
- `then(fulfill: Function, reject?: Function)`
- `abort()`
- `then(onFulfill: Function, onReject?: Function)`
- `done: boolean`
- `data: Dictionary`
- `keys: Array<string>`
- `count: number`
- `exact: boolean`
- `timeout: number`
- `defaults: object`
- `reassign: boolean`
- `validate?: (data: Record<string, unknown>) => unknown`
- `signal: AbortSignal`

Collect keys with `.set` method:

Expand Down Expand Up @@ -84,6 +91,17 @@ ac.take('user', getUserCallback, 'Marcus');
const result = await ac;
```

Set default values ​​for unset keys using the `options.defaults` argument:

```js
const defaults = { key1: 'sub1', key2: 'sub1' };

const dc = collect(['key1', 'key2'], { defaults, timeout: 2000 });
dc.set('key2', 'sub2');

const result = await dc;
```

Compose collectors (collect subkeys from multiple sources):

```js
Expand Down

0 comments on commit 0521125

Please sign in to comment.