@yornaath/batshit
Advanced tools
Comparing version 0.9.0 to 0.10.0
@@ -104,3 +104,3 @@ /// <reference types="node" /> | ||
*/ | ||
export declare const indexedResolver: <T extends Record<any, any>, Q>() => (itemsIndex: T, query: Q) => T[Q]; | ||
export declare const indexedResolver: <T extends Record<any, any>, Q>() => (itemsIndex: T, query: Q) => NonNullable<T[Q]> | null; | ||
/** | ||
@@ -107,0 +107,0 @@ * Give a window in ms where all queued fetched made within the window will be batched into |
@@ -88,3 +88,3 @@ import { deferred } from './deferred.esm.js'; | ||
*/ | ||
const keyResolver = (key) => (items, query) => items.find((item) => item[key] == query); | ||
const keyResolver = (key) => (items, query) => items.find((item) => item[key] == query) ?? null; | ||
/** | ||
@@ -96,3 +96,3 @@ * Resolve by record index when response is an object. | ||
*/ | ||
const indexedResolver = () => (itemsIndex, query) => itemsIndex[query]; | ||
const indexedResolver = () => (itemsIndex, query) => itemsIndex[query] ?? null; | ||
/** | ||
@@ -99,0 +99,0 @@ * Give a window in ms where all queued fetched made within the window will be batched into |
@@ -90,3 +90,3 @@ 'use strict'; | ||
*/ | ||
const keyResolver = (key) => (items, query) => items.find((item) => item[key] == query); | ||
const keyResolver = (key) => (items, query) => items.find((item) => item[key] == query) ?? null; | ||
/** | ||
@@ -98,3 +98,3 @@ * Resolve by record index when response is an object. | ||
*/ | ||
const indexedResolver = () => (itemsIndex, query) => itemsIndex[query]; | ||
const indexedResolver = () => (itemsIndex, query) => itemsIndex[query] ?? null; | ||
/** | ||
@@ -101,0 +101,0 @@ * Give a window in ms where all queued fetched made within the window will be batched into |
{ | ||
"name": "@yornaath/batshit", | ||
"version": "0.9.0", | ||
"version": "0.10.0", | ||
"description": "A batch manager that will deduplicate and batch requests for a certain data type made within a window.", | ||
@@ -34,3 +34,3 @@ "author": { | ||
"dependencies": { | ||
"@yornaath/batshit-devtools": "^1.6.0" | ||
"@yornaath/batshit-devtools": "^1.7.0" | ||
}, | ||
@@ -37,0 +37,0 @@ "scripts": { |
@@ -125,3 +125,3 @@ # @yornaath/batshit [![CI](https://github.com/yornaath/batshit/actions/workflows/ci.yml/badge.svg)](https://github.com/yornaath/batshit/actions/workflows/ci.yml) | ||
..., | ||
scheduler: maxBatchSizeScheduler({ | ||
scheduler: windowedFiniteBatchScheduler({ | ||
windowMs: 10, | ||
@@ -170,3 +170,3 @@ maxBatchSize: 100, | ||
### Fethcing with needed context | ||
### Fetching with needed context | ||
@@ -173,0 +173,0 @@ If the batch fetcher needs some context like an sdk or client to make its fetching you can use a memoizer to make sure that you reuse a batcher for the given context in the hook calls. |
@@ -197,3 +197,3 @@ import type { DevtoolsListener } from "@yornaath/batshit-devtools"; | ||
(items: T, query: Q): R => | ||
items.find((item) => item[key] == query); | ||
items.find((item) => item[key] == query) ?? null; | ||
@@ -209,3 +209,3 @@ /** | ||
(itemsIndex: T, query: Q) => | ||
itemsIndex[query]; | ||
itemsIndex[query] ?? null; | ||
@@ -212,0 +212,0 @@ /** |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
78197