Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

node scripts/sanitize-lockfiles.mjs
npx lint-staged
21 changes: 7 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pnpm add @blackrock-oss/micro-batcher

The [Examples Directory](./examples) is a great resource for learning how to setup Micro Batcher.

[Web Application](./examples/webapp) is a playground application which provides example on how to configure and integrate Micro Batcher with [Recoil's Data Fetching Pattern using Selector Family](https://recoiljs.org/docs/guides/asynchronous-data-queries/#queries-with-parameters).
[Web Application](./examples/webapp) is a playground application which provides examples on how to configure and integrate Micro Batcher, including error handling scenarios and batch resilience demonstrations.

## Usage

Expand Down Expand Up @@ -62,21 +62,14 @@ export const decoratedFetchSecurity = MicroBatcher(fetchSingleSecurity)
.build();
```

In this example, the decorated function is being used in conjunction with [Recoil's Data Fetching Pattern](https://recoiljs.org/docs/guides/asynchronous-data-queries/#queries-with-parameters) which combines the benefit of selector caching and automatic burst APIs batching.
The decorated function has the same signature as the original, so it can be used as a drop-in replacement:

```typescript
export const cusipToSecuritySelectorFamily = selectorFamily<Security, string>({
key: 'cusipToSecuritySelectorFamily',
get:
(cusip: string) =>
({ get }) => {
const enableMicroBatcher = get(enableMicroBatcherAtom);
if (enableMicroBatcher) {
return decoratedFetchSecurity(cusip);
}
return fetchSingleSecurity(cusip);
}
});
// With Micro Batcher enabled
const result = await decoratedFetchSecurity('AAPL');

// Without Micro Batcher — same signature, same result
const result = await fetchSingleSecurity('AAPL');
```

#### Other Examples
Expand Down
Loading
Loading