diff --git a/.changeset/yellow-eggs-smoke.md b/.changeset/yellow-eggs-smoke.md new file mode 100644 index 00000000..bfd6009c --- /dev/null +++ b/.changeset/yellow-eggs-smoke.md @@ -0,0 +1,13 @@ +--- +'@tanstack/preact-pacer-devtools': minor +'@tanstack/react-pacer-devtools': minor +'@tanstack/solid-pacer-devtools': minor +'@tanstack/pacer-devtools': minor +'@tanstack/preact-pacer': minor +'@tanstack/react-pacer': minor +'@tanstack/solid-pacer': minor +'@tanstack/pacer-lite': minor +'@tanstack/pacer': minor +--- + +feat: add preact adapter\ diff --git a/README.md b/README.md index 42347dcc..5a42510f 100644 --- a/README.md +++ b/README.md @@ -89,9 +89,9 @@ A lightweight timing and scheduling library for debouncing, throttling, rate lim > You may know **TanSack Pacer** by our adapter names, too! > > - [**React Pacer**](https://tanstack.com/pacer/latest/docs/framework/react/react-pacer) +> - [**Preact Pacer**](https://tanstack.com/pacer/latest/docs/framework/preact/preact-pacer) > - [**Solid Pacer**](https://tanstack.com/pacer/latest/docs/framework/solid/solid-pacer) > - Angular Pacer - needs a contributor! -> - Preact Pacer - Coming soon! (After React Pacer is more fleshed out) > - Svelte Pacer - needs a contributor! > - Vue Pacer - needs a contributor! diff --git a/docs/config.json b/docs/config.json index bea3d7bd..88c30a79 100644 --- a/docs/config.json +++ b/docs/config.json @@ -44,6 +44,15 @@ "to": "framework/solid/adapter" } ] + }, + { + "label": "preact", + "children": [ + { + "label": "Preact Adapter", + "to": "framework/preact/adapter" + } + ] } ] }, @@ -126,6 +135,15 @@ "to": "framework/solid/reference/index" } ] + }, + { + "label": "preact", + "children": [ + { + "label": "Preact Hooks", + "to": "framework/preact/reference/index" + } + ] } ] }, @@ -233,6 +251,43 @@ "to": "framework/solid/reference/functions/createAsyncDebouncer" } ] + }, + { + "label": "preact", + "children": [ + { + "label": "PreactDebouncer", + "to": "framework/preact/reference/interfaces/PreactDebouncer" + }, + { + "label": "PreactAsyncDebouncer", + "to": "framework/preact/reference/interfaces/PreactAsyncDebouncer" + }, + { + "label": "useDebouncer", + "to": "framework/preact/reference/functions/useDebouncer" + }, + { + "label": "useDebouncedCallback", + "to": "framework/preact/reference/functions/useDebouncedCallback" + }, + { + "label": "useDebouncedState", + "to": "framework/preact/reference/functions/useDebouncedState" + }, + { + "label": "useDebouncedValue", + "to": "framework/preact/reference/functions/useDebouncedValue" + }, + { + "label": "useAsyncDebouncer", + "to": "framework/preact/reference/functions/useAsyncDebouncer" + }, + { + "label": "useAsyncDebouncedCallback", + "to": "framework/preact/reference/functions/useAsyncDebouncedCallback" + } + ] } ] }, @@ -340,6 +395,43 @@ "to": "framework/solid/reference/functions/createAsyncThrottler" } ] + }, + { + "label": "preact", + "children": [ + { + "label": "PreactThrottler", + "to": "framework/preact/reference/interfaces/PreactThrottler" + }, + { + "label": "PreactAsyncThrottler", + "to": "framework/preact/reference/interfaces/PreactAsyncThrottler" + }, + { + "label": "useThrottler", + "to": "framework/preact/reference/functions/useThrottler" + }, + { + "label": "useThrottledCallback", + "to": "framework/preact/reference/functions/useThrottledCallback" + }, + { + "label": "useThrottledState", + "to": "framework/preact/reference/functions/useThrottledState" + }, + { + "label": "useThrottledValue", + "to": "framework/preact/reference/functions/useThrottledValue" + }, + { + "label": "useAsyncThrottler", + "to": "framework/preact/reference/functions/useAsyncThrottler" + }, + { + "label": "useAsyncThrottledCallback", + "to": "framework/preact/reference/functions/useAsyncThrottledCallback" + } + ] } ] }, @@ -447,6 +539,43 @@ "to": "framework/solid/reference/functions/createAsyncRateLimiter" } ] + }, + { + "label": "preact", + "children": [ + { + "label": "PreactRateLimiter", + "to": "framework/preact/reference/interfaces/PreactRateLimiter" + }, + { + "label": "PreactAsyncRateLimiter", + "to": "framework/preact/reference/interfaces/PreactAsyncRateLimiter" + }, + { + "label": "useRateLimiter", + "to": "framework/preact/reference/functions/useRateLimiter" + }, + { + "label": "useRateLimitedCallback", + "to": "framework/preact/reference/functions/useRateLimitedCallback" + }, + { + "label": "useRateLimitedState", + "to": "framework/preact/reference/functions/useRateLimitedState" + }, + { + "label": "useRateLimitedValue", + "to": "framework/preact/reference/functions/useRateLimitedValue" + }, + { + "label": "useAsyncRateLimiter", + "to": "framework/preact/reference/functions/useAsyncRateLimiter" + }, + { + "label": "useAsyncRateLimitedCallback", + "to": "framework/preact/reference/functions/useAsyncRateLimitedCallback" + } + ] } ] }, @@ -546,6 +675,39 @@ "to": "framework/solid/reference/functions/createQueuedSignal" } ] + }, + { + "label": "preact", + "children": [ + { + "label": "PreactQueuer", + "to": "framework/preact/reference/interfaces/PreactQueuer" + }, + { + "label": "PreactAsyncQueuer", + "to": "framework/preact/reference/interfaces/PreactAsyncQueuer" + }, + { + "label": "useQueuer", + "to": "framework/preact/reference/functions/useQueuer" + }, + { + "label": "useQueuedState", + "to": "framework/preact/reference/functions/useQueuedState" + }, + { + "label": "useQueuedValue", + "to": "framework/preact/reference/functions/useQueuedValue" + }, + { + "label": "useAsyncQueuer", + "to": "framework/preact/reference/functions/useAsyncQueuer" + }, + { + "label": "useAsyncQueuedState", + "to": "framework/preact/reference/functions/useAsyncQueuedState" + } + ] } ] }, @@ -637,6 +799,35 @@ "to": "framework/solid/reference/functions/createAsyncBatcher" } ] + }, + { + "label": "preact", + "children": [ + { + "label": "PreactBatcher", + "to": "framework/preact/reference/interfaces/PreactBatcher" + }, + { + "label": "PreactAsyncBatcher", + "to": "framework/preact/reference/interfaces/PreactAsyncBatcher" + }, + { + "label": "useBatcher", + "to": "framework/preact/reference/functions/useBatcher" + }, + { + "label": "useAsyncBatcher", + "to": "framework/preact/reference/functions/useAsyncBatcher" + }, + { + "label": "useBatchedCallback", + "to": "framework/preact/reference/functions/useBatchedCallback" + }, + { + "label": "useAsyncBatchedCallback", + "to": "framework/preact/reference/functions/useAsyncBatchedCallback" + } + ] } ] }, @@ -718,6 +909,43 @@ "to": "framework/solid/examples/createAsyncDebouncer" } ] + }, + { + "label": "preact", + "children": [ + { + "label": "debounce", + "to": "framework/preact/examples/debounce" + }, + { + "label": "asyncDebounce", + "to": "framework/preact/examples/asyncDebounce" + }, + { + "label": "useDebouncer", + "to": "framework/preact/examples/useDebouncer" + }, + { + "label": "useDebouncedCallback", + "to": "framework/preact/examples/useDebouncedCallback" + }, + { + "label": "useDebouncedState", + "to": "framework/preact/examples/useDebouncedState" + }, + { + "label": "useDebouncedValue", + "to": "framework/preact/examples/useDebouncedValue" + }, + { + "label": "useAsyncDebouncer", + "to": "framework/preact/examples/useAsyncDebouncer" + }, + { + "label": "useAsyncDebouncedCallback", + "to": "framework/preact/examples/useAsyncDebouncedCallback" + } + ] } ] }, @@ -795,6 +1023,43 @@ "to": "framework/solid/examples/createAsyncThrottler" } ] + }, + { + "label": "preact", + "children": [ + { + "label": "throttle", + "to": "framework/preact/examples/throttle" + }, + { + "label": "asyncThrottle", + "to": "framework/preact/examples/asyncThrottle" + }, + { + "label": "useThrottler", + "to": "framework/preact/examples/useThrottler" + }, + { + "label": "useThrottledCallback", + "to": "framework/preact/examples/useThrottledCallback" + }, + { + "label": "useThrottledState", + "to": "framework/preact/examples/useThrottledState" + }, + { + "label": "useThrottledValue", + "to": "framework/preact/examples/useThrottledValue" + }, + { + "label": "useAsyncThrottler", + "to": "framework/preact/examples/useAsyncThrottler" + }, + { + "label": "useAsyncThrottledCallback", + "to": "framework/preact/examples/useAsyncThrottledCallback" + } + ] } ] }, @@ -880,6 +1145,47 @@ "to": "framework/solid/examples/createAsyncRateLimiter" } ] + }, + { + "label": "preact", + "children": [ + { + "label": "rateLimit", + "to": "framework/preact/examples/rateLimit" + }, + { + "label": "asyncRateLimit", + "to": "framework/preact/examples/asyncRateLimit" + }, + { + "label": "useRateLimiter", + "to": "framework/preact/examples/useRateLimiter" + }, + { + "label": "useRateLimiterWithPersister", + "to": "framework/preact/examples/useRateLimiterWithPersister" + }, + { + "label": "useRateLimitedCallback", + "to": "framework/preact/examples/useRateLimitedCallback" + }, + { + "label": "useRateLimitedState", + "to": "framework/preact/examples/useRateLimitedState" + }, + { + "label": "useRateLimitedValue", + "to": "framework/preact/examples/useRateLimitedValue" + }, + { + "label": "useAsyncRateLimiter", + "to": "framework/preact/examples/useAsyncRateLimiter" + }, + { + "label": "useAsyncRateLimiterWithPersister", + "to": "framework/preact/examples/useAsyncRateLimiterWithPersister" + } + ] } ] }, @@ -949,6 +1255,39 @@ "to": "framework/solid/examples/createQueuedSignal" } ] + }, + { + "label": "preact", + "children": [ + { + "label": "queue", + "to": "framework/preact/examples/queue" + }, + { + "label": "useQueuer", + "to": "framework/preact/examples/useQueuer" + }, + { + "label": "useQueuerWithPersister", + "to": "framework/preact/examples/useQueuerWithPersister" + }, + { + "label": "useQueuedState", + "to": "framework/preact/examples/useQueuedState" + }, + { + "label": "useQueuedValue", + "to": "framework/preact/examples/useQueuedValue" + }, + { + "label": "useAsyncQueuer", + "to": "framework/preact/examples/useAsyncQueuer" + }, + { + "label": "useAsyncQueuedState", + "to": "framework/preact/examples/useAsyncQueuedState" + } + ] } ] }, @@ -1010,6 +1349,35 @@ "to": "framework/solid/examples/createAsyncBatcher" } ] + }, + { + "label": "preact", + "children": [ + { + "label": "batch", + "to": "framework/preact/examples/batch" + }, + { + "label": "asyncBatch", + "to": "framework/preact/examples/asyncBatch" + }, + { + "label": "useBatcher", + "to": "framework/preact/examples/useBatcher" + }, + { + "label": "useAsyncBatcher", + "to": "framework/preact/examples/useAsyncBatcher" + }, + { + "label": "useBatchedCallback", + "to": "framework/preact/examples/useBatchedCallback" + }, + { + "label": "useAsyncBatchedCallback", + "to": "framework/preact/examples/useAsyncBatchedCallback" + } + ] } ] }, diff --git a/docs/framework/preact/adapter.md b/docs/framework/preact/adapter.md new file mode 100644 index 00000000..e8e708b5 --- /dev/null +++ b/docs/framework/preact/adapter.md @@ -0,0 +1,208 @@ +--- +title: TanStack Pacer Preact Adapter +id: adapter +--- + +If you are using TanStack Pacer in a Preact application, we recommend using the Preact Adapter. The Preact Adapter provides a set of easy-to-use hooks on top of the core Pacer utilities. If you find yourself wanting to use the core Pacer classes/functions directly, the Preact Adapter will also re-export everything from the core package. + +## Installation + +```sh +npm install @tanstack/preact-pacer +``` + +## Preact Hooks + +See the [Preact Functions Reference](./reference/index.md) to see the full list of hooks available in the Preact Adapter. + +## Basic Usage + +Import a preact specific hook from the Preact Adapter. + +```tsx +import { useDebouncedValue } from '@tanstack/preact-pacer' +import { useState } from 'preact/hooks' + +const [instantValue, setInstantValue] = useState(0) +const [debouncedValue, debouncer] = useDebouncedValue(instantValue, { + wait: 1000, +}) +``` + +Or import a core Pacer class/function that is re-exported from the Preact Adapter. + +```tsx +import { debounce, Debouncer } from '@tanstack/preact-pacer' // no need to install the core package separately +``` + +## Option Helpers + +If you want a type-safe way to define common options for pacer utilities, TanStack Pacer provides option helpers for each utility. These helpers can be used with Preact hooks. + +### Debouncer Options + +```tsx +import { useDebouncer } from '@tanstack/preact-pacer' +import { debouncerOptions } from '@tanstack/pacer' + +const commonDebouncerOptions = debouncerOptions({ + wait: 1000, + leading: false, + trailing: true, +}) + +const debouncer = useDebouncer( + (query: string) => fetchSearchResults(query), + { ...commonDebouncerOptions, key: 'searchDebouncer' } +) +``` + +### Queuer Options + +```tsx +import { useQueuer } from '@tanstack/preact-pacer' +import { queuerOptions } from '@tanstack/pacer' + +const commonQueuerOptions = queuerOptions({ + concurrency: 3, + addItemsTo: 'back', +}) + +const queuer = useQueuer( + (item: string) => processItem(item), + { ...commonQueuerOptions, key: 'itemQueuer' } +) +``` + +### Rate Limiter Options + +```tsx +import { useRateLimiter } from '@tanstack/preact-pacer' +import { rateLimiterOptions } from '@tanstack/pacer' + +const commonRateLimiterOptions = rateLimiterOptions({ + limit: 5, + window: 60000, + windowType: 'sliding', +}) + +const rateLimiter = useRateLimiter( + (data: string) => sendApiRequest(data), + { ...commonRateLimiterOptions, key: 'apiRateLimiter' } +) +``` + +## Provider + +The Preact Adapter provides a `PacerProvider` component that you can use to provide default options to all instances of pacer utilities within your component tree. + +```tsx +import { PacerProvider } from '@tanstack/preact-pacer' + +// Set default options for preact-pacer instances + + + +``` + +All hooks within the provider will automatically use these default options, which can be overridden on a per-hook basis. + +## Examples + +### Debouncer Example + +```tsx +import { useDebouncer } from '@tanstack/preact-pacer' + +function SearchComponent() { + const debouncer = useDebouncer( + (query: string) => { + console.log('Searching for:', query) + // Perform search + }, + { wait: 500 } + ) + + return ( + debouncer.maybeExecute(e.target.value)} + placeholder="Search..." + /> + ) +} +``` + +### Queuer Example + +```tsx +import { useQueuer } from '@tanstack/preact-pacer' + +function UploadComponent() { + const queuer = useQueuer( + async (file: File) => { + await uploadFile(file) + }, + { concurrency: 3 } + ) + + const handleFileSelect = (files: FileList) => { + Array.from(files).forEach((file) => { + queuer.addItem(file) + }) + } + + return ( + { + if (e.target.files) { + handleFileSelect(e.target.files) + } + }} + /> + ) +} +``` + +### Rate Limiter Example + +```tsx +import { useRateLimiter } from '@tanstack/preact-pacer' + +function ApiComponent() { + const rateLimiter = useRateLimiter( + (data: string) => { + return fetch('/api/endpoint', { + method: 'POST', + body: JSON.stringify({ data }), + }) + }, + { + limit: 5, + window: 60000, + windowType: 'sliding', + onReject: () => { + alert('Rate limit reached. Please try again later.') + }, + } + ) + + const handleSubmit = () => { + const remaining = rateLimiter.getRemainingInWindow() + if (remaining > 0) { + rateLimiter.maybeExecute('some data') + } + } + + return +} +``` + + diff --git a/docs/framework/preact/reference/functions/PacerProvider.md b/docs/framework/preact/reference/functions/PacerProvider.md new file mode 100644 index 00000000..cc5190e6 --- /dev/null +++ b/docs/framework/preact/reference/functions/PacerProvider.md @@ -0,0 +1,22 @@ +--- +id: PacerProvider +title: PacerProvider +--- + +# Function: PacerProvider() + +```ts +function PacerProvider(__namedParameters): Element; +``` + +Defined in: [preact-pacer/src/provider/PacerProvider.tsx:45](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/provider/PacerProvider.tsx#L45) + +## Parameters + +### \_\_namedParameters + +[`PacerProviderProps`](../interfaces/PacerProviderProps.md) + +## Returns + +`Element` diff --git a/docs/framework/preact/reference/functions/useAsyncBatchedCallback.md b/docs/framework/preact/reference/functions/useAsyncBatchedCallback.md new file mode 100644 index 00000000..f7061072 --- /dev/null +++ b/docs/framework/preact/reference/functions/useAsyncBatchedCallback.md @@ -0,0 +1,81 @@ +--- +id: useAsyncBatchedCallback +title: useAsyncBatchedCallback +--- + +# Function: useAsyncBatchedCallback() + +```ts +function useAsyncBatchedCallback(fn, options): (...args) => Promise; +``` + +Defined in: [preact-pacer/src/async-batcher/useAsyncBatchedCallback.ts:43](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-batcher/useAsyncBatchedCallback.ts#L43) + +A Preact hook that creates a batched version of an async callback function. +This hook is a convenient wrapper around the `useAsyncBatcher` hook, +providing a stable, batched async function reference for use in Preact components. + +The batched async function will collect individual calls into batches and execute them +when batch conditions are met (max size reached, wait time elapsed, or custom logic). +The returned function always returns a promise that resolves with undefined (since the +batch function processes multiple items together). + +This hook provides a simpler API compared to `useAsyncBatcher`, making it ideal for basic +async batching needs. However, it does not expose the underlying AsyncBatcher instance. + +For advanced usage requiring features like: +- Manual batch execution +- Access to batch results and state +- Custom useCallback dependencies + +Consider using the `useAsyncBatcher` hook instead. + +## Type Parameters + +### TFn + +`TFn` *extends* `AnyAsyncFunction` + +## Parameters + +### fn + +(`items`) => `Promise`\<`any`\> + +### options + +`AsyncBatcherOptions`\<`Parameters`\<`TFn`\>\[`0`\]\> + +## Returns + +```ts +(...args): Promise; +``` + +### Parameters + +#### args + +...`Parameters`\<`TFn`\> + +### Returns + +`Promise`\<`void`\> + +## Example + +```tsx +// Batch API requests +const batchApiCall = useAsyncBatchedCallback(async (requests: ApiRequest[]) => { + const results = await Promise.all(requests.map(req => fetch(req.url))); + return results.map(res => res.json()); +}, { + maxSize: 10, // Process when 10 requests collected + wait: 1000 // Or after 1 second +}); + +// Use in event handlers + +``` diff --git a/docs/framework/preact/reference/functions/useAsyncBatcher.md b/docs/framework/preact/reference/functions/useAsyncBatcher.md new file mode 100644 index 00000000..842f9934 --- /dev/null +++ b/docs/framework/preact/reference/functions/useAsyncBatcher.md @@ -0,0 +1,185 @@ +--- +id: useAsyncBatcher +title: useAsyncBatcher +--- + +# Function: useAsyncBatcher() + +```ts +function useAsyncBatcher( + fn, + options, +selector): ReactAsyncBatcher; +``` + +Defined in: [preact-pacer/src/async-batcher/useAsyncBatcher.ts:170](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-batcher/useAsyncBatcher.ts#L170) + +A Preact hook that creates an `AsyncBatcher` instance for managing asynchronous batches of items. + +This is the async version of the useBatcher hook. Unlike the sync version, this async batcher: +- Handles promises and returns results from batch executions +- Provides error handling with configurable error behavior +- Tracks success, error, and settle counts separately +- Has state tracking for when batches are executing +- Returns the result of the batch function execution + +Features: +- Configurable batch size and wait time +- Custom batch processing logic via getShouldExecute +- Event callbacks for monitoring batch operations +- Error handling for failed batch operations +- Automatic or manual batch processing + +The batcher collects items and processes them in batches based on: +- Maximum batch size (number of items per batch) +- Time-based batching (process after X milliseconds) +- Custom batch processing logic via getShouldExecute + +Error Handling: +- If an `onError` handler is provided, it will be called with the error and batcher instance +- If `throwOnError` is true (default when no onError handler is provided), the error will be thrown +- If `throwOnError` is false (default when onError handler is provided), the error will be swallowed +- Both onError and throwOnError can be used together - the handler will be called before any error is thrown +- The error state can be checked using the underlying AsyncBatcher instance + +## State Management and Selector + +The hook uses TanStack Store for reactive state management. The `selector` parameter allows you +to specify which state changes will trigger a re-render, optimizing performance by preventing +unnecessary re-renders when irrelevant state changes occur. + +**By default, there will be no reactive state subscriptions** and you must opt-in to state +tracking by providing a selector function. This prevents unnecessary re-renders and gives you +full control over when your component updates. Only when you provide a selector will the +component re-render when the selected state values change. + +Available state properties: +- `errorCount`: Number of batch executions that have resulted in errors +- `failedItems`: Array of items that failed during batch processing +- `isEmpty`: Whether the batcher has no items to process +- `isExecuting`: Whether a batch is currently being processed asynchronously +- `isPending`: Whether the batcher is waiting for the timeout to trigger batch processing +- `isRunning`: Whether the batcher is active and will process items automatically +- `items`: Array of items currently queued for batch processing +- `lastResult`: The result from the most recent batch execution +- `settleCount`: Number of batch executions that have completed (success or error) +- `size`: Number of items currently in the batch queue +- `status`: Current processing status ('idle' | 'pending' | 'executing' | 'populated') +- `successCount`: Number of batch executions that have completed successfully +- `totalItemsProcessed`: Total number of items processed across all batches +- `totalItemsFailed`: Total number of items that have failed processing + +## Type Parameters + +### TValue + +`TValue` + +### TSelected + +`TSelected` = \{ +\} + +## Parameters + +### fn + +(`items`) => `Promise`\<`any`\> + +### options + +`AsyncBatcherOptions`\<`TValue`\> = `{}` + +### selector + +(`state`) => `TSelected` + +## Returns + +[`ReactAsyncBatcher`](../interfaces/ReactAsyncBatcher.md)\<`TValue`, `TSelected`\> + +## Example + +```tsx +// Basic async batcher for API requests - no reactive state subscriptions +const asyncBatcher = useAsyncBatcher( + async (items) => { + const results = await Promise.all(items.map(item => processItem(item))); + return results; + }, + { maxSize: 10, wait: 2000 } +); + +// Opt-in to re-render when execution state changes (optimized for loading indicators) +const asyncBatcher = useAsyncBatcher( + async (items) => { + const results = await Promise.all(items.map(item => processItem(item))); + return results; + }, + { maxSize: 10, wait: 2000 }, + (state) => ({ + isExecuting: state.isExecuting, + isPending: state.isPending, + status: state.status + }) +); + +// Opt-in to re-render when results are available (optimized for data display) +const asyncBatcher = useAsyncBatcher( + async (items) => { + const results = await Promise.all(items.map(item => processItem(item))); + return results; + }, + { maxSize: 10, wait: 2000 }, + (state) => ({ + lastResult: state.lastResult, + successCount: state.successCount, + totalItemsProcessed: state.totalItemsProcessed + }) +); + +// Opt-in to re-render when error state changes (optimized for error handling) +const asyncBatcher = useAsyncBatcher( + async (items) => { + const results = await Promise.all(items.map(item => processItem(item))); + return results; + }, + { + maxSize: 10, + wait: 2000, + onError: (error) => console.error('Batch processing failed:', error) + }, + (state) => ({ + errorCount: state.errorCount, + failedItems: state.failedItems, + totalItemsFailed: state.totalItemsFailed + }) +); + +// Complete example with all callbacks +const asyncBatcher = useAsyncBatcher( + async (items) => { + const results = await Promise.all(items.map(item => processItem(item))); + return results; + }, + { + maxSize: 10, + wait: 2000, + onSuccess: (result) => { + console.log('Batch processed successfully:', result); + }, + onError: (error) => { + console.error('Batch processing failed:', error); + } + } +); + +// Add items to batch +asyncBatcher.addItem(newItem); + +// Manually execute batch +const result = await asyncBatcher.execute(); + +// Access the selected state (will be empty object {} unless selector provided) +const { isExecuting, lastResult, size } = asyncBatcher.state; +``` diff --git a/docs/framework/preact/reference/functions/useAsyncDebouncedCallback.md b/docs/framework/preact/reference/functions/useAsyncDebouncedCallback.md new file mode 100644 index 00000000..eded4f34 --- /dev/null +++ b/docs/framework/preact/reference/functions/useAsyncDebouncedCallback.md @@ -0,0 +1,81 @@ +--- +id: useAsyncDebouncedCallback +title: useAsyncDebouncedCallback +--- + +# Function: useAsyncDebouncedCallback() + +```ts +function useAsyncDebouncedCallback(fn, options): (...args) => Promise>; +``` + +Defined in: [preact-pacer/src/async-debouncer/useAsyncDebouncedCallback.ts:44](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-debouncer/useAsyncDebouncedCallback.ts#L44) + +A Preact hook that creates a debounced version of an async callback function. +This hook is a convenient wrapper around the `useAsyncDebouncer` hook, +providing a stable, debounced async function reference for use in Preact components. + +The debounced async function will only execute after the specified wait time has elapsed +since its last invocation. If called again before the wait time expires, the timer +resets and starts waiting again. The returned function always returns a promise +that resolves or rejects with the result of the original async function. + +This hook provides a simpler API compared to `useAsyncDebouncer`, making it ideal for basic +async debouncing needs. However, it does not expose the underlying AsyncDebouncer instance. + +For advanced usage requiring features like: +- Manual cancellation +- Access to execution/error state +- Custom useCallback dependencies + +Consider using the `useAsyncDebouncer` hook instead. + +## Type Parameters + +### TFn + +`TFn` *extends* `AnyAsyncFunction` + +## Parameters + +### fn + +`TFn` + +### options + +`AsyncDebouncerOptions`\<`TFn`\> + +## Returns + +```ts +(...args): Promise>; +``` + +### Parameters + +#### args + +...`Parameters`\<`TFn`\> + +### Returns + +`Promise`\<`ReturnType`\<`TFn`\>\> + +## Example + +```tsx +// Debounce an async search handler +const handleSearch = useAsyncDebouncedCallback(async (query: string) => { + const results = await fetchSearchResults(query); + return results; +}, { + wait: 500 // Wait 500ms between executions +}); + +// Use in an input + handleSearch(e.target.value)} +/> +``` diff --git a/docs/framework/preact/reference/functions/useAsyncDebouncer.md b/docs/framework/preact/reference/functions/useAsyncDebouncer.md new file mode 100644 index 00000000..1ad48823 --- /dev/null +++ b/docs/framework/preact/reference/functions/useAsyncDebouncer.md @@ -0,0 +1,164 @@ +--- +id: useAsyncDebouncer +title: useAsyncDebouncer +--- + +# Function: useAsyncDebouncer() + +```ts +function useAsyncDebouncer( + fn, + options, +selector): ReactAsyncDebouncer; +``` + +Defined in: [preact-pacer/src/async-debouncer/useAsyncDebouncer.ts:150](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-debouncer/useAsyncDebouncer.ts#L150) + +A low-level Preact hook that creates an `AsyncDebouncer` instance to delay execution of an async function. + +This hook is designed to be flexible and state-management agnostic - it simply returns a debouncer instance that +you can integrate with any state management solution (useState, Redux, Zustand, Jotai, etc). + +Async debouncing ensures that an async function only executes after a specified delay has passed since its last invocation. +Each new invocation resets the delay timer. This is useful for handling frequent events like window resizing +or input changes where you only want to execute the handler after the events have stopped occurring. + +Unlike throttling which allows execution at regular intervals, debouncing prevents any execution until +the function stops being called for the specified delay period. + +Unlike the non-async Debouncer, this async version supports returning values from the debounced function, +making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call +instead of setting the result on a state variable from within the debounced function. + +Error Handling: +- If an `onError` handler is provided, it will be called with the error and debouncer instance +- If `throwOnError` is true (default when no onError handler is provided), the error will be thrown +- If `throwOnError` is false (default when onError handler is provided), the error will be swallowed +- Both onError and throwOnError can be used together - the handler will be called before any error is thrown +- The error state can be checked using the underlying AsyncDebouncer instance + +## State Management and Selector + +The hook uses TanStack Store for reactive state management. The `selector` parameter allows you +to specify which state changes will trigger a re-render, optimizing performance by preventing +unnecessary re-renders when irrelevant state changes occur. + +**By default, there will be no reactive state subscriptions** and you must opt-in to state +tracking by providing a selector function. This prevents unnecessary re-renders and gives you +full control over when your component updates. Only when you provide a selector will the +component re-render when the selected state values change. + +Available state properties: +- `canLeadingExecute`: Whether the debouncer can execute on the leading edge +- `errorCount`: Number of function executions that have resulted in errors +- `isExecuting`: Whether the debounced function is currently executing asynchronously +- `isPending`: Whether the debouncer is waiting for the timeout to trigger execution +- `lastArgs`: The arguments from the most recent call to maybeExecute +- `lastResult`: The result from the most recent successful function execution +- `settleCount`: Number of function executions that have completed (success or error) +- `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing' | 'settled') +- `successCount`: Number of function executions that have completed successfully + +## Type Parameters + +### TFn + +`TFn` *extends* `AnyAsyncFunction` + +### TSelected + +`TSelected` = \{ +\} + +## Parameters + +### fn + +`TFn` + +### options + +`AsyncDebouncerOptions`\<`TFn`\> + +### selector + +(`state`) => `TSelected` + +## Returns + +[`ReactAsyncDebouncer`](../interfaces/ReactAsyncDebouncer.md)\<`TFn`, `TSelected`\> + +## Example + +```tsx +// Default behavior - no reactive state subscriptions +const searchDebouncer = useAsyncDebouncer( + async (query: string) => { + const results = await api.search(query); + return results; + }, + { wait: 500 } +); + +// Opt-in to re-render when execution state changes (optimized for loading indicators) +const searchDebouncer = useAsyncDebouncer( + async (query: string) => { + const results = await api.search(query); + return results; + }, + { wait: 500 }, + (state) => ({ + isExecuting: state.isExecuting, + isPending: state.isPending + }) +); + +// Opt-in to re-render when results are available (optimized for data display) +const searchDebouncer = useAsyncDebouncer( + async (query: string) => { + const results = await api.search(query); + return results; + }, + { wait: 500 }, + (state) => ({ + lastResult: state.lastResult, + successCount: state.successCount + }) +); + +// Opt-in to re-render when error state changes (optimized for error handling) +const searchDebouncer = useAsyncDebouncer( + async (query: string) => { + const results = await api.search(query); + return results; + }, + { + wait: 500, + onError: (error) => console.error('Search failed:', error) + }, + (state) => ({ + errorCount: state.errorCount, + status: state.status + }) +); + +// With state management +const [results, setResults] = useState([]); +const { maybeExecute, state } = useAsyncDebouncer( + async (searchTerm) => { + const data = await searchAPI(searchTerm); + setResults(data); + }, + { + wait: 300, + leading: true, // Execute immediately on first call + trailing: false, // Skip trailing edge updates + onError: (error) => { + console.error('API call failed:', error); + } + } +); + +// Access the selected state (will be empty object {} unless selector provided) +const { isExecuting, lastResult } = state; +``` diff --git a/docs/framework/preact/reference/functions/useAsyncQueuedState.md b/docs/framework/preact/reference/functions/useAsyncQueuedState.md new file mode 100644 index 00000000..a473950c --- /dev/null +++ b/docs/framework/preact/reference/functions/useAsyncQueuedState.md @@ -0,0 +1,186 @@ +--- +id: useAsyncQueuedState +title: useAsyncQueuedState +--- + +# Function: useAsyncQueuedState() + +```ts +function useAsyncQueuedState( + fn, + options, + selector?): [TValue[], ReactAsyncQueuer]; +``` + +Defined in: [preact-pacer/src/async-queuer/useAsyncQueuedState.ts:151](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-queuer/useAsyncQueuedState.ts#L151) + +A higher-level Preact hook that creates an `AsyncQueuer` instance with built-in state management. + +This hook combines an AsyncQueuer with Preact state to automatically track the queue items. +It returns a tuple containing: +- The current array of queued items as Preact state +- The queuer instance with methods to control the queue + +The queue can be configured with: +- Maximum concurrent operations +- Maximum queue size +- Processing function for queue items +- Various lifecycle callbacks + +The state will automatically update whenever items are: +- Added to the queue +- Removed from the queue +- Started processing +- Completed processing + +## State Management and Selector + +The hook uses TanStack Store for reactive state management via the underlying async queuer instance. +The `selector` parameter allows you to specify which async queuer state changes will trigger a re-render, +optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur. + +**By default, there will be no reactive state subscriptions** and you must opt-in to state +tracking by providing a selector function. This prevents unnecessary re-renders and gives you +full control over when your component updates. Only when you provide a selector will the +component re-render when the selected state values change. + +Available async queuer state properties: +- `activeItems`: Items currently being processed by the queuer +- `errorCount`: Number of task executions that have resulted in errors +- `expirationCount`: Number of items that have been removed due to expiration +- `isEmpty`: Whether the queuer has no items to process +- `isFull`: Whether the queuer has reached its maximum capacity +- `isIdle`: Whether the queuer is not currently processing any items +- `isRunning`: Whether the queuer is active and will process items automatically +- `items`: Array of items currently waiting to be processed +- `itemTimestamps`: Timestamps when items were added for expiration tracking +- `lastResult`: The result from the most recent task execution +- `pendingTick`: Whether the queuer has a pending timeout for processing the next item +- `rejectionCount`: Number of items that have been rejected from being added +- `settledCount`: Number of task executions that have completed (success or error) +- `size`: Number of items currently in the queue +- `status`: Current processing status ('idle' | 'running' | 'stopped') +- `successCount`: Number of task executions that have completed successfully + +## Type Parameters + +### TValue + +`TValue` + +### TSelected + +`TSelected` *extends* `Pick`\<`AsyncQueuerState`\<`TValue`\>, `"items"`\> = `Pick`\<`AsyncQueuerState`\<`TValue`\>, `"items"`\> + +## Parameters + +### fn + +(`value`) => `Promise`\<`any`\> + +### options + +`AsyncQueuerOptions`\<`TValue`\> = `{}` + +### selector? + +(`state`) => `TSelected` + +## Returns + +\[`TValue`[], [`ReactAsyncQueuer`](../interfaces/ReactAsyncQueuer.md)\<`TValue`, `TSelected`\>\] + +## Example + +```tsx +// Default behavior - no reactive state subscriptions +const [queueItems, asyncQueuer] = useAsyncQueuedState( + async (item) => { + const result = await processItem(item); + return result; + }, + { + concurrency: 2, + maxSize: 100, + started: true + } +); + +// Opt-in to re-render when queue contents change (optimized for displaying queue items) +const [queueItems, asyncQueuer] = useAsyncQueuedState( + async (item) => { + const result = await processItem(item); + return result; + }, + { concurrency: 2, maxSize: 100, started: true }, + (state) => ({ + items: state.items, + size: state.size, + isEmpty: state.isEmpty, + isFull: state.isFull + }) +); + +// Opt-in to re-render when processing state changes (optimized for loading indicators) +const [queueItems, asyncQueuer] = useAsyncQueuedState( + async (item) => { + const result = await processItem(item); + return result; + }, + { concurrency: 2, maxSize: 100, started: true }, + (state) => ({ + isRunning: state.isRunning, + isIdle: state.isIdle, + status: state.status, + activeItems: state.activeItems, + pendingTick: state.pendingTick + }) +); + +// Opt-in to re-render when execution metrics change (optimized for stats display) +const [queueItems, asyncQueuer] = useAsyncQueuedState( + async (item) => { + const result = await processItem(item); + return result; + }, + { concurrency: 2, maxSize: 100, started: true }, + (state) => ({ + successCount: state.successCount, + errorCount: state.errorCount, + settledCount: state.settledCount, + expirationCount: state.expirationCount, + rejectionCount: state.rejectionCount + }) +); + +// Opt-in to re-render when results are available (optimized for data display) +const [queueItems, asyncQueuer] = useAsyncQueuedState( + async (item) => { + const result = await processItem(item); + return result; + }, + { concurrency: 2, maxSize: 100, started: true }, + (state) => ({ + lastResult: state.lastResult, + successCount: state.successCount + }) +); + +// Add items to queue - state updates automatically +asyncQueuer.addItem(async () => { + const result = await fetchData(); + return result; +}); + +// Start processing +asyncQueuer.start(); + +// Stop processing +asyncQueuer.stop(); + +// queueItems reflects current queue state +const pendingCount = asyncQueuer.peekPendingItems().length; + +// Access the selected async queuer state (will be empty object {} unless selector provided) +const { size, isRunning, activeItems } = asyncQueuer.state; +``` diff --git a/docs/framework/preact/reference/functions/useAsyncQueuer.md b/docs/framework/preact/reference/functions/useAsyncQueuer.md new file mode 100644 index 00000000..c884aabe --- /dev/null +++ b/docs/framework/preact/reference/functions/useAsyncQueuer.md @@ -0,0 +1,185 @@ +--- +id: useAsyncQueuer +title: useAsyncQueuer +--- + +# Function: useAsyncQueuer() + +```ts +function useAsyncQueuer( + fn, + options, +selector): ReactAsyncQueuer; +``` + +Defined in: [preact-pacer/src/async-queuer/useAsyncQueuer.ts:170](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-queuer/useAsyncQueuer.ts#L170) + +A lower-level Preact hook that creates an `AsyncQueuer` instance for managing an async queue of items. + +Features: +- Priority queue support via getPriority option +- Configurable concurrency limit +- Task success/error/completion callbacks +- FIFO (First In First Out) or LIFO (Last In First Out) queue behavior +- Pause/resume task processing +- Task cancellation +- Item expiration to clear stale items from the queue + +Tasks are processed concurrently up to the configured concurrency limit. When a task completes, +the next pending task is processed if below the concurrency limit. + +Error Handling: +- If an `onError` handler is provided, it will be called with the error and queuer instance +- If `throwOnError` is true (default when no onError handler is provided), the error will be thrown +- If `throwOnError` is false (default when onError handler is provided), the error will be swallowed +- Both onError and throwOnError can be used together - the handler will be called before any error is thrown +- The error state can be checked using the underlying AsyncQueuer instance + +## State Management and Selector + +The hook uses TanStack Store for reactive state management. The `selector` parameter allows you +to specify which state changes will trigger a re-render, optimizing performance by preventing +unnecessary re-renders when irrelevant state changes occur. + +**By default, there will be no reactive state subscriptions** and you must opt-in to state +tracking by providing a selector function. This prevents unnecessary re-renders and gives you +full control over when your component updates. Only when you provide a selector will the +component re-render when the selected state values change. + +Available state properties: +- `activeItems`: Items currently being processed by the queuer +- `errorCount`: Number of task executions that have resulted in errors +- `expirationCount`: Number of items that have been removed due to expiration +- `isEmpty`: Whether the queuer has no items to process +- `isFull`: Whether the queuer has reached its maximum capacity +- `isIdle`: Whether the queuer is not currently processing any items +- `isRunning`: Whether the queuer is active and will process items automatically +- `items`: Array of items currently waiting to be processed +- `itemTimestamps`: Timestamps when items were added for expiration tracking +- `lastResult`: The result from the most recent task execution +- `pendingTick`: Whether the queuer has a pending timeout for processing the next item +- `rejectionCount`: Number of items that have been rejected from being added +- `settledCount`: Number of task executions that have completed (success or error) +- `size`: Number of items currently in the queue +- `status`: Current processing status ('idle' | 'running' | 'stopped') +- `successCount`: Number of task executions that have completed successfully + +## Type Parameters + +### TValue + +`TValue` + +### TSelected + +`TSelected` = \{ +\} + +## Parameters + +### fn + +(`value`) => `Promise`\<`any`\> + +### options + +`AsyncQueuerOptions`\<`TValue`\> = `{}` + +### selector + +(`state`) => `TSelected` + +## Returns + +[`ReactAsyncQueuer`](../interfaces/ReactAsyncQueuer.md)\<`TValue`, `TSelected`\> + +## Example + +```tsx +// Default behavior - no reactive state subscriptions +const asyncQueuer = useAsyncQueuer( + async (item) => { + const result = await processItem(item); + return result; + }, + { concurrency: 2, maxSize: 100, started: false } +); + +// Opt-in to re-render when queue size changes (optimized for displaying queue length) +const asyncQueuer = useAsyncQueuer( + async (item) => { + const result = await processItem(item); + return result; + }, + { concurrency: 2, maxSize: 100, started: false }, + (state) => ({ + size: state.size, + isEmpty: state.isEmpty, + isFull: state.isFull + }) +); + +// Opt-in to re-render when processing state changes (optimized for loading indicators) +const asyncQueuer = useAsyncQueuer( + async (item) => { + const result = await processItem(item); + return result; + }, + { concurrency: 2, maxSize: 100, started: false }, + (state) => ({ + isRunning: state.isRunning, + isIdle: state.isIdle, + status: state.status, + activeItems: state.activeItems, + pendingTick: state.pendingTick + }) +); + +// Opt-in to re-render when execution metrics change (optimized for stats display) +const asyncQueuer = useAsyncQueuer( + async (item) => { + const result = await processItem(item); + return result; + }, + { concurrency: 2, maxSize: 100, started: false }, + (state) => ({ + successCount: state.successCount, + errorCount: state.errorCount, + settledCount: state.settledCount, + expirationCount: state.expirationCount, + rejectionCount: state.rejectionCount + }) +); + +// Opt-in to re-render when results are available (optimized for data display) +const asyncQueuer = useAsyncQueuer( + async (item) => { + const result = await processItem(item); + return result; + }, + { + concurrency: 2, + maxSize: 100, + started: false, + onSuccess: (result) => { + console.log('Item processed:', result); + }, + onError: (error) => { + console.error('Processing failed:', error); + } + }, + (state) => ({ + lastResult: state.lastResult, + successCount: state.successCount + }) +); + +// Add items to queue +asyncQueuer.addItem(newItem); + +// Start processing +asyncQueuer.start(); + +// Access the selected state (will be empty object {} unless selector provided) +const { size, isRunning, activeItems } = asyncQueuer.state; +``` diff --git a/docs/framework/preact/reference/functions/useAsyncRateLimitedCallback.md b/docs/framework/preact/reference/functions/useAsyncRateLimitedCallback.md new file mode 100644 index 00000000..ce682a3a --- /dev/null +++ b/docs/framework/preact/reference/functions/useAsyncRateLimitedCallback.md @@ -0,0 +1,96 @@ +--- +id: useAsyncRateLimitedCallback +title: useAsyncRateLimitedCallback +--- + +# Function: useAsyncRateLimitedCallback() + +```ts +function useAsyncRateLimitedCallback(fn, options): (...args) => Promise>; +``` + +Defined in: [preact-pacer/src/async-rate-limiter/useAsyncRateLimitedCallback.ts:59](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-rate-limiter/useAsyncRateLimitedCallback.ts#L59) + +A Preact hook that creates a rate-limited version of an async callback function. +This hook is a convenient wrapper around the `useAsyncRateLimiter` hook, +providing a stable, async rate-limited function reference for use in Preact components. + +Async rate limiting is a "hard limit" approach for async functions: it allows all calls +until the limit is reached, then blocks (rejects) subsequent calls until the window resets. +Unlike throttling or debouncing, it does not attempt to space out or collapse calls. +This can lead to bursts of rapid executions followed by periods where all calls are blocked. + +The async rate limiter supports two types of windows: +- 'fixed': A strict window that resets after the window period. All executions within the window count + towards the limit, and the window resets completely after the period. +- 'sliding': A rolling window that allows executions as old ones expire. This provides a more + consistent rate of execution over time. + +For smoother execution patterns, consider: +- useAsyncThrottledCallback: When you want consistent spacing between executions (e.g. UI updates) +- useAsyncDebouncedCallback: When you want to collapse rapid calls into a single execution (e.g. search input) + +Async rate limiting should primarily be used when you need to enforce strict limits +on async operations, like API rate limits or other scenarios requiring hard caps +on execution frequency. + +This hook provides a simpler API compared to `useAsyncRateLimiter`, making it ideal for basic +async rate limiting needs. However, it does not expose the underlying AsyncRateLimiter instance. + +For advanced usage requiring features like: +- Manual cancellation +- Access to execution counts +- Custom useCallback dependencies + +Consider using the `useAsyncRateLimiter` hook instead. + +## Type Parameters + +### TFn + +`TFn` *extends* `AnyAsyncFunction` + +## Parameters + +### fn + +`TFn` + +### options + +`AsyncRateLimiterOptions`\<`TFn`\> + +## Returns + +```ts +(...args): Promise>; +``` + +### Parameters + +#### args + +...`Parameters`\<`TFn`\> + +### Returns + +`Promise`\<`ReturnType`\<`TFn`\>\> + +## Example + +```tsx +// Rate limit async API calls to maximum 5 calls per minute with a sliding window +const makeApiCall = useAsyncRateLimitedCallback( + async (data: ApiData) => { + return fetch('/api/endpoint', { method: 'POST', body: JSON.stringify(data) }); + }, + { + limit: 5, + window: 60000, // 1 minute + windowType: 'sliding', + onReject: () => { + console.warn('API rate limit reached. Please wait before trying again.'); + } + } +); +``` diff --git a/docs/framework/preact/reference/functions/useAsyncRateLimiter.md b/docs/framework/preact/reference/functions/useAsyncRateLimiter.md new file mode 100644 index 00000000..af81481f --- /dev/null +++ b/docs/framework/preact/reference/functions/useAsyncRateLimiter.md @@ -0,0 +1,193 @@ +--- +id: useAsyncRateLimiter +title: useAsyncRateLimiter +--- + +# Function: useAsyncRateLimiter() + +```ts +function useAsyncRateLimiter( + fn, + options, +selector): ReactAsyncRateLimiter; +``` + +Defined in: [preact-pacer/src/async-rate-limiter/useAsyncRateLimiter.ts:179](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-rate-limiter/useAsyncRateLimiter.ts#L179) + +A low-level Preact hook that creates an `AsyncRateLimiter` instance to limit how many times an async function can execute within a time window. + +This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that +you can integrate with any state management solution (useState, Redux, Zustand, Jotai, etc). + +Rate limiting allows an async function to execute up to a specified limit within a time window, +then blocks subsequent calls until the window passes. This is useful for respecting API rate limits, +managing resource constraints, or controlling bursts of async operations. + +Unlike the non-async RateLimiter, this async version supports returning values from the rate-limited function, +making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call +instead of setting the result on a state variable from within the rate-limited function. + +The rate limiter supports two types of windows: +- 'fixed': A strict window that resets after the window period. All executions within the window count + towards the limit, and the window resets completely after the period. +- 'sliding': A rolling window that allows executions as old ones expire. This provides a more + consistent rate of execution over time. + +Error Handling: +- If an `onError` handler is provided, it will be called with the error and rate limiter instance +- If `throwOnError` is true (default when no onError handler is provided), the error will be thrown +- If `throwOnError` is false (default when onError handler is provided), the error will be swallowed +- Both onError and throwOnError can be used together - the handler will be called before any error is thrown +- The error state can be checked using the underlying AsyncRateLimiter instance +- Rate limit rejections (when limit is exceeded) are handled separately from execution errors via the `onReject` handler + +## State Management and Selector + +The hook uses TanStack Store for reactive state management. The `selector` parameter allows you +to specify which state changes will trigger a re-render, optimizing performance by preventing +unnecessary re-renders when irrelevant state changes occur. + +**By default, there will be no reactive state subscriptions** and you must opt-in to state +tracking by providing a selector function. This prevents unnecessary re-renders and gives you +full control over when your component updates. Only when you provide a selector will the +component re-render when the selected state values change. + +Available state properties: +- `errorCount`: Number of function executions that have resulted in errors +- `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations +- `isExecuting`: Whether the rate-limited function is currently executing asynchronously +- `lastResult`: The result from the most recent successful function execution +- `rejectionCount`: Number of function executions that have been rejected due to rate limiting +- `settleCount`: Number of function executions that have completed (success or error) +- `successCount`: Number of function executions that have completed successfully + +## Type Parameters + +### TFn + +`TFn` *extends* `AnyAsyncFunction` + +### TSelected + +`TSelected` = \{ +\} + +## Parameters + +### fn + +`TFn` + +### options + +`AsyncRateLimiterOptions`\<`TFn`\> + +### selector + +(`state`) => `TSelected` + +## Returns + +[`ReactAsyncRateLimiter`](../interfaces/ReactAsyncRateLimiter.md)\<`TFn`, `TSelected`\> + +## Example + +```tsx +// Default behavior - no reactive state subscriptions +const asyncRateLimiter = useAsyncRateLimiter( + async (id: string) => { + const data = await api.fetchData(id); + return data; // Return value is preserved + }, + { limit: 5, window: 1000 } // 5 calls per second +); + +// Opt-in to re-render when execution state changes (optimized for loading indicators) +const asyncRateLimiter = useAsyncRateLimiter( + async (id: string) => { + const data = await api.fetchData(id); + return data; + }, + { limit: 5, window: 1000 }, + (state) => ({ isExecuting: state.isExecuting }) +); + +// Opt-in to re-render when results are available (optimized for data display) +const asyncRateLimiter = useAsyncRateLimiter( + async (id: string) => { + const data = await api.fetchData(id); + return data; + }, + { limit: 5, window: 1000 }, + (state) => ({ + lastResult: state.lastResult, + successCount: state.successCount + }) +); + +// Opt-in to re-render when error/rejection state changes (optimized for error handling) +const asyncRateLimiter = useAsyncRateLimiter( + async (id: string) => { + const data = await api.fetchData(id); + return data; + }, + { + limit: 5, + window: 1000, + onError: (error) => console.error('API call failed:', error), + onReject: (rateLimiter) => console.log('Rate limit exceeded') + }, + (state) => ({ + errorCount: state.errorCount, + rejectionCount: state.rejectionCount + }) +); + +// Opt-in to re-render when execution metrics change (optimized for stats display) +const asyncRateLimiter = useAsyncRateLimiter( + async (id: string) => { + const data = await api.fetchData(id); + return data; + }, + { limit: 5, window: 1000 }, + (state) => ({ + successCount: state.successCount, + errorCount: state.errorCount, + settleCount: state.settleCount, + rejectionCount: state.rejectionCount + }) +); + +// Opt-in to re-render when execution times change (optimized for window calculations) +const asyncRateLimiter = useAsyncRateLimiter( + async (id: string) => { + const data = await api.fetchData(id); + return data; + }, + { limit: 5, window: 1000 }, + (state) => ({ executionTimes: state.executionTimes }) +); + +// With state management and return value +const [data, setData] = useState(null); +const { maybeExecute, state } = useAsyncRateLimiter( + async (query) => { + const result = await searchAPI(query); + setData(result); + return result; // Return value can be used by the caller + }, + { + limit: 10, + window: 60000, // 10 calls per minute + onReject: (rateLimiter) => { + console.log(`Rate limit exceeded. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`); + }, + onError: (error) => { + console.error('API call failed:', error); + } + } +); + +// Access the selected state (will be empty object {} unless selector provided) +const { isExecuting, lastResult, rejectionCount } = state; +``` diff --git a/docs/framework/preact/reference/functions/useAsyncThrottledCallback.md b/docs/framework/preact/reference/functions/useAsyncThrottledCallback.md new file mode 100644 index 00000000..9a462f8e --- /dev/null +++ b/docs/framework/preact/reference/functions/useAsyncThrottledCallback.md @@ -0,0 +1,79 @@ +--- +id: useAsyncThrottledCallback +title: useAsyncThrottledCallback +--- + +# Function: useAsyncThrottledCallback() + +```ts +function useAsyncThrottledCallback(fn, options): (...args) => Promise>; +``` + +Defined in: [preact-pacer/src/async-throttler/useAsyncThrottledCallback.ts:42](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-throttler/useAsyncThrottledCallback.ts#L42) + +A Preact hook that creates a throttled version of an async callback function. +This hook is a convenient wrapper around the `useAsyncThrottler` hook, +providing a stable, throttled async function reference for use in Preact components. + +The throttled async function will execute at most once within the specified wait time period, +regardless of how many times it is called. If called multiple times during the wait period, +only the first invocation will execute, and subsequent calls will be ignored until +the wait period has elapsed. The returned function always returns a promise +that resolves or rejects with the result of the original async function. + +This hook provides a simpler API compared to `useAsyncThrottler`, making it ideal for basic +async throttling needs. However, it does not expose the underlying AsyncThrottler instance. + +For advanced usage requiring features like: +- Manual cancellation +- Access to execution/error state +- Custom useCallback dependencies + +Consider using the `useAsyncThrottler` hook instead. + +## Type Parameters + +### TFn + +`TFn` *extends* `AnyAsyncFunction` + +## Parameters + +### fn + +`TFn` + +### options + +`AsyncThrottlerOptions`\<`TFn`\> + +## Returns + +```ts +(...args): Promise>; +``` + +### Parameters + +#### args + +...`Parameters`\<`TFn`\> + +### Returns + +`Promise`\<`ReturnType`\<`TFn`\>\> + +## Example + +```tsx +// Throttle an async API call +const handleApiCall = useAsyncThrottledCallback(async (data) => { + const result = await sendDataToServer(data); + return result; +}, { + wait: 200 // Execute at most once every 200ms +}); + +// Use in an event handler + +``` diff --git a/docs/framework/preact/reference/functions/useAsyncThrottler.md b/docs/framework/preact/reference/functions/useAsyncThrottler.md new file mode 100644 index 00000000..2da15b0a --- /dev/null +++ b/docs/framework/preact/reference/functions/useAsyncThrottler.md @@ -0,0 +1,175 @@ +--- +id: useAsyncThrottler +title: useAsyncThrottler +--- + +# Function: useAsyncThrottler() + +```ts +function useAsyncThrottler( + fn, + options, +selector): ReactAsyncThrottler; +``` + +Defined in: [preact-pacer/src/async-throttler/useAsyncThrottler.ts:161](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-throttler/useAsyncThrottler.ts#L161) + +A low-level Preact hook that creates an `AsyncThrottler` instance to limit how often an async function can execute. + +This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that +you can integrate with any state management solution (useState, Redux, Zustand, Jotai, etc). + +Async throttling ensures an async function executes at most once within a specified time window, +regardless of how many times it is called. This is useful for rate-limiting expensive API calls, +database operations, or other async tasks. + +Unlike the non-async Throttler, this async version supports returning values from the throttled function, +making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call +instead of setting the result on a state variable from within the throttled function. + +Error Handling: +- If an `onError` handler is provided, it will be called with the error and throttler instance +- If `throwOnError` is true (default when no onError handler is provided), the error will be thrown +- If `throwOnError` is false (default when onError handler is provided), the error will be swallowed +- Both onError and throwOnError can be used together - the handler will be called before any error is thrown +- The error state can be checked using the underlying AsyncThrottler instance + +## State Management and Selector + +The hook uses TanStack Store for reactive state management. The `selector` parameter allows you +to specify which state changes will trigger a re-render, optimizing performance by preventing +unnecessary re-renders when irrelevant state changes occur. + +**By default, there will be no reactive state subscriptions** and you must opt-in to state +tracking by providing a selector function. This prevents unnecessary re-renders and gives you +full control over when your component updates. Only when you provide a selector will the +component re-render when the selected state values change. + +Available state properties: +- `errorCount`: Number of function executions that have resulted in errors +- `isExecuting`: Whether the throttled function is currently executing asynchronously +- `isPending`: Whether the throttler is waiting for the timeout to trigger execution +- `lastArgs`: The arguments from the most recent call to maybeExecute +- `lastExecutionTime`: Timestamp of the last function execution in milliseconds +- `lastResult`: The result from the most recent successful function execution +- `nextExecutionTime`: Timestamp when the next execution can occur in milliseconds +- `settleCount`: Number of function executions that have completed (success or error) +- `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing' | 'settled') +- `successCount`: Number of function executions that have completed successfully + +## Type Parameters + +### TFn + +`TFn` *extends* `AnyAsyncFunction` + +### TSelected + +`TSelected` = \{ +\} + +## Parameters + +### fn + +`TFn` + +### options + +`AsyncThrottlerOptions`\<`TFn`\> + +### selector + +(`state`) => `TSelected` + +## Returns + +[`ReactAsyncThrottler`](../interfaces/ReactAsyncThrottler.md)\<`TFn`, `TSelected`\> + +## Example + +```tsx +// Default behavior - no reactive state subscriptions +const asyncThrottler = useAsyncThrottler( + async (id: string) => { + const data = await api.fetchData(id); + return data; // Return value is preserved + }, + { wait: 1000 } +); + +// Opt-in to re-render when execution state changes (optimized for loading indicators) +const asyncThrottler = useAsyncThrottler( + async (id: string) => { + const data = await api.fetchData(id); + return data; + }, + { wait: 1000 }, + (state) => ({ + isExecuting: state.isExecuting, + isPending: state.isPending, + status: state.status + }) +); + +// Opt-in to re-render when results are available (optimized for data display) +const asyncThrottler = useAsyncThrottler( + async (id: string) => { + const data = await api.fetchData(id); + return data; + }, + { wait: 1000 }, + (state) => ({ + lastResult: state.lastResult, + successCount: state.successCount, + settleCount: state.settleCount + }) +); + +// Opt-in to re-render when error state changes (optimized for error handling) +const asyncThrottler = useAsyncThrottler( + async (id: string) => { + const data = await api.fetchData(id); + return data; + }, + { + wait: 1000, + onError: (error) => console.error('API call failed:', error) + }, + (state) => ({ + errorCount: state.errorCount, + status: state.status + }) +); + +// Opt-in to re-render when timing information changes (optimized for timing displays) +const asyncThrottler = useAsyncThrottler( + async (id: string) => { + const data = await api.fetchData(id); + return data; + }, + { wait: 1000 }, + (state) => ({ + lastExecutionTime: state.lastExecutionTime, + nextExecutionTime: state.nextExecutionTime + }) +); + +// With state management and return value +const [data, setData] = useState(null); +const { maybeExecute, state } = useAsyncThrottler( + async (query) => { + const result = await searchAPI(query); + setData(result); + return result; // Return value can be used by the caller + }, + { + wait: 2000, + leading: true, // Execute immediately on first call + trailing: false // Skip trailing edge updates + } +); + +// Access the selected state (will be empty object {} unless selector provided) +const { isExecuting, lastResult } = state; +``` diff --git a/docs/framework/preact/reference/functions/useBatchedCallback.md b/docs/framework/preact/reference/functions/useBatchedCallback.md new file mode 100644 index 00000000..26435fb0 --- /dev/null +++ b/docs/framework/preact/reference/functions/useBatchedCallback.md @@ -0,0 +1,79 @@ +--- +id: useBatchedCallback +title: useBatchedCallback +--- + +# Function: useBatchedCallback() + +```ts +function useBatchedCallback(fn, options): (...args) => void; +``` + +Defined in: [preact-pacer/src/batcher/useBatchedCallback.ts:41](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/batcher/useBatchedCallback.ts#L41) + +A Preact hook that creates a batched version of a callback function. +This hook is essentially a wrapper around the basic `batch` function +that is exported from `@tanstack/pacer`, +but optimized for Preact with reactive options and a stable function reference. + +The batched function will collect individual calls into batches and execute them +when batch conditions are met (max size reached, wait time elapsed, or custom logic). + +This hook provides a simpler API compared to `useBatcher`, making it ideal for basic +batching needs. However, it does not expose the underlying Batcher instance. + +For advanced usage requiring features like: +- Manual batch execution +- Access to batch state and metrics +- Custom useCallback dependencies + +Consider using the `useBatcher` hook instead. + +## Type Parameters + +### TFn + +`TFn` *extends* `AnyFunction` + +## Parameters + +### fn + +(`items`) => `void` + +### options + +`BatcherOptions`\<`Parameters`\<`TFn`\>\[`0`\]\> + +## Returns + +```ts +(...args): void; +``` + +### Parameters + +#### args + +...`Parameters`\<`TFn`\> + +### Returns + +`void` + +## Example + +```tsx +// Batch analytics events +const trackEvents = useBatchedCallback((events: AnalyticsEvent[]) => { + sendAnalytics(events); +}, { + maxSize: 5, // Process when 5 events collected + wait: 2000 // Or after 2 seconds +}); + +// Use in event handlers + +``` diff --git a/docs/framework/preact/reference/functions/useBatcher.md b/docs/framework/preact/reference/functions/useBatcher.md new file mode 100644 index 00000000..58fd9bef --- /dev/null +++ b/docs/framework/preact/reference/functions/useBatcher.md @@ -0,0 +1,142 @@ +--- +id: useBatcher +title: useBatcher +--- + +# Function: useBatcher() + +```ts +function useBatcher( + fn, + options, +selector): PreactBatcher; +``` + +Defined in: [preact-pacer/src/batcher/useBatcher.ts:124](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/batcher/useBatcher.ts#L124) + +A Preact hook that creates and manages a Batcher instance. + +This is a lower-level hook that provides direct access to the Batcher's functionality without +any built-in state management. This allows you to integrate it with any state management solution +you prefer (useState, Redux, Zustand, etc.) by utilizing the onItemsChange callback. + +The Batcher collects items and processes them in batches based on configurable conditions: +- Maximum batch size +- Time-based batching (process after X milliseconds) +- Custom batch processing logic via getShouldExecute + +## State Management and Selector + +The hook uses TanStack Store for reactive state management. The `selector` parameter allows you +to specify which state changes will trigger a re-render, optimizing performance by preventing +unnecessary re-renders when irrelevant state changes occur. + +**By default, there will be no reactive state subscriptions** and you must opt-in to state +tracking by providing a selector function. This prevents unnecessary re-renders and gives you +full control over when your component updates. Only when you provide a selector will the +component re-render when the selected state values change. + +Available state properties: +- `executionCount`: Number of batch executions that have been completed +- `isEmpty`: Whether the batcher has no items to process +- `isPending`: Whether the batcher is waiting for the timeout to trigger batch processing +- `isRunning`: Whether the batcher is active and will process items automatically +- `items`: Array of items currently queued for batch processing +- `size`: Number of items currently in the batch queue +- `status`: Current processing status ('idle' | 'pending') +- `totalItemsProcessed`: Total number of items processed across all batches + +## Type Parameters + +### TValue + +`TValue` + +### TSelected + +`TSelected` = \{ +\} + +## Parameters + +### fn + +(`items`) => `void` + +### options + +`BatcherOptions`\<`TValue`\> = `{}` + +### selector + +(`state`) => `TSelected` + +## Returns + +[`PreactBatcher`](../interfaces/PreactBatcher.md)\<`TValue`, `TSelected`\> + +## Example + +```tsx +// Default behavior - no reactive state subscriptions +const batcher = useBatcher( + (items) => console.log('Processing batch:', items), + { maxSize: 5, wait: 2000 } +); + +// Opt-in to re-render when batch size changes (optimized for displaying queue size) +const batcher = useBatcher( + (items) => console.log('Processing batch:', items), + { maxSize: 5, wait: 2000 }, + (state) => ({ + size: state.size, + isEmpty: state.isEmpty + }) +); + +// Opt-in to re-render when execution metrics change (optimized for stats display) +const batcher = useBatcher( + (items) => console.log('Processing batch:', items), + { maxSize: 5, wait: 2000 }, + (state) => ({ + executionCount: state.executionCount, + totalItemsProcessed: state.totalItemsProcessed + }) +); + +// Opt-in to re-render when processing state changes (optimized for loading indicators) +const batcher = useBatcher( + (items) => console.log('Processing batch:', items), + { maxSize: 5, wait: 2000 }, + (state) => ({ + isPending: state.isPending, + isRunning: state.isRunning, + status: state.status + }) +); + +// Example with custom state management and batching +const [items, setItems] = useState([]); + +const batcher = useBatcher( + (items) => console.log('Processing batch:', items), + { + maxSize: 5, + wait: 2000, + onItemsChange: (batcher) => setItems(batcher.peekAllItems()), + getShouldExecute: (items) => items.length >= 3 + } +); + +// Add items to batch - they'll be processed when conditions are met +batcher.addItem(1); +batcher.addItem(2); +batcher.addItem(3); // Triggers batch processing + +// Control the batcher +batcher.stop(); // Pause batching +batcher.start(); // Resume batching + +// Access the selected state (will be empty object {} unless selector provided) +const { size, isPending } = batcher.state; +``` diff --git a/docs/framework/preact/reference/functions/useDebouncedCallback.md b/docs/framework/preact/reference/functions/useDebouncedCallback.md new file mode 100644 index 00000000..e50ee1c7 --- /dev/null +++ b/docs/framework/preact/reference/functions/useDebouncedCallback.md @@ -0,0 +1,80 @@ +--- +id: useDebouncedCallback +title: useDebouncedCallback +--- + +# Function: useDebouncedCallback() + +```ts +function useDebouncedCallback(fn, options): (...args) => void; +``` + +Defined in: [preact-pacer/src/debouncer/useDebouncedCallback.ts:42](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/debouncer/useDebouncedCallback.ts#L42) + +A Preact hook that creates a debounced version of a callback function. +This hook is essentially a wrapper around the basic `debounce` function +that is exported from `@tanstack/pacer`, +but optimized for Preact with reactive options and a stable function reference. + +The debounced function will only execute after the specified wait time has elapsed +since its last invocation. If called again before the wait time expires, the timer +resets and starts waiting again. + +This hook provides a simpler API compared to `useDebouncer`, making it ideal for basic +debouncing needs. However, it does not expose the underlying Debouncer instance. + +For advanced usage requiring features like: +- Manual cancellation +- Access to execution counts +- Custom useCallback dependencies + +Consider using the `useDebouncer` hook instead. + +## Type Parameters + +### TFn + +`TFn` *extends* `AnyFunction` + +## Parameters + +### fn + +`TFn` + +### options + +`DebouncerOptions`\<`TFn`\> + +## Returns + +```ts +(...args): void; +``` + +### Parameters + +#### args + +...`Parameters`\<`TFn`\> + +### Returns + +`void` + +## Example + +```tsx +// Debounce a search handler +const handleSearch = useDebouncedCallback((query: string) => { + fetchSearchResults(query); +}, { + wait: 500 // Wait 500ms between executions +}); + +// Use in an input + handleSearch(e.target.value)} +/> +``` diff --git a/docs/framework/preact/reference/functions/useDebouncedState.md b/docs/framework/preact/reference/functions/useDebouncedState.md new file mode 100644 index 00000000..333adce7 --- /dev/null +++ b/docs/framework/preact/reference/functions/useDebouncedState.md @@ -0,0 +1,115 @@ +--- +id: useDebouncedState +title: useDebouncedState +--- + +# Function: useDebouncedState() + +```ts +function useDebouncedState( + value, + options, + selector?): [TValue, Dispatch>, PreactDebouncer>, TSelected>]; +``` + +Defined in: [preact-pacer/src/debouncer/useDebouncedState.ts:82](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/debouncer/useDebouncedState.ts#L82) + +A Preact hook that creates a debounced state value, combining Preact's useState with debouncing functionality. +This hook provides both the current debounced value and methods to update it. + +The state value is only updated after the specified wait time has elapsed since the last update attempt. +If another update is attempted before the wait time expires, the timer resets and starts waiting again. +This is useful for handling frequent state updates that should be throttled, like search input values +or window resize dimensions. + +The hook returns a tuple containing: +- The current debounced value +- A function to update the debounced value +- The debouncer instance with additional control methods + +## State Management and Selector + +The hook uses TanStack Store for reactive state management via the underlying debouncer instance. +The `selector` parameter allows you to specify which debouncer state changes will trigger a re-render, +optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur. + +**By default, there will be no reactive state subscriptions** and you must opt-in to state +tracking by providing a selector function. This prevents unnecessary re-renders and gives you +full control over when your component updates. Only when you provide a selector will the +component re-render when the selected state values change. + +Available debouncer state properties: +- `canLeadingExecute`: Whether the debouncer can execute on the leading edge +- `executionCount`: Number of function executions that have been completed +- `isPending`: Whether the debouncer is waiting for the timeout to trigger execution +- `lastArgs`: The arguments from the most recent call to maybeExecute +- `status`: Current execution status ('disabled' | 'idle' | 'pending') + +## Type Parameters + +### TValue + +`TValue` + +### TSelected + +`TSelected` = `DebouncerState`\<`Dispatch`\<`StateUpdater`\<`TValue`\>\>\> + +## Parameters + +### value + +`TValue` + +### options + +`DebouncerOptions`\<`Dispatch`\<`StateUpdater`\<`TValue`\>\>\> + +### selector? + +(`state`) => `TSelected` + +## Returns + +\[`TValue`, `Dispatch`\<`StateUpdater`\<`TValue`\>\>, [`PreactDebouncer`](../interfaces/PreactDebouncer.md)\<`Dispatch`\<`StateUpdater`\<`TValue`\>\>, `TSelected`\>\] + +## Example + +```tsx +// Default behavior - no reactive state subscriptions +const [searchTerm, setSearchTerm, debouncer] = useDebouncedState('', { + wait: 500 // Wait 500ms after last keystroke +}); + +// Opt-in to re-render when pending state changes (optimized for loading indicators) +const [searchTerm, setSearchTerm, debouncer] = useDebouncedState( + '', + { wait: 500 }, + (state) => ({ isPending: state.isPending }) +); + +// Opt-in to re-render when execution count changes (optimized for tracking executions) +const [searchTerm, setSearchTerm, debouncer] = useDebouncedState( + '', + { wait: 500 }, + (state) => ({ executionCount: state.executionCount }) +); + +// Opt-in to re-render when debouncing status changes (optimized for status display) +const [searchTerm, setSearchTerm, debouncer] = useDebouncedState( + '', + { wait: 500 }, + (state) => ({ + status: state.status, + canLeadingExecute: state.canLeadingExecute + }) +); + +// Update value - will be debounced +const handleChange = (e) => { + setSearchTerm(e.target.value); +}; + +// Access the selected debouncer state (will be empty object {} unless selector provided) +const { isPending, executionCount } = debouncer.state; +``` diff --git a/docs/framework/preact/reference/functions/useDebouncedValue.md b/docs/framework/preact/reference/functions/useDebouncedValue.md new file mode 100644 index 00000000..8db56509 --- /dev/null +++ b/docs/framework/preact/reference/functions/useDebouncedValue.md @@ -0,0 +1,124 @@ +--- +id: useDebouncedValue +title: useDebouncedValue +--- + +# Function: useDebouncedValue() + +```ts +function useDebouncedValue( + value, + options, + selector?): [TValue, PreactDebouncer>, TSelected>]; +``` + +Defined in: [preact-pacer/src/debouncer/useDebouncedValue.ts:91](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/debouncer/useDebouncedValue.ts#L91) + +A Preact hook that creates a debounced value that updates only after a specified delay. +Unlike useDebouncedState, this hook automatically tracks changes to the input value +and updates the debounced value accordingly. + +The debounced value will only update after the specified wait time has elapsed since +the last change to the input value. If the input value changes again before the wait +time expires, the timer resets and starts waiting again. + +This is useful for deriving debounced values from props or state that change frequently, +like search queries or form inputs, where you want to limit how often downstream effects +or calculations occur. + +The hook returns the current debounced value and the underlying debouncer instance. +The debouncer instance can be used to access additional functionality like cancellation +and execution counts. + +## State Management and Selector + +The hook uses TanStack Store for reactive state management via the underlying debouncer instance. +The `selector` parameter allows you to specify which debouncer state changes will trigger a re-render, +optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur. + +**By default, there will be no reactive state subscriptions** and you must opt-in to state +tracking by providing a selector function. This prevents unnecessary re-renders and gives you +full control over when your component updates. Only when you provide a selector will the +component re-render when the selected state values change. + +Available debouncer state properties: +- `canLeadingExecute`: Whether the debouncer can execute on the leading edge +- `executionCount`: Number of function executions that have been completed +- `isPending`: Whether the debouncer is waiting for the timeout to trigger execution +- `lastArgs`: The arguments from the most recent call to maybeExecute +- `status`: Current execution status ('disabled' | 'idle' | 'pending') + +## Type Parameters + +### TValue + +`TValue` + +### TSelected + +`TSelected` = `DebouncerState`\<`Dispatch`\<`StateUpdater`\<`TValue`\>\>\> + +## Parameters + +### value + +`TValue` + +### options + +`DebouncerOptions`\<`Dispatch`\<`StateUpdater`\<`TValue`\>\>\> + +### selector? + +(`state`) => `TSelected` + +## Returns + +\[`TValue`, [`PreactDebouncer`](../interfaces/PreactDebouncer.md)\<`Dispatch`\<`StateUpdater`\<`TValue`\>\>, `TSelected`\>\] + +## Example + +```tsx +// Default behavior - no reactive state subscriptions +const [searchQuery, setSearchQuery] = useState(''); +const [debouncedQuery, debouncer] = useDebouncedValue(searchQuery, { + wait: 500 // Wait 500ms after last change +}); + +// Opt-in to re-render when pending state changes (optimized for loading indicators) +const [debouncedQuery, debouncer] = useDebouncedValue( + searchQuery, + { wait: 500 }, + (state) => ({ isPending: state.isPending }) +); + +// Opt-in to re-render when execution count changes (optimized for tracking executions) +const [debouncedQuery, debouncer] = useDebouncedValue( + searchQuery, + { wait: 500 }, + (state) => ({ executionCount: state.executionCount }) +); + +// Opt-in to re-render when debouncing status changes (optimized for status display) +const [debouncedQuery, debouncer] = useDebouncedValue( + searchQuery, + { wait: 500 }, + (state) => ({ + status: state.status, + canLeadingExecute: state.canLeadingExecute + }) +); + +// debouncedQuery will update 500ms after searchQuery stops changing +useEffect(() => { + fetchSearchResults(debouncedQuery); +}, [debouncedQuery]); + +// Handle input changes +const handleChange = (e) => { + setSearchQuery(e.target.value); +}; + +// Access the selected debouncer state (will be empty object {} unless selector provided) +const { isPending, executionCount } = debouncer.state; +``` diff --git a/docs/framework/preact/reference/functions/useDebouncer.md b/docs/framework/preact/reference/functions/useDebouncer.md new file mode 100644 index 00000000..e8ac6452 --- /dev/null +++ b/docs/framework/preact/reference/functions/useDebouncer.md @@ -0,0 +1,119 @@ +--- +id: useDebouncer +title: useDebouncer +--- + +# Function: useDebouncer() + +```ts +function useDebouncer( + fn, + options, +selector): PreactDebouncer; +``` + +Defined in: [preact-pacer/src/debouncer/useDebouncer.ts:105](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/debouncer/useDebouncer.ts#L105) + +A Preact hook that creates and manages a Debouncer instance. + +This is a lower-level hook that provides direct access to the Debouncer's functionality without +any built-in state management. This allows you to integrate it with any state management solution +you prefer (useState, Redux, Zustand, etc.). + +This hook provides debouncing functionality to limit how often a function can be called, +waiting for a specified delay before executing the latest call. This is useful for handling +frequent events like window resizing, scroll events, or real-time search inputs. + +The debouncer will only execute the function after the specified wait time has elapsed +since the last call. If the function is called again before the wait time expires, the +timer resets and starts waiting again. + +## State Management and Selector + +The hook uses TanStack Store for reactive state management. The `selector` parameter allows you +to specify which state changes will trigger a re-render, optimizing performance by preventing +unnecessary re-renders when irrelevant state changes occur. + +**By default, there will be no reactive state subscriptions** and you must opt-in to state +tracking by providing a selector function. This prevents unnecessary re-renders and gives you +full control over when your component updates. Only when you provide a selector will the +component re-render when the selected state values change. + +Available state properties: +- `canLeadingExecute`: Whether the debouncer can execute on the leading edge +- `executionCount`: Number of function executions that have been completed +- `isPending`: Whether the debouncer is waiting for the timeout to trigger execution +- `lastArgs`: The arguments from the most recent call to maybeExecute +- `status`: Current execution status ('disabled' | 'idle' | 'pending') + +## Type Parameters + +### TFn + +`TFn` *extends* `AnyFunction` + +### TSelected + +`TSelected` = \{ +\} + +## Parameters + +### fn + +`TFn` + +### options + +`DebouncerOptions`\<`TFn`\> + +### selector + +(`state`) => `TSelected` + +## Returns + +[`PreactDebouncer`](../interfaces/PreactDebouncer.md)\<`TFn`, `TSelected`\> + +## Example + +```tsx +// Default behavior - no reactive state subscriptions +const searchDebouncer = useDebouncer( + (query: string) => fetchSearchResults(query), + { wait: 500 } +); + +// Opt-in to re-render when isPending changes (optimized for loading states) +const searchDebouncer = useDebouncer( + (query: string) => fetchSearchResults(query), + { wait: 500 }, + (state) => ({ isPending: state.isPending }) +); + +// Opt-in to re-render when executionCount changes (optimized for tracking execution) +const searchDebouncer = useDebouncer( + (query: string) => fetchSearchResults(query), + { wait: 500 }, + (state) => ({ executionCount: state.executionCount }) +); + +// Multiple state properties - re-render when any of these change +const searchDebouncer = useDebouncer( + (query: string) => fetchSearchResults(query), + { wait: 500 }, + (state) => ({ + isPending: state.isPending, + executionCount: state.executionCount, + status: state.status + }) +); + +// In an event handler +const handleChange = (e) => { + searchDebouncer.maybeExecute(e.target.value); +}; + +// Access the selected state (will be empty object {} unless selector provided) +const { isPending } = searchDebouncer.state; +``` diff --git a/docs/framework/preact/reference/functions/useDefaultPacerOptions.md b/docs/framework/preact/reference/functions/useDefaultPacerOptions.md new file mode 100644 index 00000000..1ddcfc77 --- /dev/null +++ b/docs/framework/preact/reference/functions/useDefaultPacerOptions.md @@ -0,0 +1,16 @@ +--- +id: useDefaultPacerOptions +title: useDefaultPacerOptions +--- + +# Function: useDefaultPacerOptions() + +```ts +function useDefaultPacerOptions(): PacerProviderOptions; +``` + +Defined in: [preact-pacer/src/provider/PacerProvider.tsx:67](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/provider/PacerProvider.tsx#L67) + +## Returns + +[`PacerProviderOptions`](../interfaces/PacerProviderOptions.md) diff --git a/docs/framework/preact/reference/functions/usePacerContext.md b/docs/framework/preact/reference/functions/usePacerContext.md new file mode 100644 index 00000000..d469ac33 --- /dev/null +++ b/docs/framework/preact/reference/functions/usePacerContext.md @@ -0,0 +1,16 @@ +--- +id: usePacerContext +title: usePacerContext +--- + +# Function: usePacerContext() + +```ts +function usePacerContext(): PacerContextValue | null; +``` + +Defined in: [preact-pacer/src/provider/PacerProvider.tsx:63](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/provider/PacerProvider.tsx#L63) + +## Returns + +`PacerContextValue` \| `null` diff --git a/docs/framework/preact/reference/functions/useQueuedState.md b/docs/framework/preact/reference/functions/useQueuedState.md new file mode 100644 index 00000000..e7a2098c --- /dev/null +++ b/docs/framework/preact/reference/functions/useQueuedState.md @@ -0,0 +1,157 @@ +--- +id: useQueuedState +title: useQueuedState +--- + +# Function: useQueuedState() + +```ts +function useQueuedState( + fn, + options, + selector?): [TValue[], (item, position?, runOnItemsChange?) => boolean, PreactQueuer]; +``` + +Defined in: [preact-pacer/src/queuer/useQueuedState.ts:119](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/queuer/useQueuedState.ts#L119) + +A Preact hook that creates a queuer with managed state, combining Preact's useState with queuing functionality. +This hook provides both the current queue state and queue control methods. + +The queue state is automatically updated whenever items are added, removed, or reordered in the queue. +All queue operations are reflected in the state array returned by the hook. + +The queue can be started and stopped to automatically process items at a specified interval, +making it useful as a scheduler. When started, it will process one item per tick, with an +optional wait time between ticks. + +The hook returns a tuple containing: +- The current queue state as an array +- The queue instance with methods for queue manipulation + +## State Management and Selector + +The hook uses TanStack Store for reactive state management via the underlying queuer instance. +The `selector` parameter allows you to specify which queuer state changes will trigger a re-render, +optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur. + +**By default, there will be no reactive state subscriptions** and you must opt-in to state +tracking by providing a selector function. This prevents unnecessary re-renders and gives you +full control over when your component updates. Only when you provide a selector will the +component re-render when the selected state values change. + +Available queuer state properties: +- `executionCount`: Number of items that have been processed by the queuer +- `expirationCount`: Number of items that have been removed due to expiration +- `isEmpty`: Whether the queuer has no items to process +- `isFull`: Whether the queuer has reached its maximum capacity +- `isIdle`: Whether the queuer is not currently processing any items +- `isRunning`: Whether the queuer is active and will process items automatically +- `items`: Array of items currently waiting to be processed +- `itemTimestamps`: Timestamps when items were added for expiration tracking +- `pendingTick`: Whether the queuer has a pending timeout for processing the next item +- `rejectionCount`: Number of items that have been rejected from being added +- `size`: Number of items currently in the queue +- `status`: Current processing status ('idle' | 'running' | 'stopped') + +## Type Parameters + +### TValue + +`TValue` + +### TSelected + +`TSelected` *extends* `Pick`\<`QueuerState`\<`TValue`\>, `"items"`\> = `Pick`\<`QueuerState`\<`TValue`\>, `"items"`\> + +## Parameters + +### fn + +(`item`) => `void` + +### options + +`QueuerOptions`\<`TValue`\> = `{}` + +### selector? + +(`state`) => `TSelected` + +## Returns + +\[`TValue`[], (`item`, `position?`, `runOnItemsChange?`) => `boolean`, [`PreactQueuer`](../interfaces/PreactQueuer.md)\<`TValue`, `TSelected`\>\] + +## Example + +```tsx +// Default behavior - no reactive state subscriptions +const [items, addItem, queue] = useQueuedState( + (item) => console.log('Processing:', item), + { + initialItems: ['item1', 'item2'], + started: true, + wait: 1000, + getPriority: (item) => item.priority + } +); + +// Opt-in to re-render when queue contents change (optimized for displaying queue items) +const [items, addItem, queue] = useQueuedState( + (item) => console.log('Processing:', item), + { started: true, wait: 1000 }, + (state) => ({ + items: state.items, + size: state.size, + isEmpty: state.isEmpty + }) +); + +// Opt-in to re-render when processing state changes (optimized for loading indicators) +const [items, addItem, queue] = useQueuedState( + (item) => console.log('Processing:', item), + { started: true, wait: 1000 }, + (state) => ({ + isRunning: state.isRunning, + isIdle: state.isIdle, + status: state.status, + pendingTick: state.pendingTick + }) +); + +// Opt-in to re-render when execution metrics change (optimized for stats display) +const [items, addItem, queue] = useQueuedState( + (item) => console.log('Processing:', item), + { started: true, wait: 1000 }, + (state) => ({ + executionCount: state.executionCount, + expirationCount: state.expirationCount, + rejectionCount: state.rejectionCount + }) +); + +// Add items to queue +const handleAdd = (item) => { + addItem(item); +}; + +// Start automatic processing +const startProcessing = () => { + queue.start(); +}; + +// Stop automatic processing +const stopProcessing = () => { + queue.stop(); +}; + +// Manual processing still available +const handleProcess = () => { + const nextItem = queue.getNextItem(); + if (nextItem) { + processItem(nextItem); + } +}; + +// Access the selected queuer state (will be empty object {} unless selector provided) +const { size, isRunning, executionCount } = queue.state; +``` diff --git a/docs/framework/preact/reference/functions/useQueuedValue.md b/docs/framework/preact/reference/functions/useQueuedValue.md new file mode 100644 index 00000000..3ffb5ebb --- /dev/null +++ b/docs/framework/preact/reference/functions/useQueuedValue.md @@ -0,0 +1,140 @@ +--- +id: useQueuedValue +title: useQueuedValue +--- + +# Function: useQueuedValue() + +```ts +function useQueuedValue( + initialValue, + options, + selector?): [TValue, PreactQueuer]; +``` + +Defined in: [preact-pacer/src/queuer/useQueuedValue.ts:103](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/queuer/useQueuedValue.ts#L103) + +A Preact hook that creates a queued value that processes state changes in order with an optional delay. +This hook uses useQueuer internally to manage a queue of state changes and apply them sequentially. + +The queued value will process changes in the order they are received, with optional delays between +processing each change. This is useful for handling state updates that need to be processed +in a specific order, like animations or sequential UI updates. + +The hook returns a tuple containing: +- The current queued value +- The queuer instance with control methods + +## State Management and Selector + +The hook uses TanStack Store for reactive state management via the underlying queuer instance. +The `selector` parameter allows you to specify which queuer state changes will trigger a re-render, +optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur. + +**By default, there will be no reactive state subscriptions** and you must opt-in to state +tracking by providing a selector function. This prevents unnecessary re-renders and gives you +full control over when your component updates. Only when you provide a selector will the +component re-render when the selected state values change. + +Available queuer state properties: +- `executionCount`: Number of items that have been processed by the queuer +- `expirationCount`: Number of items that have been removed due to expiration +- `isEmpty`: Whether the queuer has no items to process +- `isFull`: Whether the queuer has reached its maximum capacity +- `isIdle`: Whether the queuer is not currently processing any items +- `isRunning`: Whether the queuer is active and will process items automatically +- `items`: Array of items currently waiting to be processed +- `itemTimestamps`: Timestamps when items were added for expiration tracking +- `pendingTick`: Whether the queuer has a pending timeout for processing the next item +- `rejectionCount`: Number of items that have been rejected from being added +- `size`: Number of items currently in the queue +- `status`: Current processing status ('idle' | 'running' | 'stopped') + +## Type Parameters + +### TValue + +`TValue` + +### TSelected + +`TSelected` *extends* `Pick`\<`QueuerState`\<`TValue`\>, `"items"`\> = `Pick`\<`QueuerState`\<`TValue`\>, `"items"`\> + +## Parameters + +### initialValue + +`TValue` + +### options + +`QueuerOptions`\<`TValue`\> = `{}` + +### selector? + +(`state`) => `TSelected` + +## Returns + +\[`TValue`, [`PreactQueuer`](../interfaces/PreactQueuer.md)\<`TValue`, `TSelected`\>\] + +## Example + +```tsx +// Default behavior - no reactive state subscriptions +const [value, queuer] = useQueuedValue(initialValue, { + wait: 500, // Wait 500ms between processing each change + started: true // Start processing immediately +}); + +// Opt-in to re-render when queue processing state changes (optimized for loading indicators) +const [value, queuer] = useQueuedValue( + initialValue, + { wait: 500, started: true }, + (state) => ({ + isRunning: state.isRunning, + isIdle: state.isIdle, + status: state.status, + pendingTick: state.pendingTick + }) +); + +// Opt-in to re-render when queue contents change (optimized for displaying queue status) +const [value, queuer] = useQueuedValue( + initialValue, + { wait: 500, started: true }, + (state) => ({ + size: state.size, + isEmpty: state.isEmpty, + isFull: state.isFull + }) +); + +// Opt-in to re-render when execution metrics change (optimized for stats display) +const [value, queuer] = useQueuedValue( + initialValue, + { wait: 500, started: true }, + (state) => ({ + executionCount: state.executionCount, + expirationCount: state.expirationCount, + rejectionCount: state.rejectionCount + }) +); + +// Add changes to the queue +const handleChange = (newValue) => { + queuer.addItem(newValue); +}; + +// Control the queue +const pauseProcessing = () => { + queuer.stop(); +}; + +const resumeProcessing = () => { + queuer.start(); +}; + +// Access the selected queuer state (will be empty object {} unless selector provided) +const { size, isRunning, executionCount } = queuer.state; +``` diff --git a/docs/framework/preact/reference/functions/useQueuer.md b/docs/framework/preact/reference/functions/useQueuer.md new file mode 100644 index 00000000..3c49c902 --- /dev/null +++ b/docs/framework/preact/reference/functions/useQueuer.md @@ -0,0 +1,153 @@ +--- +id: useQueuer +title: useQueuer +--- + +# Function: useQueuer() + +```ts +function useQueuer( + fn, + options, +selector): PreactQueuer; +``` + +Defined in: [preact-pacer/src/queuer/useQueuer.ts:135](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/queuer/useQueuer.ts#L135) + +A Preact hook that creates and manages a Queuer instance. + +This is a lower-level hook that provides direct access to the Queuer's functionality without +any built-in state management. This allows you to integrate it with any state management solution +you prefer (useState, Redux, Zustand, etc.) by utilizing the onItemsChange callback. + +For a hook with built-in state management, see useQueuedState. + +The Queuer extends the base Queue to add processing capabilities. Items are processed +synchronously in order, with optional delays between processing each item. The queuer includes +an internal tick mechanism that can be started and stopped, making it useful as a scheduler. +When started, it will process one item per tick, with an optional wait time between ticks. + +By default uses FIFO (First In First Out) behavior, but can be configured for LIFO +(Last In First Out) by specifying 'front' position when adding items. + +## State Management and Selector + +The hook uses TanStack Store for reactive state management. The `selector` parameter allows you +to specify which state changes will trigger a re-render, optimizing performance by preventing +unnecessary re-renders when irrelevant state changes occur. + +**By default, there will be no reactive state subscriptions** and you must opt-in to state +tracking by providing a selector function. This prevents unnecessary re-renders and gives you +full control over when your component updates. Only when you provide a selector will the +component re-render when the selected state values change. + +Available state properties: +- `executionCount`: Number of items that have been processed by the queuer +- `expirationCount`: Number of items that have been removed due to expiration +- `isEmpty`: Whether the queuer has no items to process +- `isFull`: Whether the queuer has reached its maximum capacity +- `isIdle`: Whether the queuer is not currently processing any items +- `isRunning`: Whether the queuer is active and will process items automatically +- `items`: Array of items currently waiting to be processed +- `itemTimestamps`: Timestamps when items were added for expiration tracking +- `pendingTick`: Whether the queuer has a pending timeout for processing the next item +- `rejectionCount`: Number of items that have been rejected from being added +- `size`: Number of items currently in the queue +- `status`: Current processing status ('idle' | 'running' | 'stopped') + +## Type Parameters + +### TValue + +`TValue` + +### TSelected + +`TSelected` = \{ +\} + +## Parameters + +### fn + +(`item`) => `void` + +### options + +`QueuerOptions`\<`TValue`\> = `{}` + +### selector + +(`state`) => `TSelected` + +## Returns + +[`PreactQueuer`](../interfaces/PreactQueuer.md)\<`TValue`, `TSelected`\> + +## Example + +```tsx +// Default behavior - no reactive state subscriptions +const queue = useQueuer( + (item) => console.log('Processing:', item), + { started: true, wait: 1000 } +); + +// Opt-in to re-render when queue size changes (optimized for displaying queue length) +const queue = useQueuer( + (item) => console.log('Processing:', item), + { started: true, wait: 1000 }, + (state) => ({ + size: state.size, + isEmpty: state.isEmpty, + isFull: state.isFull + }) +); + +// Opt-in to re-render when processing state changes (optimized for loading indicators) +const queue = useQueuer( + (item) => console.log('Processing:', item), + { started: true, wait: 1000 }, + (state) => ({ + isRunning: state.isRunning, + isIdle: state.isIdle, + status: state.status, + pendingTick: state.pendingTick + }) +); + +// Opt-in to re-render when execution metrics change (optimized for stats display) +const queue = useQueuer( + (item) => console.log('Processing:', item), + { started: true, wait: 1000 }, + (state) => ({ + executionCount: state.executionCount, + expirationCount: state.expirationCount, + rejectionCount: state.rejectionCount + }) +); + +// Example with custom state management and scheduling +const [items, setItems] = useState([]); + +const queue = useQueuer( + (item) => console.log('Processing:', item), + { + started: true, // Start processing immediately + wait: 1000, // Process one item every second + onItemsChange: (queue) => setItems(queue.peekAllItems()), + getPriority: (item) => item.priority // Process higher priority items first + } +); + +// Add items to process - they'll be handled automatically +queue.addItem('task1'); +queue.addItem('task2'); + +// Control the scheduler +queue.stop(); // Pause processing +queue.start(); // Resume processing + +// Access the selected state (will be empty object {} unless selector provided) +const { size, isRunning, executionCount } = queue.state; +``` diff --git a/docs/framework/preact/reference/functions/useRateLimitedCallback.md b/docs/framework/preact/reference/functions/useRateLimitedCallback.md new file mode 100644 index 00000000..d5955653 --- /dev/null +++ b/docs/framework/preact/reference/functions/useRateLimitedCallback.md @@ -0,0 +1,97 @@ +--- +id: useRateLimitedCallback +title: useRateLimitedCallback +--- + +# Function: useRateLimitedCallback() + +```ts +function useRateLimitedCallback(fn, options): (...args) => boolean; +``` + +Defined in: [preact-pacer/src/rate-limiter/useRateLimitedCallback.ts:59](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/rate-limiter/useRateLimitedCallback.ts#L59) + +A Preact hook that creates a rate-limited version of a callback function. +This hook is essentially a wrapper around the basic `rateLimiter` function +that is exported from `@tanstack/pacer`, +but optimized for Preact with reactive options and a stable function reference. + +Rate limiting is a simple "hard limit" approach - it allows all calls until the limit +is reached, then blocks subsequent calls until the window resets. Unlike throttling +or debouncing, it does not attempt to space out or intelligently collapse calls. +This can lead to bursts of rapid executions followed by periods where all calls +are blocked. + +The rate limiter supports two types of windows: +- 'fixed': A strict window that resets after the window period. All executions within the window count + towards the limit, and the window resets completely after the period. +- 'sliding': A rolling window that allows executions as old ones expire. This provides a more + consistent rate of execution over time. + +For smoother execution patterns, consider: +- useThrottledCallback: When you want consistent spacing between executions (e.g. UI updates) +- useDebouncedCallback: When you want to collapse rapid calls into a single execution (e.g. search input) + +Rate limiting should primarily be used when you need to enforce strict limits, +like API rate limits or other scenarios requiring hard caps on execution frequency. + +This hook provides a simpler API compared to `useRateLimiter`, making it ideal for basic +rate limiting needs. However, it does not expose the underlying RateLimiter instance. + +For advanced usage requiring features like: +- Manual cancellation +- Access to execution counts +- Custom useCallback dependencies + +Consider using the `useRateLimiter` hook instead. + +## Type Parameters + +### TFn + +`TFn` *extends* `AnyFunction` + +## Parameters + +### fn + +`TFn` + +### options + +`RateLimiterOptions`\<`TFn`\> + +## Returns + +```ts +(...args): boolean; +``` + +### Parameters + +#### args + +...`Parameters`\<`TFn`\> + +### Returns + +`boolean` + +## Example + +```tsx +// Rate limit API calls to maximum 5 calls per minute with a sliding window +const makeApiCall = useRateLimitedCallback( + (data: ApiData) => { + return fetch('/api/endpoint', { method: 'POST', body: JSON.stringify(data) }); + }, + { + limit: 5, + window: 60000, // 1 minute + windowType: 'sliding', + onReject: () => { + console.warn('API rate limit reached. Please wait before trying again.'); + } + } +); +``` diff --git a/docs/framework/preact/reference/functions/useRateLimitedState.md b/docs/framework/preact/reference/functions/useRateLimitedState.md new file mode 100644 index 00000000..76e7ffa7 --- /dev/null +++ b/docs/framework/preact/reference/functions/useRateLimitedState.md @@ -0,0 +1,141 @@ +--- +id: useRateLimitedState +title: useRateLimitedState +--- + +# Function: useRateLimitedState() + +```ts +function useRateLimitedState( + value, + options, + selector?): [TValue, Dispatch>, PreactRateLimiter>, TSelected>]; +``` + +Defined in: [preact-pacer/src/rate-limiter/useRateLimitedState.ts:108](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/rate-limiter/useRateLimitedState.ts#L108) + +A Preact hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window. +This hook combines Preact's useState with rate limiting functionality to provide controlled state updates. + +Rate limiting is a simple "hard limit" approach - it allows all updates until the limit is reached, then blocks +subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out +or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates. + +The rate limiter supports two types of windows: +- 'fixed': A strict window that resets after the window period. All updates within the window count + towards the limit, and the window resets completely after the period. +- 'sliding': A rolling window that allows updates as old ones expire. This provides a more + consistent rate of updates over time. + +For smoother update patterns, consider: +- useThrottledState: When you want consistent spacing between updates (e.g. UI changes) +- useDebouncedState: When you want to collapse rapid updates into a single update (e.g. search input) + +Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits. + +The hook returns a tuple containing: +- The rate-limited state value +- A rate-limited setter function that respects the configured limits +- The rateLimiter instance for additional control + +For more direct control over rate limiting without state management, +consider using the lower-level useRateLimiter hook instead. + +## State Management and Selector + +The hook uses TanStack Store for reactive state management via the underlying rate limiter instance. +The `selector` parameter allows you to specify which rate limiter state changes will trigger a re-render, +optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur. + +**By default, there will be no reactive state subscriptions** and you must opt-in to state +tracking by providing a selector function. This prevents unnecessary re-renders and gives you +full control over when your component updates. Only when you provide a selector will the +component re-render when the selected state values change. + +Available rate limiter state properties: +- `executionCount`: Number of function executions that have been completed +- `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations +- `rejectionCount`: Number of function executions that have been rejected due to rate limiting + +## Type Parameters + +### TValue + +`TValue` + +### TSelected + +`TSelected` = `RateLimiterState` + +## Parameters + +### value + +`TValue` + +### options + +`RateLimiterOptions`\<`Dispatch`\<`StateUpdater`\<`TValue`\>\>\> + +### selector? + +(`state`) => `TSelected` + +## Returns + +\[`TValue`, `Dispatch`\<`StateUpdater`\<`TValue`\>\>, [`PreactRateLimiter`](../interfaces/PreactRateLimiter.md)\<`Dispatch`\<`StateUpdater`\<`TValue`\>\>, `TSelected`\>\] + +## Example + +```tsx +// Default behavior - no reactive state subscriptions +const [value, setValue, rateLimiter] = useRateLimitedState(0, { + limit: 5, + window: 60000, + windowType: 'sliding' +}); + +// Opt-in to re-render when execution count changes (optimized for tracking successful updates) +const [value, setValue, rateLimiter] = useRateLimitedState( + 0, + { limit: 5, window: 60000, windowType: 'sliding' }, + (state) => ({ executionCount: state.executionCount }) +); + +// Opt-in to re-render when rejection count changes (optimized for tracking rate limit violations) +const [value, setValue, rateLimiter] = useRateLimitedState( + 0, + { limit: 5, window: 60000, windowType: 'sliding' }, + (state) => ({ rejectionCount: state.rejectionCount }) +); + +// Opt-in to re-render when execution times change (optimized for window calculations) +const [value, setValue, rateLimiter] = useRateLimitedState( + 0, + { limit: 5, window: 60000, windowType: 'sliding' }, + (state) => ({ executionTimes: state.executionTimes }) +); + +// With rejection callback and fixed window +const [value, setValue] = useRateLimitedState(0, { + limit: 3, + window: 5000, + windowType: 'fixed', + onReject: (rateLimiter) => { + alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`); + } +}); + +// Access rateLimiter methods if needed +const handleSubmit = () => { + const remaining = rateLimiter.getRemainingInWindow(); + if (remaining > 0) { + setValue(newValue); + } else { + showRateLimitWarning(); + } +}; + +// Access the selected rate limiter state (will be empty object {} unless selector provided) +const { executionCount, rejectionCount } = rateLimiter.state; +``` diff --git a/docs/framework/preact/reference/functions/useRateLimitedValue.md b/docs/framework/preact/reference/functions/useRateLimitedValue.md new file mode 100644 index 00000000..0be539cc --- /dev/null +++ b/docs/framework/preact/reference/functions/useRateLimitedValue.md @@ -0,0 +1,130 @@ +--- +id: useRateLimitedValue +title: useRateLimitedValue +--- + +# Function: useRateLimitedValue() + +```ts +function useRateLimitedValue( + value, + options, + selector?): [TValue, PreactRateLimiter>, TSelected>]; +``` + +Defined in: [preact-pacer/src/rate-limiter/useRateLimitedValue.ts:97](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/rate-limiter/useRateLimitedValue.ts#L97) + +A high-level Preact hook that creates a rate-limited version of a value that updates at most a certain number of times within a time window. +This hook uses Preact's useState internally to manage the rate-limited state. + +Rate limiting is a simple "hard limit" approach - it allows all updates until the limit is reached, then blocks +subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out +or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates. + +The rate limiter supports two types of windows: +- 'fixed': A strict window that resets after the window period. All updates within the window count + towards the limit, and the window resets completely after the period. +- 'sliding': A rolling window that allows updates as old ones expire. This provides a more + consistent rate of updates over time. + +For smoother update patterns, consider: +- useThrottledValue: When you want consistent spacing between updates (e.g. UI changes) +- useDebouncedValue: When you want to collapse rapid updates into a single update (e.g. search input) + +Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits. + +The hook returns a tuple containing: +- The rate-limited value that updates according to the configured rate limit +- The rate limiter instance with control methods + +For more direct control over rate limiting behavior without Preact state management, +consider using the lower-level useRateLimiter hook instead. + +## State Management and Selector + +The hook uses TanStack Store for reactive state management via the underlying rate limiter instance. +The `selector` parameter allows you to specify which rate limiter state changes will trigger a re-render, +optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur. + +**By default, there will be no reactive state subscriptions** and you must opt-in to state +tracking by providing a selector function. This prevents unnecessary re-renders and gives you +full control over when your component updates. Only when you provide a selector will the +component re-render when the selected state values change. + +Available rate limiter state properties: +- `executionCount`: Number of function executions that have been completed +- `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations +- `rejectionCount`: Number of function executions that have been rejected due to rate limiting + +## Type Parameters + +### TValue + +`TValue` + +### TSelected + +`TSelected` = `RateLimiterState` + +## Parameters + +### value + +`TValue` + +### options + +`RateLimiterOptions`\<`Dispatch`\<`StateUpdater`\<`TValue`\>\>\> + +### selector? + +(`state`) => `TSelected` + +## Returns + +\[`TValue`, [`PreactRateLimiter`](../interfaces/PreactRateLimiter.md)\<`Dispatch`\<`StateUpdater`\<`TValue`\>\>, `TSelected`\>\] + +## Example + +```tsx +// Default behavior - no reactive state subscriptions +const [rateLimitedValue, rateLimiter] = useRateLimitedValue(rawValue, { + limit: 5, + window: 60000, + windowType: 'sliding' +}); + +// Opt-in to re-render when execution count changes (optimized for tracking successful updates) +const [rateLimitedValue, rateLimiter] = useRateLimitedValue( + rawValue, + { limit: 5, window: 60000, windowType: 'sliding' }, + (state) => ({ executionCount: state.executionCount }) +); + +// Opt-in to re-render when rejection count changes (optimized for tracking rate limit violations) +const [rateLimitedValue, rateLimiter] = useRateLimitedValue( + rawValue, + { limit: 5, window: 60000, windowType: 'sliding' }, + (state) => ({ rejectionCount: state.rejectionCount }) +); + +// Opt-in to re-render when execution times change (optimized for window calculations) +const [rateLimitedValue, rateLimiter] = useRateLimitedValue( + rawValue, + { limit: 5, window: 60000, windowType: 'sliding' }, + (state) => ({ executionTimes: state.executionTimes }) +); + +// With rejection callback and fixed window +const [rateLimitedValue, rateLimiter] = useRateLimitedValue(rawValue, { + limit: 3, + window: 5000, + windowType: 'fixed', + onReject: (rateLimiter) => { + console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`); + } +}); + +// Access the selected rate limiter state (will be empty object {} unless selector provided) +const { executionCount, rejectionCount } = rateLimiter.state; +``` diff --git a/docs/framework/preact/reference/functions/useRateLimiter.md b/docs/framework/preact/reference/functions/useRateLimiter.md new file mode 100644 index 00000000..2c888ec2 --- /dev/null +++ b/docs/framework/preact/reference/functions/useRateLimiter.md @@ -0,0 +1,158 @@ +--- +id: useRateLimiter +title: useRateLimiter +--- + +# Function: useRateLimiter() + +```ts +function useRateLimiter( + fn, + options, +selector): PreactRateLimiter; +``` + +Defined in: [preact-pacer/src/rate-limiter/useRateLimiter.ts:144](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/rate-limiter/useRateLimiter.ts#L144) + +A low-level Preact hook that creates a `RateLimiter` instance to enforce rate limits on function execution. + +This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that +you can integrate with any state management solution (useState, Redux, Zustand, Jotai, etc). + +Rate limiting is a simple "hard limit" approach that allows executions until a maximum count is reached within +a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing, +it does not attempt to space out or collapse executions intelligently. + +The rate limiter supports two types of windows: +- 'fixed': A strict window that resets after the window period. All executions within the window count + towards the limit, and the window resets completely after the period. +- 'sliding': A rolling window that allows executions as old ones expire. This provides a more + consistent rate of execution over time. + +For smoother execution patterns: +- Use throttling when you want consistent spacing between executions (e.g. UI updates) +- Use debouncing when you want to collapse rapid-fire events (e.g. search input) +- Use rate limiting only when you need to enforce hard limits (e.g. API rate limits) + +## State Management and Selector + +The hook uses TanStack Store for reactive state management. The `selector` parameter allows you +to specify which state changes will trigger a re-render, optimizing performance by preventing +unnecessary re-renders when irrelevant state changes occur. + +**By default, there will be no reactive state subscriptions** and you must opt-in to state +tracking by providing a selector function. This prevents unnecessary re-renders and gives you +full control over when your component updates. Only when you provide a selector will the +component re-render when the selected state values change. + +Available state properties: +- `executionCount`: Number of function executions that have been completed +- `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations +- `rejectionCount`: Number of function executions that have been rejected due to rate limiting + +The hook returns an object containing: +- maybeExecute: The rate-limited function that respects the configured limits +- getExecutionCount: Returns the number of successful executions +- getRejectionCount: Returns the number of rejected executions due to rate limiting +- getRemainingInWindow: Returns how many more executions are allowed in the current window +- reset: Resets the execution counts and window timing + +## Type Parameters + +### TFn + +`TFn` *extends* `AnyFunction` + +### TSelected + +`TSelected` = \{ +\} + +## Parameters + +### fn + +`TFn` + +### options + +`RateLimiterOptions`\<`TFn`\> + +### selector + +(`state`) => `TSelected` + +## Returns + +[`PreactRateLimiter`](../interfaces/PreactRateLimiter.md)\<`TFn`, `TSelected`\> + +## Example + +```tsx +// Default behavior - no reactive state subscriptions +const rateLimiter = useRateLimiter(apiCall, { + limit: 5, + window: 60000, + windowType: 'sliding', +}); + +// Opt-in to re-render when execution count changes (optimized for tracking successful executions) +const rateLimiter = useRateLimiter( + apiCall, + { + limit: 5, + window: 60000, + windowType: 'sliding', + }, + (state) => ({ executionCount: state.executionCount }) +); + +// Opt-in to re-render when rejection count changes (optimized for tracking rate limit violations) +const rateLimiter = useRateLimiter( + apiCall, + { + limit: 5, + window: 60000, + windowType: 'sliding', + }, + (state) => ({ rejectionCount: state.rejectionCount }) +); + +// Opt-in to re-render when execution times change (optimized for window calculations) +const rateLimiter = useRateLimiter( + apiCall, + { + limit: 5, + window: 60000, + windowType: 'sliding', + }, + (state) => ({ executionTimes: state.executionTimes }) +); + +// Multiple state properties - re-render when any of these change +const rateLimiter = useRateLimiter( + apiCall, + { + limit: 5, + window: 60000, + windowType: 'sliding', + }, + (state) => ({ + executionCount: state.executionCount, + rejectionCount: state.rejectionCount + }) +); + +// Monitor rate limit status +const handleClick = () => { + const remaining = rateLimiter.getRemainingInWindow(); + if (remaining > 0) { + rateLimiter.maybeExecute(data); + } else { + showRateLimitWarning(); + } +}; + +// Access the selected state (will be empty object {} unless selector provided) +const { executionCount, rejectionCount } = rateLimiter.state; +``` diff --git a/docs/framework/preact/reference/functions/useThrottledCallback.md b/docs/framework/preact/reference/functions/useThrottledCallback.md new file mode 100644 index 00000000..d2e9d661 --- /dev/null +++ b/docs/framework/preact/reference/functions/useThrottledCallback.md @@ -0,0 +1,81 @@ +--- +id: useThrottledCallback +title: useThrottledCallback +--- + +# Function: useThrottledCallback() + +```ts +function useThrottledCallback(fn, options): (...args) => void; +``` + +Defined in: [preact-pacer/src/throttler/useThrottledCallback.ts:43](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/throttler/useThrottledCallback.ts#L43) + +A Preact hook that creates a throttled version of a callback function. +This hook is essentially a wrapper around the basic `throttle` function +that is exported from `@tanstack/pacer`, +but optimized for Preact with reactive options and a stable function reference. + +The throttled function will execute at most once within the specified wait time period, +regardless of how many times it is called. If called multiple times during the wait period, +only the first invocation will execute, and subsequent calls will be ignored until +the wait period has elapsed. + +This hook provides a simpler API compared to `useThrottler`, making it ideal for basic +throttling needs. However, it does not expose the underlying Throttler instance. + +For advanced usage requiring features like: +- Manual cancellation +- Access to execution counts +- Custom useCallback dependencies + +Consider using the `useThrottler` hook instead. + +## Type Parameters + +### TFn + +`TFn` *extends* `AnyFunction` + +## Parameters + +### fn + +`TFn` + +### options + +`ThrottlerOptions`\<`TFn`\> + +## Returns + +```ts +(...args): void; +``` + +### Parameters + +#### args + +...`Parameters`\<`TFn`\> + +### Returns + +`void` + +## Example + +```tsx +// Throttle a window resize handler +const handleResize = useThrottledCallback(() => { + updateLayoutMeasurements(); +}, { + wait: 100 // Execute at most once every 100ms +}); + +// Use in an event listener +useEffect(() => { + window.addEventListener('resize', handleResize); + return () => window.removeEventListener('resize', handleResize); +}, [handleResize]); +``` diff --git a/docs/framework/preact/reference/functions/useThrottledState.md b/docs/framework/preact/reference/functions/useThrottledState.md new file mode 100644 index 00000000..2eeb38a8 --- /dev/null +++ b/docs/framework/preact/reference/functions/useThrottledState.md @@ -0,0 +1,126 @@ +--- +id: useThrottledState +title: useThrottledState +--- + +# Function: useThrottledState() + +```ts +function useThrottledState( + value, + options, + selector?): [TValue, Dispatch>, PreactThrottler>, TSelected>]; +``` + +Defined in: [preact-pacer/src/throttler/useThrottledState.ts:94](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/throttler/useThrottledState.ts#L94) + +A Preact hook that creates a throttled state value that updates at most once within a specified time window. +This hook combines Preact's useState with throttling functionality to provide controlled state updates. + +Throttling ensures state updates occur at a controlled rate regardless of how frequently the setter is called. +This is useful for rate-limiting expensive re-renders or operations that depend on rapidly changing state. + +The hook returns a tuple containing: +- The throttled state value +- A throttled setter function that respects the configured wait time +- The throttler instance for additional control + +For more direct control over throttling without state management, +consider using the lower-level useThrottler hook instead. + +## State Management and Selector + +The hook uses TanStack Store for reactive state management via the underlying throttler instance. +The `selector` parameter allows you to specify which throttler state changes will trigger a re-render, +optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur. + +**By default, there will be no reactive state subscriptions** and you must opt-in to state +tracking by providing a selector function. This prevents unnecessary re-renders and gives you +full control over when your component updates. Only when you provide a selector will the +component re-render when the selected state values change. + +Available throttler state properties: +- `executionCount`: Number of function executions that have been completed +- `lastArgs`: The arguments from the most recent call to maybeExecute +- `lastExecutionTime`: Timestamp of the last function execution in milliseconds +- `nextExecutionTime`: Timestamp when the next execution can occur in milliseconds +- `isPending`: Whether the throttler is waiting for the timeout to trigger execution +- `status`: Current execution status ('disabled' | 'idle' | 'pending') + +## Type Parameters + +### TValue + +`TValue` + +### TSelected + +`TSelected` = `ThrottlerState`\<`Dispatch`\<`StateUpdater`\<`TValue`\>\>\> + +## Parameters + +### value + +`TValue` + +### options + +`ThrottlerOptions`\<`Dispatch`\<`StateUpdater`\<`TValue`\>\>\> + +### selector? + +(`state`) => `TSelected` + +## Returns + +\[`TValue`, `Dispatch`\<`StateUpdater`\<`TValue`\>\>, [`PreactThrottler`](../interfaces/PreactThrottler.md)\<`Dispatch`\<`StateUpdater`\<`TValue`\>\>, `TSelected`\>\] + +## Example + +```tsx +// Default behavior - no reactive state subscriptions +const [value, setValue, throttler] = useThrottledState(0, { wait: 1000 }); + +// Opt-in to re-render when execution count changes (optimized for tracking executions) +const [value, setValue, throttler] = useThrottledState( + 0, + { wait: 1000 }, + (state) => ({ executionCount: state.executionCount }) +); + +// Opt-in to re-render when throttling state changes (optimized for loading indicators) +const [value, setValue, throttler] = useThrottledState( + 0, + { wait: 1000 }, + (state) => ({ + isPending: state.isPending, + status: state.status + }) +); + +// Opt-in to re-render when timing information changes (optimized for timing displays) +const [value, setValue, throttler] = useThrottledState( + 0, + { wait: 1000 }, + (state) => ({ + lastExecutionTime: state.lastExecutionTime, + nextExecutionTime: state.nextExecutionTime + }) +); + +// With custom leading/trailing behavior +const [value, setValue] = useThrottledState(0, { + wait: 1000, + leading: true, // Update immediately on first change + trailing: false // Skip trailing edge updates +}); + +// Access throttler methods if needed +const handleReset = () => { + setValue(0); + throttler.cancel(); // Cancel any pending updates +}; + +// Access the selected throttler state (will be empty object {} unless selector provided) +const { executionCount, isPending } = throttler.state; +``` diff --git a/docs/framework/preact/reference/functions/useThrottledValue.md b/docs/framework/preact/reference/functions/useThrottledValue.md new file mode 100644 index 00000000..b8ae8420 --- /dev/null +++ b/docs/framework/preact/reference/functions/useThrottledValue.md @@ -0,0 +1,119 @@ +--- +id: useThrottledValue +title: useThrottledValue +--- + +# Function: useThrottledValue() + +```ts +function useThrottledValue( + value, + options, + selector?): [TValue, PreactThrottler>, TSelected>]; +``` + +Defined in: [preact-pacer/src/throttler/useThrottledValue.ts:86](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/throttler/useThrottledValue.ts#L86) + +A high-level Preact hook that creates a throttled version of a value that updates at most once within a specified time window. +This hook uses Preact's useState internally to manage the throttled state. + +Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes. +This is useful for rate-limiting expensive re-renders or API calls that depend on rapidly changing values. + +The hook returns a tuple containing: +- The throttled value that updates according to the leading/trailing edge behavior specified in the options +- The throttler instance with control methods + +For more direct control over throttling behavior without Preact state management, +consider using the lower-level useThrottler hook instead. + +## State Management and Selector + +The hook uses TanStack Store for reactive state management via the underlying throttler instance. +The `selector` parameter allows you to specify which throttler state changes will trigger a re-render, +optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur. + +**By default, there will be no reactive state subscriptions** and you must opt-in to state +tracking by providing a selector function. This prevents unnecessary re-renders and gives you +full control over when your component updates. Only when you provide a selector will the +component re-render when the selected state values change. + +Available throttler state properties: +- `executionCount`: Number of function executions that have been completed +- `lastArgs`: The arguments from the most recent call to maybeExecute +- `lastExecutionTime`: Timestamp of the last function execution in milliseconds +- `nextExecutionTime`: Timestamp when the next execution can occur in milliseconds +- `isPending`: Whether the throttler is waiting for the timeout to trigger execution +- `status`: Current execution status ('disabled' | 'idle' | 'pending') + +## Type Parameters + +### TValue + +`TValue` + +### TSelected + +`TSelected` = `ThrottlerState`\<`Dispatch`\<`StateUpdater`\<`TValue`\>\>\> + +## Parameters + +### value + +`TValue` + +### options + +`ThrottlerOptions`\<`Dispatch`\<`StateUpdater`\<`TValue`\>\>\> + +### selector? + +(`state`) => `TSelected` + +## Returns + +\[`TValue`, [`PreactThrottler`](../interfaces/PreactThrottler.md)\<`Dispatch`\<`StateUpdater`\<`TValue`\>\>, `TSelected`\>\] + +## Example + +```tsx +// Default behavior - no reactive state subscriptions +const [throttledValue, throttler] = useThrottledValue(rawValue, { wait: 1000 }); + +// Opt-in to re-render when execution count changes (optimized for tracking executions) +const [throttledValue, throttler] = useThrottledValue( + rawValue, + { wait: 1000 }, + (state) => ({ executionCount: state.executionCount }) +); + +// Opt-in to re-render when throttling state changes (optimized for loading indicators) +const [throttledValue, throttler] = useThrottledValue( + rawValue, + { wait: 1000 }, + (state) => ({ + isPending: state.isPending, + status: state.status + }) +); + +// Opt-in to re-render when timing information changes (optimized for timing displays) +const [throttledValue, throttler] = useThrottledValue( + rawValue, + { wait: 1000 }, + (state) => ({ + lastExecutionTime: state.lastExecutionTime, + nextExecutionTime: state.nextExecutionTime + }) +); + +// With custom leading/trailing behavior +const [throttledValue, throttler] = useThrottledValue(rawValue, { + wait: 1000, + leading: true, // Update immediately on first change + trailing: false // Skip trailing edge updates +}); + +// Access the selected throttler state (will be empty object {} unless selector provided) +const { executionCount, isPending } = throttler.state; +``` diff --git a/docs/framework/preact/reference/functions/useThrottler.md b/docs/framework/preact/reference/functions/useThrottler.md new file mode 100644 index 00000000..45d790a9 --- /dev/null +++ b/docs/framework/preact/reference/functions/useThrottler.md @@ -0,0 +1,124 @@ +--- +id: useThrottler +title: useThrottler +--- + +# Function: useThrottler() + +```ts +function useThrottler( + fn, + options, +selector): PreactThrottler; +``` + +Defined in: [preact-pacer/src/throttler/useThrottler.ts:110](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/throttler/useThrottler.ts#L110) + +A low-level Preact hook that creates a `Throttler` instance that limits how often the provided function can execute. + +This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that +you can integrate with any state management solution (useState, Redux, Zustand, Jotai, etc). For a simpler and higher-level hook that +integrates directly with Preact's useState, see useThrottledState. + +Throttling ensures a function executes at most once within a specified time window, +regardless of how many times it is called. This is useful for rate-limiting +expensive operations or UI updates. + +## State Management and Selector + +The hook uses TanStack Store for reactive state management. The `selector` parameter allows you +to specify which state changes will trigger a re-render, optimizing performance by preventing +unnecessary re-renders when irrelevant state changes occur. + +**By default, there will be no reactive state subscriptions** and you must opt-in to state +tracking by providing a selector function. This prevents unnecessary re-renders and gives you +full control over when your component updates. Only when you provide a selector will the +component re-render when the selected state values change. + +Available state properties: +- `executionCount`: Number of function executions that have been completed +- `lastArgs`: The arguments from the most recent call to maybeExecute +- `lastExecutionTime`: Timestamp of the last function execution in milliseconds +- `nextExecutionTime`: Timestamp when the next execution can occur in milliseconds +- `isPending`: Whether the throttler is waiting for the timeout to trigger execution +- `status`: Current execution status ('disabled' | 'idle' | 'pending') + +## Type Parameters + +### TFn + +`TFn` *extends* `AnyFunction` + +### TSelected + +`TSelected` = \{ +\} + +## Parameters + +### fn + +`TFn` + +### options + +`ThrottlerOptions`\<`TFn`\> + +### selector + +(`state`) => `TSelected` + +## Returns + +[`PreactThrottler`](../interfaces/PreactThrottler.md)\<`TFn`, `TSelected`\> + +## Example + +```tsx +// Default behavior - no reactive state subscriptions +const [value, setValue] = useState(0); +const throttler = useThrottler(setValue, { wait: 1000 }); + +// Opt-in to re-render when execution count changes (optimized for tracking executions) +const [value, setValue] = useState(0); +const throttler = useThrottler( + setValue, + { wait: 1000 }, + (state) => ({ executionCount: state.executionCount }) +); + +// Opt-in to re-render when throttling state changes (optimized for loading indicators) +const [value, setValue] = useState(0); +const throttler = useThrottler( + setValue, + { wait: 1000 }, + (state) => ({ + isPending: state.isPending, + status: state.status + }) +); + +// Opt-in to re-render when timing information changes (optimized for timing displays) +const [value, setValue] = useState(0); +const throttler = useThrottler( + setValue, + { wait: 1000 }, + (state) => ({ + lastExecutionTime: state.lastExecutionTime, + nextExecutionTime: state.nextExecutionTime + }) +); + +// With any state manager +const throttler = useThrottler( + (value) => stateManager.setState(value), + { + wait: 2000, + leading: true, // Execute immediately on first call + trailing: false // Skip trailing edge updates + } +); + +// Access the selected state (will be empty object {} unless selector provided) +const { executionCount, isPending } = throttler.state; +``` diff --git a/docs/framework/preact/reference/index.md b/docs/framework/preact/reference/index.md new file mode 100644 index 00000000..a68e1f28 --- /dev/null +++ b/docs/framework/preact/reference/index.md @@ -0,0 +1,54 @@ +--- +id: "@tanstack/preact-pacer" +title: "@tanstack/preact-pacer" +--- + +# @tanstack/preact-pacer + +## Interfaces + +- [PacerProviderOptions](interfaces/PacerProviderOptions.md) +- [PacerProviderProps](interfaces/PacerProviderProps.md) +- [PreactBatcher](interfaces/PreactBatcher.md) +- [PreactDebouncer](interfaces/PreactDebouncer.md) +- [PreactQueuer](interfaces/PreactQueuer.md) +- [PreactRateLimiter](interfaces/PreactRateLimiter.md) +- [PreactThrottler](interfaces/PreactThrottler.md) +- [ReactAsyncBatcher](interfaces/ReactAsyncBatcher.md) +- [ReactAsyncDebouncer](interfaces/ReactAsyncDebouncer.md) +- [ReactAsyncQueuer](interfaces/ReactAsyncQueuer.md) +- [ReactAsyncRateLimiter](interfaces/ReactAsyncRateLimiter.md) +- [ReactAsyncThrottler](interfaces/ReactAsyncThrottler.md) + +## Functions + +- [PacerProvider](functions/PacerProvider.md) +- [useAsyncBatchedCallback](functions/useAsyncBatchedCallback.md) +- [useAsyncBatcher](functions/useAsyncBatcher.md) +- [useAsyncDebouncedCallback](functions/useAsyncDebouncedCallback.md) +- [useAsyncDebouncer](functions/useAsyncDebouncer.md) +- [useAsyncQueuedState](functions/useAsyncQueuedState.md) +- [useAsyncQueuer](functions/useAsyncQueuer.md) +- [useAsyncRateLimitedCallback](functions/useAsyncRateLimitedCallback.md) +- [useAsyncRateLimiter](functions/useAsyncRateLimiter.md) +- [useAsyncThrottledCallback](functions/useAsyncThrottledCallback.md) +- [useAsyncThrottler](functions/useAsyncThrottler.md) +- [useBatchedCallback](functions/useBatchedCallback.md) +- [useBatcher](functions/useBatcher.md) +- [useDebouncedCallback](functions/useDebouncedCallback.md) +- [useDebouncedState](functions/useDebouncedState.md) +- [useDebouncedValue](functions/useDebouncedValue.md) +- [useDebouncer](functions/useDebouncer.md) +- [useDefaultPacerOptions](functions/useDefaultPacerOptions.md) +- [usePacerContext](functions/usePacerContext.md) +- [useQueuedState](functions/useQueuedState.md) +- [useQueuedValue](functions/useQueuedValue.md) +- [useQueuer](functions/useQueuer.md) +- [useRateLimitedCallback](functions/useRateLimitedCallback.md) +- [useRateLimitedState](functions/useRateLimitedState.md) +- [useRateLimitedValue](functions/useRateLimitedValue.md) +- [useRateLimiter](functions/useRateLimiter.md) +- [useThrottledCallback](functions/useThrottledCallback.md) +- [useThrottledState](functions/useThrottledState.md) +- [useThrottledValue](functions/useThrottledValue.md) +- [useThrottler](functions/useThrottler.md) diff --git a/docs/framework/preact/reference/interfaces/PacerProviderOptions.md b/docs/framework/preact/reference/interfaces/PacerProviderOptions.md new file mode 100644 index 00000000..35b9371d --- /dev/null +++ b/docs/framework/preact/reference/interfaces/PacerProviderOptions.md @@ -0,0 +1,108 @@ +--- +id: PacerProviderOptions +title: PacerProviderOptions +--- + +# Interface: PacerProviderOptions + +Defined in: [preact-pacer/src/provider/PacerProvider.tsx:19](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/provider/PacerProvider.tsx#L19) + +## Properties + +### asyncBatcher? + +```ts +optional asyncBatcher: Partial>; +``` + +Defined in: [preact-pacer/src/provider/PacerProvider.tsx:20](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/provider/PacerProvider.tsx#L20) + +*** + +### asyncDebouncer? + +```ts +optional asyncDebouncer: Partial>; +``` + +Defined in: [preact-pacer/src/provider/PacerProvider.tsx:21](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/provider/PacerProvider.tsx#L21) + +*** + +### asyncQueuer? + +```ts +optional asyncQueuer: Partial>; +``` + +Defined in: [preact-pacer/src/provider/PacerProvider.tsx:22](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/provider/PacerProvider.tsx#L22) + +*** + +### asyncRateLimiter? + +```ts +optional asyncRateLimiter: Partial>; +``` + +Defined in: [preact-pacer/src/provider/PacerProvider.tsx:23](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/provider/PacerProvider.tsx#L23) + +*** + +### asyncThrottler? + +```ts +optional asyncThrottler: Partial>; +``` + +Defined in: [preact-pacer/src/provider/PacerProvider.tsx:24](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/provider/PacerProvider.tsx#L24) + +*** + +### batcher? + +```ts +optional batcher: Partial>; +``` + +Defined in: [preact-pacer/src/provider/PacerProvider.tsx:25](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/provider/PacerProvider.tsx#L25) + +*** + +### debouncer? + +```ts +optional debouncer: Partial>; +``` + +Defined in: [preact-pacer/src/provider/PacerProvider.tsx:26](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/provider/PacerProvider.tsx#L26) + +*** + +### queuer? + +```ts +optional queuer: Partial>; +``` + +Defined in: [preact-pacer/src/provider/PacerProvider.tsx:27](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/provider/PacerProvider.tsx#L27) + +*** + +### rateLimiter? + +```ts +optional rateLimiter: Partial>; +``` + +Defined in: [preact-pacer/src/provider/PacerProvider.tsx:28](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/provider/PacerProvider.tsx#L28) + +*** + +### throttler? + +```ts +optional throttler: Partial>; +``` + +Defined in: [preact-pacer/src/provider/PacerProvider.tsx:29](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/provider/PacerProvider.tsx#L29) diff --git a/docs/framework/preact/reference/interfaces/PacerProviderProps.md b/docs/framework/preact/reference/interfaces/PacerProviderProps.md new file mode 100644 index 00000000..e5d502b4 --- /dev/null +++ b/docs/framework/preact/reference/interfaces/PacerProviderProps.md @@ -0,0 +1,28 @@ +--- +id: PacerProviderProps +title: PacerProviderProps +--- + +# Interface: PacerProviderProps + +Defined in: [preact-pacer/src/provider/PacerProvider.tsx:38](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/provider/PacerProvider.tsx#L38) + +## Properties + +### children + +```ts +children: ComponentChildren; +``` + +Defined in: [preact-pacer/src/provider/PacerProvider.tsx:39](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/provider/PacerProvider.tsx#L39) + +*** + +### defaultOptions? + +```ts +optional defaultOptions: PacerProviderOptions; +``` + +Defined in: [preact-pacer/src/provider/PacerProvider.tsx:40](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/provider/PacerProvider.tsx#L40) diff --git a/docs/framework/preact/reference/interfaces/PreactBatcher.md b/docs/framework/preact/reference/interfaces/PreactBatcher.md new file mode 100644 index 00000000..7752fecd --- /dev/null +++ b/docs/framework/preact/reference/interfaces/PreactBatcher.md @@ -0,0 +1,53 @@ +--- +id: PreactBatcher +title: PreactBatcher +--- + +# Interface: PreactBatcher\ + +Defined in: [preact-pacer/src/batcher/useBatcher.ts:8](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/batcher/useBatcher.ts#L8) + +## Extends + +- `Omit`\<`Batcher`\<`TValue`\>, `"store"`\> + +## Type Parameters + +### TValue + +`TValue` + +### TSelected + +`TSelected` = \{ +\} + +## Properties + +### state + +```ts +readonly state: Readonly; +``` + +Defined in: [preact-pacer/src/batcher/useBatcher.ts:17](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/batcher/useBatcher.ts#L17) + +Reactive state that will be updated and re-rendered when the batcher state changes + +Use this instead of `batcher.store.state` + +*** + +### ~~store~~ + +```ts +readonly store: Store>>; +``` + +Defined in: [preact-pacer/src/batcher/useBatcher.ts:23](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/batcher/useBatcher.ts#L23) + +#### Deprecated + +Use `batcher.state` instead of `batcher.store.state` if you want to read reactive state. +The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally. +Although, you can make the state reactive by using the `useStore` in your own usage. diff --git a/docs/framework/preact/reference/interfaces/PreactDebouncer.md b/docs/framework/preact/reference/interfaces/PreactDebouncer.md new file mode 100644 index 00000000..0f126943 --- /dev/null +++ b/docs/framework/preact/reference/interfaces/PreactDebouncer.md @@ -0,0 +1,53 @@ +--- +id: PreactDebouncer +title: PreactDebouncer +--- + +# Interface: PreactDebouncer\ + +Defined in: [preact-pacer/src/debouncer/useDebouncer.ts:12](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/debouncer/useDebouncer.ts#L12) + +## Extends + +- `Omit`\<`Debouncer`\<`TFn`\>, `"store"`\> + +## Type Parameters + +### TFn + +`TFn` *extends* `AnyFunction` + +### TSelected + +`TSelected` = \{ +\} + +## Properties + +### state + +```ts +readonly state: Readonly; +``` + +Defined in: [preact-pacer/src/debouncer/useDebouncer.ts:21](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/debouncer/useDebouncer.ts#L21) + +Reactive state that will be updated and re-rendered when the debouncer state changes + +Use this instead of `debouncer.store.state` + +*** + +### ~~store~~ + +```ts +readonly store: Store>>; +``` + +Defined in: [preact-pacer/src/debouncer/useDebouncer.ts:27](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/debouncer/useDebouncer.ts#L27) + +#### Deprecated + +Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state. +The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally. +Although, you can make the state reactive by using the `useStore` in your own usage. diff --git a/docs/framework/preact/reference/interfaces/PreactQueuer.md b/docs/framework/preact/reference/interfaces/PreactQueuer.md new file mode 100644 index 00000000..25c93a18 --- /dev/null +++ b/docs/framework/preact/reference/interfaces/PreactQueuer.md @@ -0,0 +1,53 @@ +--- +id: PreactQueuer +title: PreactQueuer +--- + +# Interface: PreactQueuer\ + +Defined in: [preact-pacer/src/queuer/useQueuer.ts:8](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/queuer/useQueuer.ts#L8) + +## Extends + +- `Omit`\<`Queuer`\<`TValue`\>, `"store"`\> + +## Type Parameters + +### TValue + +`TValue` + +### TSelected + +`TSelected` = \{ +\} + +## Properties + +### state + +```ts +readonly state: Readonly; +``` + +Defined in: [preact-pacer/src/queuer/useQueuer.ts:17](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/queuer/useQueuer.ts#L17) + +Reactive state that will be updated and re-rendered when the queuer state changes + +Use this instead of `queuer.store.state` + +*** + +### ~~store~~ + +```ts +readonly store: Store>>; +``` + +Defined in: [preact-pacer/src/queuer/useQueuer.ts:23](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/queuer/useQueuer.ts#L23) + +#### Deprecated + +Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state. +The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally. +Although, you can make the state reactive by using the `useStore` in your own usage. diff --git a/docs/framework/preact/reference/interfaces/PreactRateLimiter.md b/docs/framework/preact/reference/interfaces/PreactRateLimiter.md new file mode 100644 index 00000000..48783a41 --- /dev/null +++ b/docs/framework/preact/reference/interfaces/PreactRateLimiter.md @@ -0,0 +1,53 @@ +--- +id: PreactRateLimiter +title: PreactRateLimiter +--- + +# Interface: PreactRateLimiter\ + +Defined in: [preact-pacer/src/rate-limiter/useRateLimiter.ts:12](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/rate-limiter/useRateLimiter.ts#L12) + +## Extends + +- `Omit`\<`RateLimiter`\<`TFn`\>, `"store"`\> + +## Type Parameters + +### TFn + +`TFn` *extends* `AnyFunction` + +### TSelected + +`TSelected` = \{ +\} + +## Properties + +### state + +```ts +readonly state: Readonly; +``` + +Defined in: [preact-pacer/src/rate-limiter/useRateLimiter.ts:21](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/rate-limiter/useRateLimiter.ts#L21) + +Reactive state that will be updated and re-rendered when the rate limiter state changes + +Use this instead of `rateLimiter.store.state` + +*** + +### ~~store~~ + +```ts +readonly store: Store>; +``` + +Defined in: [preact-pacer/src/rate-limiter/useRateLimiter.ts:27](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/rate-limiter/useRateLimiter.ts#L27) + +#### Deprecated + +Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state. +The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally. +Although, you can make the state reactive by using the `useStore` in your own usage. diff --git a/docs/framework/preact/reference/interfaces/PreactThrottler.md b/docs/framework/preact/reference/interfaces/PreactThrottler.md new file mode 100644 index 00000000..4ab56418 --- /dev/null +++ b/docs/framework/preact/reference/interfaces/PreactThrottler.md @@ -0,0 +1,53 @@ +--- +id: PreactThrottler +title: PreactThrottler +--- + +# Interface: PreactThrottler\ + +Defined in: [preact-pacer/src/throttler/useThrottler.ts:12](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/throttler/useThrottler.ts#L12) + +## Extends + +- `Omit`\<`Throttler`\<`TFn`\>, `"store"`\> + +## Type Parameters + +### TFn + +`TFn` *extends* `AnyFunction` + +### TSelected + +`TSelected` = \{ +\} + +## Properties + +### state + +```ts +readonly state: Readonly; +``` + +Defined in: [preact-pacer/src/throttler/useThrottler.ts:21](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/throttler/useThrottler.ts#L21) + +Reactive state that will be updated and re-rendered when the throttler state changes + +Use this instead of `throttler.store.state` + +*** + +### ~~store~~ + +```ts +readonly store: Store>>; +``` + +Defined in: [preact-pacer/src/throttler/useThrottler.ts:27](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/throttler/useThrottler.ts#L27) + +#### Deprecated + +Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state. +The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally. +Although, you can make the state reactive by using the `useStore` in your own usage. diff --git a/docs/framework/preact/reference/interfaces/ReactAsyncBatcher.md b/docs/framework/preact/reference/interfaces/ReactAsyncBatcher.md new file mode 100644 index 00000000..d796c2bb --- /dev/null +++ b/docs/framework/preact/reference/interfaces/ReactAsyncBatcher.md @@ -0,0 +1,53 @@ +--- +id: ReactAsyncBatcher +title: ReactAsyncBatcher +--- + +# Interface: ReactAsyncBatcher\ + +Defined in: [preact-pacer/src/async-batcher/useAsyncBatcher.ts:11](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-batcher/useAsyncBatcher.ts#L11) + +## Extends + +- `Omit`\<`AsyncBatcher`\<`TValue`\>, `"store"`\> + +## Type Parameters + +### TValue + +`TValue` + +### TSelected + +`TSelected` = \{ +\} + +## Properties + +### state + +```ts +readonly state: Readonly; +``` + +Defined in: [preact-pacer/src/async-batcher/useAsyncBatcher.ts:20](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-batcher/useAsyncBatcher.ts#L20) + +Reactive state that will be updated and re-rendered when the batcher state changes + +Use this instead of `batcher.store.state` + +*** + +### ~~store~~ + +```ts +readonly store: Store>>; +``` + +Defined in: [preact-pacer/src/async-batcher/useAsyncBatcher.ts:26](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-batcher/useAsyncBatcher.ts#L26) + +#### Deprecated + +Use `batcher.state` instead of `batcher.store.state` if you want to read reactive state. +The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally. +Although, you can make the state reactive by using the `useStore` in your own usage. diff --git a/docs/framework/preact/reference/interfaces/ReactAsyncDebouncer.md b/docs/framework/preact/reference/interfaces/ReactAsyncDebouncer.md new file mode 100644 index 00000000..28c1ab9a --- /dev/null +++ b/docs/framework/preact/reference/interfaces/ReactAsyncDebouncer.md @@ -0,0 +1,53 @@ +--- +id: ReactAsyncDebouncer +title: ReactAsyncDebouncer +--- + +# Interface: ReactAsyncDebouncer\ + +Defined in: [preact-pacer/src/async-debouncer/useAsyncDebouncer.ts:12](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-debouncer/useAsyncDebouncer.ts#L12) + +## Extends + +- `Omit`\<`AsyncDebouncer`\<`TFn`\>, `"store"`\> + +## Type Parameters + +### TFn + +`TFn` *extends* `AnyAsyncFunction` + +### TSelected + +`TSelected` = \{ +\} + +## Properties + +### state + +```ts +readonly state: Readonly; +``` + +Defined in: [preact-pacer/src/async-debouncer/useAsyncDebouncer.ts:21](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-debouncer/useAsyncDebouncer.ts#L21) + +Reactive state that will be updated and re-rendered when the debouncer state changes + +Use this instead of `debouncer.store.state` + +*** + +### ~~store~~ + +```ts +readonly store: Store>>; +``` + +Defined in: [preact-pacer/src/async-debouncer/useAsyncDebouncer.ts:27](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-debouncer/useAsyncDebouncer.ts#L27) + +#### Deprecated + +Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state. +The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally. +Although, you can make the state reactive by using the `useStore` in your own usage. diff --git a/docs/framework/preact/reference/interfaces/ReactAsyncQueuer.md b/docs/framework/preact/reference/interfaces/ReactAsyncQueuer.md new file mode 100644 index 00000000..706b43d8 --- /dev/null +++ b/docs/framework/preact/reference/interfaces/ReactAsyncQueuer.md @@ -0,0 +1,53 @@ +--- +id: ReactAsyncQueuer +title: ReactAsyncQueuer +--- + +# Interface: ReactAsyncQueuer\ + +Defined in: [preact-pacer/src/async-queuer/useAsyncQueuer.ts:11](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-queuer/useAsyncQueuer.ts#L11) + +## Extends + +- `Omit`\<`AsyncQueuer`\<`TValue`\>, `"store"`\> + +## Type Parameters + +### TValue + +`TValue` + +### TSelected + +`TSelected` = \{ +\} + +## Properties + +### state + +```ts +readonly state: Readonly; +``` + +Defined in: [preact-pacer/src/async-queuer/useAsyncQueuer.ts:20](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-queuer/useAsyncQueuer.ts#L20) + +Reactive state that will be updated and re-rendered when the queuer state changes + +Use this instead of `queuer.store.state` + +*** + +### ~~store~~ + +```ts +readonly store: Store>>; +``` + +Defined in: [preact-pacer/src/async-queuer/useAsyncQueuer.ts:26](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-queuer/useAsyncQueuer.ts#L26) + +#### Deprecated + +Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state. +The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally. +Although, you can make the state reactive by using the `useStore` in your own usage. diff --git a/docs/framework/preact/reference/interfaces/ReactAsyncRateLimiter.md b/docs/framework/preact/reference/interfaces/ReactAsyncRateLimiter.md new file mode 100644 index 00000000..32013a45 --- /dev/null +++ b/docs/framework/preact/reference/interfaces/ReactAsyncRateLimiter.md @@ -0,0 +1,53 @@ +--- +id: ReactAsyncRateLimiter +title: ReactAsyncRateLimiter +--- + +# Interface: ReactAsyncRateLimiter\ + +Defined in: [preact-pacer/src/async-rate-limiter/useAsyncRateLimiter.ts:12](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-rate-limiter/useAsyncRateLimiter.ts#L12) + +## Extends + +- `Omit`\<`AsyncRateLimiter`\<`TFn`\>, `"store"`\> + +## Type Parameters + +### TFn + +`TFn` *extends* `AnyAsyncFunction` + +### TSelected + +`TSelected` = \{ +\} + +## Properties + +### state + +```ts +readonly state: Readonly; +``` + +Defined in: [preact-pacer/src/async-rate-limiter/useAsyncRateLimiter.ts:21](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-rate-limiter/useAsyncRateLimiter.ts#L21) + +Reactive state that will be updated and re-rendered when the rate limiter state changes + +Use this instead of `rateLimiter.store.state` + +*** + +### ~~store~~ + +```ts +readonly store: Store>>; +``` + +Defined in: [preact-pacer/src/async-rate-limiter/useAsyncRateLimiter.ts:27](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-rate-limiter/useAsyncRateLimiter.ts#L27) + +#### Deprecated + +Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state. +The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally. +Although, you can make the state reactive by using the `useStore` in your own usage. diff --git a/docs/framework/preact/reference/interfaces/ReactAsyncThrottler.md b/docs/framework/preact/reference/interfaces/ReactAsyncThrottler.md new file mode 100644 index 00000000..34aa7058 --- /dev/null +++ b/docs/framework/preact/reference/interfaces/ReactAsyncThrottler.md @@ -0,0 +1,53 @@ +--- +id: ReactAsyncThrottler +title: ReactAsyncThrottler +--- + +# Interface: ReactAsyncThrottler\ + +Defined in: [preact-pacer/src/async-throttler/useAsyncThrottler.ts:12](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-throttler/useAsyncThrottler.ts#L12) + +## Extends + +- `Omit`\<`AsyncThrottler`\<`TFn`\>, `"store"`\> + +## Type Parameters + +### TFn + +`TFn` *extends* `AnyAsyncFunction` + +### TSelected + +`TSelected` = \{ +\} + +## Properties + +### state + +```ts +readonly state: Readonly; +``` + +Defined in: [preact-pacer/src/async-throttler/useAsyncThrottler.ts:21](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-throttler/useAsyncThrottler.ts#L21) + +Reactive state that will be updated and re-rendered when the throttler state changes + +Use this instead of `throttler.store.state` + +*** + +### ~~store~~ + +```ts +readonly store: Store>>; +``` + +Defined in: [preact-pacer/src/async-throttler/useAsyncThrottler.ts:27](https://github.com/TanStack/pacer/blob/main/packages/preact-pacer/src/async-throttler/useAsyncThrottler.ts#L27) + +#### Deprecated + +Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state. +The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally. +Although, you can make the state reactive by using the `useStore` in your own usage. diff --git a/examples/preact/asyncBatch/README.md b/examples/preact/asyncBatch/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/asyncBatch/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/asyncBatch/index.html b/examples/preact/asyncBatch/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/asyncBatch/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/asyncBatch/package.json b/examples/preact/asyncBatch/package.json new file mode 100644 index 00000000..b7593ce1 --- /dev/null +++ b/examples/preact/asyncBatch/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-async-batch", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/asyncBatch/public/emblem-light.svg b/examples/preact/asyncBatch/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/asyncBatch/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/asyncBatch/src/index.tsx b/examples/preact/asyncBatch/src/index.tsx new file mode 100644 index 00000000..45af67a9 --- /dev/null +++ b/examples/preact/asyncBatch/src/index.tsx @@ -0,0 +1,203 @@ +import { useCallback, useState } from 'preact/hooks' +import { render } from 'preact' +import { asyncBatch } from '@tanstack/preact-pacer/async-batcher' + +const fakeProcessingTime = 1000 + +type Item = { + id: number + value: string + timestamp: number +} + +function App() { + const [processedBatches, setProcessedBatches] = useState< + Array<{ items: Array; result: string; timestamp: number }> + >([]) + const [errors, setErrors] = useState>([]) + const [pendingItems, setPendingItems] = useState>([]) + const [isProcessing, setIsProcessing] = useState(false) + const [shouldFail, setShouldFail] = useState(false) + const [successCount, setSuccessCount] = useState(0) + const [errorCount, setErrorCount] = useState(0) + + // The async function that will process a batch of items + const processBatch = useCallback( + async (items: Array): Promise => { + console.log('Processing batch of', items.length, 'items:', items) + setIsProcessing(true) + + try { + // Simulate async processing time + await new Promise((resolve) => setTimeout(resolve, fakeProcessingTime)) + + // Simulate occasional failures for demo purposes + if (shouldFail && Math.random() < 0.3) { + throw new Error( + `Processing failed for batch with ${items.length} items`, + ) + } + + // Return a result from the batch processing + const result = `Processed ${items.length} items: ${items.map((item) => item.value).join(', ')}` + + setProcessedBatches((prev) => [ + ...prev, + { items, result, timestamp: Date.now() }, + ]) + + setSuccessCount((prev) => prev + 1) + console.log('Batch succeeded:', result) + + return result + } catch (error: any) { + setErrors((prev) => [ + ...prev, + `Error: ${error} (${new Date().toLocaleTimeString()})`, + ]) + setErrorCount((prev) => prev + 1) + console.error('Batch failed:', error) + throw error + } finally { + setIsProcessing(false) + } + }, + [shouldFail], + ) + + // Create the async batcher function using useCallback + const addToBatch = useCallback( + asyncBatch(processBatch, { + maxSize: 5, + wait: 3000, + getShouldExecute: (items) => + items.some((item) => item.value.includes('urgent')), + throwOnError: false, // Don't throw errors, handle them in the processBatch function + onItemsChange: (batcher) => { + setPendingItems(batcher.peekAllItems()) + }, + onSuccess: (result, batch, batcher) => { + console.log('AsyncBatcher succeeded:', result) + console.log('Processed batch:', batch) + console.log( + 'Total successful batches:', + batcher.store.state.successCount, + ) + }, + onError: (error: any, failedItems, batcher) => { + console.error('AsyncBatcher failed:', error) + console.log('Failed items:', failedItems) + console.log('Total failed batches:', batcher.store.state.errorCount) + }, + onSettled: (batch, batcher) => { + console.log('Batch settled:', batch) + console.log( + 'Total processed items:', + batcher.store.state.totalItemsProcessed, + ) + }, + }), + [], // must be memoized to avoid re-creating the batcher on every render (consider using useAsyncBatcher instead in preact) + ) + + const addItem = (isUrgent = false) => { + const nextId = Date.now() + const item: Item = { + id: nextId, + value: isUrgent ? `urgent-${nextId}` : `item-${nextId}`, + timestamp: nextId, + } + addToBatch(item) + } + + return ( +
+

TanStack Pacer asyncBatch Example

+ +
+

Batch Status

+
Pending Items: {pendingItems.length}
+
Max Batch Size: 5
+
Is Processing: {isProcessing ? 'Yes' : 'No'}
+
Successful Batches: {successCount}
+
Failed Batches: {errorCount}
+
+ +
+

Current Pending Items

+
+ {pendingItems.length === 0 ? ( + No items pending + ) : ( + pendingItems.map((item, index) => ( +
+ {index + 1}: {item.value} (added at{' '} + {new Date(item.timestamp).toLocaleTimeString()}) +
+ )) + )} +
+
+ +
+

Controls

+
+ + +
+ +
+ +
+
+ +
+

Processed Batches ({processedBatches.length})

+
+ {processedBatches.length === 0 ? ( + No batches processed yet + ) : ( + processedBatches.map((batch, index) => ( +
+ Batch {index + 1} (processed at{' '} + {new Date(batch.timestamp).toLocaleTimeString()}) +
{batch.result}
+
+ )) + )} +
+
+ + {errors.length > 0 && ( +
+

Errors ({errors.length})

+
+ {errors.map((error, index) => ( +
{error}
+ ))} +
+ +
+ )} +
+ ) +} + +const root = document.getElementById('root')! +render(, root) diff --git a/examples/preact/asyncBatch/tsconfig.json b/examples/preact/asyncBatch/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/asyncBatch/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/asyncBatch/vite.config.ts b/examples/preact/asyncBatch/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/asyncBatch/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/asyncDebounce/README.md b/examples/preact/asyncDebounce/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/asyncDebounce/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/asyncDebounce/index.html b/examples/preact/asyncDebounce/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/asyncDebounce/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/asyncDebounce/package.json b/examples/preact/asyncDebounce/package.json new file mode 100644 index 00000000..fb3d622a --- /dev/null +++ b/examples/preact/asyncDebounce/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-async-debounce", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/asyncDebounce/public/emblem-light.svg b/examples/preact/asyncDebounce/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/asyncDebounce/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/asyncDebounce/src/index.tsx b/examples/preact/asyncDebounce/src/index.tsx new file mode 100644 index 00000000..e1af2a69 --- /dev/null +++ b/examples/preact/asyncDebounce/src/index.tsx @@ -0,0 +1,85 @@ +import { useCallback, useState } from 'preact/hooks' +import { render } from 'preact' +import { asyncDebounce } from '@tanstack/preact-pacer/async-debouncer' + +function SearchApp() { + const [searchText, setSearchText] = useState('') + const [debouncedSearchText, setDebouncedSearchText] = useState('') + const [searchResults, setSearchResults] = useState>([]) + const [loading, setLoading] = useState(false) + + // Simulate search API + const simulateSearch = async (query: string) => { + await new Promise((resolve) => setTimeout(resolve, 800)) + return [ + `Result 1 for ${query}`, + `Result 2 for ${query}`, + `Result 3 for ${query}`, + ] + } + + const debouncedSetSearch = useCallback( + asyncDebounce( + async (value: string) => { + try { + setLoading(true) + setDebouncedSearchText(value) + const results = await simulateSearch(value) + setSearchResults(results) + } catch (err) { + setSearchResults([]) + } finally { + setLoading(false) + } + }, + { + wait: 500, + }, + ), + [], // must be memoized to avoid re-creating the debouncer on every render (consider using useAsyncDebouncer instead in preact) + ) + + return ( +
+

TanStack Pacer asyncDebounce Example

+
+ { + const newValue = e.currentTarget.value + setSearchText(newValue) + debouncedSetSearch(newValue) + }} + placeholder="Type to search..." + style={{ width: '100%' }} + /> + {loading &&
Loading...
} +
+ + + + + + + + + + + +
Instant Search:{searchText}
Debounced Search:{debouncedSearchText}
+
+

Search Results:

+
    + {searchResults.map((result, i) => ( +
  • {result}
  • + ))} +
+
+
+ ) +} + +const root = document.getElementById('root')! +render(, root) diff --git a/examples/preact/asyncDebounce/tsconfig.json b/examples/preact/asyncDebounce/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/asyncDebounce/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/asyncDebounce/vite.config.ts b/examples/preact/asyncDebounce/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/asyncDebounce/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/asyncRateLimit/README.md b/examples/preact/asyncRateLimit/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/asyncRateLimit/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/asyncRateLimit/index.html b/examples/preact/asyncRateLimit/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/asyncRateLimit/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/asyncRateLimit/package.json b/examples/preact/asyncRateLimit/package.json new file mode 100644 index 00000000..24e7d963 --- /dev/null +++ b/examples/preact/asyncRateLimit/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-async-rate-limit", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/asyncRateLimit/public/emblem-light.svg b/examples/preact/asyncRateLimit/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/asyncRateLimit/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/asyncRateLimit/src/index.tsx b/examples/preact/asyncRateLimit/src/index.tsx new file mode 100644 index 00000000..df64d00f --- /dev/null +++ b/examples/preact/asyncRateLimit/src/index.tsx @@ -0,0 +1,115 @@ +import { useCallback, useState } from 'preact/hooks' +import { render } from 'preact' +import { asyncRateLimit } from '@tanstack/preact-pacer/async-rate-limiter' + +function SearchApp() { + const [windowType, setWindowType] = useState<'fixed' | 'sliding'>('fixed') + const [searchText, setSearchText] = useState('') + const [rateLimitedSearchText, setRateLimitedSearchText] = useState('') + const [searchResults, setSearchResults] = useState>([]) + const [loading, setLoading] = useState(false) + + // Simulate search API + const simulateSearch = async (query: string) => { + await new Promise((resolve) => setTimeout(resolve, 800)) + return [ + `Result 1 for ${query}`, + `Result 2 for ${query}`, + `Result 3 for ${query}`, + ] + } + + const rateLimitedSetSearch = useCallback( + asyncRateLimit( + async (value: string) => { + try { + setLoading(true) + setRateLimitedSearchText(value) + const results = await simulateSearch(value) + setSearchResults(results) + } catch (err) { + setSearchResults([]) + } finally { + setLoading(false) + } + }, + { + limit: 5, + window: 5000, + windowType: windowType, + onReject: (_args, rateLimiter) => { + console.log( + `Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`, + ) + }, + }, + ), + [windowType], // must be memoized to avoid re-creating the rate limiter on every render (consider using useAsyncRateLimit instead in preact) + ) + + return ( +
+

TanStack Pacer asyncRateLimit Example

+
+ + +
+
+ { + const newValue = e.currentTarget.value + setSearchText(newValue) + rateLimitedSetSearch(newValue) + }} + placeholder="Type to search..." + style={{ width: '100%' }} + /> + {loading &&
Loading...
} +
+ + + + + + + + + + + +
Instant Search:{searchText}
Rate Limited Search:{rateLimitedSearchText}
+
+

Search Results:

+
    + {searchResults.map((result, i) => ( +
  • {result}
  • + ))} +
+
+
+ ) +} + +const root = document.getElementById('root')! +render(, root) diff --git a/examples/preact/asyncRateLimit/tsconfig.json b/examples/preact/asyncRateLimit/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/asyncRateLimit/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/asyncRateLimit/vite.config.ts b/examples/preact/asyncRateLimit/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/asyncRateLimit/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/asyncRetry/README.md b/examples/preact/asyncRetry/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/asyncRetry/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/asyncRetry/index.html b/examples/preact/asyncRetry/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/asyncRetry/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/asyncRetry/package.json b/examples/preact/asyncRetry/package.json new file mode 100644 index 00000000..6d096b27 --- /dev/null +++ b/examples/preact/asyncRetry/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-async-retry", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/asyncRetry/public/emblem-light.svg b/examples/preact/asyncRetry/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/asyncRetry/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/asyncRetry/src/index.tsx b/examples/preact/asyncRetry/src/index.tsx new file mode 100644 index 00000000..75b17eb3 --- /dev/null +++ b/examples/preact/asyncRetry/src/index.tsx @@ -0,0 +1,408 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import { asyncRetry } from '@tanstack/preact-pacer' + +interface UserData { + id: number + name: string + email: string +} + +// Simulate API call with fake data that can fail or timeout +const fakeApi = async ( + userId: string, + options: { shouldFail?: boolean; shouldTimeout?: boolean } = {}, +): Promise => { + const delay = options.shouldTimeout ? 3000 : 800 // Simulate network delay + await new Promise((resolve) => setTimeout(resolve, delay)) + + if (options.shouldFail || Math.random() < 0.6) { + throw new Error(`Network error fetching user ${userId}`) + } + + return { + id: parseInt(userId), + name: `User ${userId}`, + email: `user${userId}@example.com`, + } +} + +function App() { + const [userId, setUserId] = useState('123') + const [userData, setUserData] = useState(null) + const [isLoading, setIsLoading] = useState(false) + const [error, setError] = useState(null) + const [currentAttempt, setCurrentAttempt] = useState(0) + const [scenario, setScenario] = useState< + 'default' | 'timeout' | 'jitter' | 'linear' + >('default') + const [logs, setLogs] = useState([]) + + const addLog = (message: string) => { + setLogs((prev) => [ + ...prev.slice(-9), + `${new Date().toLocaleTimeString()}: ${message}`, + ]) + } + + // Get options based on selected scenario + const getOptions = () => { + const baseOptions = { + onRetry: (attempt: number, error: Error) => { + addLog(`Retry attempt ${attempt} after error: ${error.message}`) + setCurrentAttempt(attempt + 1) + }, + onError: (error: Error) => { + addLog(`Request failed: ${error.message}`) + }, + onLastError: (error: Error) => { + addLog(`All retries exhausted: ${error.message}`) + setError(error.message) + setUserData(null) + }, + onSuccess: (result: UserData) => { + addLog(`Request succeeded for user ${result.id}`) + setUserData(result) + setError(null) + }, + onSettled: () => { + addLog('Request settled') + setCurrentAttempt(0) + }, + } + + switch (scenario) { + case 'timeout': + return { + ...baseOptions, + maxAttempts: 3, + backoff: 'exponential' as const, + baseWait: 500, + maxExecutionTime: 2000, // Individual call timeout + maxTotalExecutionTime: 8000, // Total timeout for all retries + jitter: 0, + } + case 'jitter': + return { + ...baseOptions, + maxAttempts: 5, + backoff: 'exponential' as const, + baseWait: 500, + jitter: 0.3, // 30% random variation + } + case 'linear': + return { + ...baseOptions, + maxAttempts: 4, + backoff: 'linear' as const, + baseWait: 1000, + jitter: 0, + } + default: + return { + ...baseOptions, + maxAttempts: 5, + backoff: 'exponential' as const, + baseWait: 1000, + jitter: 0, + } + } + } + + // Handle fetch with retry - following docs pattern + async function onFetchUser() { + setLogs([]) + setIsLoading(true) + setError(null) + setCurrentAttempt(1) + addLog('Starting fetch operation') + + try { + // Create retry-enabled function + const fetchUserWithRetry = asyncRetry(async (id: string) => { + addLog(`Attempting to fetch user ${id}`) + return await fakeApi(id, { + shouldTimeout: scenario === 'timeout', + }) + }, getOptions()) + + // Call the retry-enabled function + const result = await fetchUserWithRetry(userId) + addLog(`Final result: ${result ? `User ${result.id}` : 'undefined'}`) + } catch (error) { + addLog( + `Caught error: ${error instanceof Error ? error.message : 'Unknown error'}`, + ) + setError(error instanceof Error ? error.message : 'Unknown error') + } finally { + setIsLoading(false) + } + } + + function onReset() { + setUserData(null) + setError(null) + setLogs([]) + setCurrentAttempt(0) + addLog('State reset') + } + + return ( +
+

TanStack Pacer asyncRetry Example

+

+ Demonstrates the asyncRetry utility function with configurable backoff + strategies, timeouts, jitter, and error handling. +

+ +
+
+

Configuration

+
+ + +
+ +
+ + setUserId(e.currentTarget.value)} + placeholder="Enter user ID..." + style={{ padding: '5px', width: '100%' }} + disabled={isLoading} + /> +
+ +
+ + +
+ +
+

Current Options:

+
+              {(() => {
+                const opts = getOptions()
+                return JSON.stringify(
+                  {
+                    maxAttempts: opts.maxAttempts,
+                    backoff: opts.backoff,
+                    baseWait: opts.baseWait,
+                    jitter: opts.jitter,
+                    maxExecutionTime:
+                      'maxExecutionTime' in opts
+                        ? opts.maxExecutionTime
+                        : Infinity,
+                    maxTotalExecutionTime:
+                      'maxTotalExecutionTime' in opts
+                        ? opts.maxTotalExecutionTime
+                        : Infinity,
+                  },
+                  null,
+                  2,
+                )
+              })()}
+            
+
+
+ +
+

State

+
+
+ Status:{' '} + 1 + ? '#ff8c00' + : '#ffd700' + : '#90ee90', + }} + > + {isLoading + ? currentAttempt > 1 + ? 'retrying' + : 'executing' + : 'idle'} + +
+ {currentAttempt > 0 && ( +

+ Current Attempt: {currentAttempt} /{' '} + {(() => { + const opts = getOptions() + return opts.maxAttempts + })()} +

+ )} + {error && ( +
+ Error: +
+ {error} +
+ )} +
+ + {userData && ( +
+

User Data:

+

+ ID: {userData.id} +

+

+ Name: {userData.name} +

+

+ Email: {userData.email} +

+
+ )} +
+
+ +
+

Activity Log

+
+ {logs.length === 0 ? ( +
No activity yet
+ ) : ( + logs.map((log, i) => ( +
+ {log} +
+ )) + )} +
+
+ +
+ Note: This example uses the asyncRetry{' '} + utility function, which creates a retry-enabled version of your async + function. Each call to the retry-enabled function creates a fresh retry + context. +
+ +
+ Key Features: +
    +
  • + Exponential Backoff: Wait time doubles with each + retry (1s, 2s, 4s, ...) +
  • +
  • + Linear Backoff: Wait time increases linearly (1s, + 2s, 3s, ...) +
  • +
  • + Jitter: Adds randomness to prevent thundering herd + problems +
  • +
  • + Timeouts: Control individual and total execution + time +
  • +
+
+
+ ) +} + +const root = document.getElementById('root')! +render(, root) diff --git a/examples/preact/asyncRetry/tsconfig.json b/examples/preact/asyncRetry/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/asyncRetry/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/asyncRetry/vite.config.ts b/examples/preact/asyncRetry/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/asyncRetry/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/asyncThrottle/README.md b/examples/preact/asyncThrottle/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/asyncThrottle/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/asyncThrottle/index.html b/examples/preact/asyncThrottle/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/asyncThrottle/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/asyncThrottle/package.json b/examples/preact/asyncThrottle/package.json new file mode 100644 index 00000000..216d2218 --- /dev/null +++ b/examples/preact/asyncThrottle/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-async-throttle", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/asyncThrottle/public/emblem-light.svg b/examples/preact/asyncThrottle/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/asyncThrottle/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/asyncThrottle/src/index.tsx b/examples/preact/asyncThrottle/src/index.tsx new file mode 100644 index 00000000..482a5106 --- /dev/null +++ b/examples/preact/asyncThrottle/src/index.tsx @@ -0,0 +1,85 @@ +import { useCallback, useState } from 'preact/hooks' +import { render } from 'preact' +import { asyncThrottle } from '@tanstack/preact-pacer/async-throttler' + +function SearchApp() { + const [searchText, setSearchText] = useState('') + const [throttledSearchText, setThrottledSearchText] = useState('') + const [searchResults, setSearchResults] = useState>([]) + const [loading, setLoading] = useState(false) + + // Simulate search API + const simulateSearch = async (query: string) => { + await new Promise((resolve) => setTimeout(resolve, 800)) + return [ + `Result 1 for ${query}`, + `Result 2 for ${query}`, + `Result 3 for ${query}`, + ] + } + + const throttledSetSearch = useCallback( + asyncThrottle( + async (value: string) => { + try { + setLoading(true) + setThrottledSearchText(value) + const results = await simulateSearch(value) + setSearchResults(results) + } catch (err) { + setSearchResults([]) + } finally { + setLoading(false) + } + }, + { + wait: 1000, + }, + ), + [], // must be memoized to avoid re-creating the throttler on every render (consider using useAsyncThrottler instead in preact) + ) + + return ( +
+

TanStack Pacer asyncThrottle Example

+
+ { + const newValue = e.currentTarget.value + setSearchText(newValue) + throttledSetSearch(newValue) + }} + placeholder="Type to search..." + style={{ width: '100%' }} + /> + {loading &&
Loading...
} +
+ + + + + + + + + + + +
Instant Search:{searchText}
Throttled Search:{throttledSearchText}
+
+

Search Results:

+
    + {searchResults.map((result, i) => ( +
  • {result}
  • + ))} +
+
+
+ ) +} + +const root = document.getElementById('root')! +render(, root) diff --git a/examples/preact/asyncThrottle/tsconfig.json b/examples/preact/asyncThrottle/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/asyncThrottle/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/asyncThrottle/vite.config.ts b/examples/preact/asyncThrottle/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/asyncThrottle/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/batch/README.md b/examples/preact/batch/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/batch/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/batch/index.html b/examples/preact/batch/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/batch/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/batch/package.json b/examples/preact/batch/package.json new file mode 100644 index 00000000..916ca309 --- /dev/null +++ b/examples/preact/batch/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-batch", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/batch/public/emblem-light.svg b/examples/preact/batch/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/batch/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/batch/src/index.tsx b/examples/preact/batch/src/index.tsx new file mode 100644 index 00000000..59d00e68 --- /dev/null +++ b/examples/preact/batch/src/index.tsx @@ -0,0 +1,55 @@ +import { useCallback, useState } from 'preact/hooks' +import { render } from 'preact' +import { batch } from '@tanstack/preact-pacer/batcher' + +function App() { + const [processedBatches, setProcessedBatches] = useState< + Array> + >([]) + const [batchItems, setBatchItems] = useState>([]) + + // Create the batcher function only once using useCallback + const addToBatch = useCallback( + batch( + (items) => { + setProcessedBatches((prev) => [...prev, items]) + console.log('Processing batch', items) + }, + { + maxSize: 5, + wait: 3000, + getShouldExecute: (items) => items.includes(42), + onItemsChange: (batcherInstance) => { + setBatchItems(batcherInstance.peekAllItems()) + }, + }, + ), + [], // must be memoized to avoid re-creating the batcher on every render (consider using useBatcher instead in preact) + ) + + return ( +
+

TanStack Pacer batcher Example

+
Batch Items: {batchItems.join(', ')}
+
+ Processed Batches:{' '} + {processedBatches.map((b, i) => ( + [{b.join(', ')}], + ))} +
+ +
+ ) +} + +const root = document.getElementById('root')! +render(, root) diff --git a/examples/preact/batch/tsconfig.json b/examples/preact/batch/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/batch/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/batch/vite.config.ts b/examples/preact/batch/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/batch/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/debounce/README.md b/examples/preact/debounce/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/debounce/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/debounce/index.html b/examples/preact/debounce/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/debounce/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/debounce/package.json b/examples/preact/debounce/package.json new file mode 100644 index 00000000..d199215e --- /dev/null +++ b/examples/preact/debounce/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-debounce", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/debounce/public/emblem-light.svg b/examples/preact/debounce/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/debounce/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/debounce/src/index.tsx b/examples/preact/debounce/src/index.tsx new file mode 100644 index 00000000..9d6449e2 --- /dev/null +++ b/examples/preact/debounce/src/index.tsx @@ -0,0 +1,161 @@ +import { useCallback, useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { debounce } from '@tanstack/preact-pacer/debouncer' + +function App1() { + // Use your state management library of choice + const [instantCount, setInstantCount] = useState(0) + const [debouncedCount, setDebouncedCount] = useState(0) + + // Create debounced setter function - Stable reference required! + const debouncedSetCount = useCallback( + debounce(setDebouncedCount, { + wait: 500, + // leading: true, // optional, defaults to false + }), + [], // must be memoized to avoid re-creating the debouncer on every render (consider using useDebouncer instead in preact) + ) + + function increment() { + // this pattern helps avoid common bugs with stale closures and state + setInstantCount((c) => { + const newInstantCount = c + 1 // common new value for both + debouncedSetCount(newInstantCount) // debounced state update + return newInstantCount // instant state update + }) + } + + return ( +
+

TanStack Pacer debounce Example 1

+ + + + + + + + + + + +
Instant Count:{instantCount}
Debounced Count:{debouncedCount}
+
+ +
+
+ ) +} + +function App2() { + const [searchText, setSearchText] = useState('') + const [debouncedSearchText, setDebouncedSearchText] = useState('') + + // Create debounced setter function - Stable reference required! + const debouncedSetSearch = useCallback( + debounce(setDebouncedSearchText, { + wait: 500, + }), + [], + ) + + function handleSearchChange(e: JSX.TargetedEvent) { + const newValue = e.currentTarget.value + setSearchText(newValue) + debouncedSetSearch(newValue) + } + + return ( +
+

TanStack Pacer debounce Example 2

+
+ +
+ + + + + + + + + + + +
Instant Search:{searchText}
Debounced Search:{debouncedSearchText}
+
+ ) +} + +function App3() { + const [instantValue, setInstantValue] = useState(50) + const [debouncedValue, setDebouncedValue] = useState(50) + + // Create debounced setter function - Stable reference required! + const debouncedSetValue = useCallback( + debounce(setDebouncedValue, { + wait: 250, + }), + [], + ) + + function handleRangeChange(e: JSX.TargetedEvent) { + const newValue = parseInt(e.currentTarget.value, 10) + setInstantValue(newValue) + debouncedSetValue(newValue) + } + + return ( +
+

TanStack Pacer debounce Example 3

+
+ +
+
+ +
+
+ ) +} + +const root = document.getElementById('root')! +render( +
+ +
+ +
+ +
, + root, +) diff --git a/examples/preact/debounce/tsconfig.json b/examples/preact/debounce/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/debounce/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/debounce/vite.config.ts b/examples/preact/debounce/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/debounce/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/queue/README.md b/examples/preact/queue/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/queue/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/queue/index.html b/examples/preact/queue/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/queue/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/queue/package.json b/examples/preact/queue/package.json new file mode 100644 index 00000000..cb41dfd7 --- /dev/null +++ b/examples/preact/queue/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-queue", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/queue/public/emblem-light.svg b/examples/preact/queue/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/queue/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/queue/src/index.tsx b/examples/preact/queue/src/index.tsx new file mode 100644 index 00000000..eb9c2678 --- /dev/null +++ b/examples/preact/queue/src/index.tsx @@ -0,0 +1,220 @@ +import { useCallback, useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { queue } from '@tanstack/preact-pacer/queuer' + +function App1() { + const [queueItems, setQueueItems] = useState>([]) + const [processedCount, setProcessedCount] = useState(0) + + function processQueueItem(item: number) { + console.log('Processing item:', item) + } + + // Create the simplified queuer function + const queueItem = useCallback( + queue(processQueueItem, { + key: 'Add Number Queue', + maxSize: 25, + wait: 1000, + onItemsChange: (queue) => { + setQueueItems(queue.peekAllItems()) + setProcessedCount(queue.store.state.executionCount) + }, + }), + [], // must be memoized to avoid re-creating the queue on every render (consider using useQueuer instead in preact) + ) + + return ( +
+

TanStack Pacer queue Example 1

+ + + + + + + + + + + + + + + +
Queue Size:{queueItems.length}
Items Processed:{processedCount}
Queue Items:{queueItems.join(', ')}
+ +
+ ) +} + +function App2() { + const [queueItems, setQueueItems] = useState>([]) + const [processedCount, setProcessedCount] = useState(0) + const [inputText, setInputText] = useState('') + const [queuedText, setQueuedText] = useState('') + + function processQueueItem(item: string) { + setQueuedText(item) + } + + // Create the simplified queuer function + const queueTextChange = useCallback( + queue(processQueueItem, { + key: 'Text Change Queue', + maxSize: 100, + wait: 500, + onItemsChange: (queue) => { + setQueueItems(queue.peekAllItems()) + setProcessedCount(queue.store.state.executionCount) + }, + }), + [], + ) + + function handleInputChange(e: JSX.TargetedEvent) { + const newValue = e.currentTarget.value + setInputText(newValue) + queueTextChange(newValue) + } + + return ( +
+

TanStack Pacer queue Example 2

+
+ +
+ + + + + + + + + + + + + + + + + + + +
Queued Text:{queuedText}
Queue Size:{queueItems.length}
Items Processed:{processedCount}
Queue Items:{queueItems.join(', ')}
+
+ ) +} + +function App3() { + const [queueItems, setQueueItems] = useState>([]) + const [processedCount, setProcessedCount] = useState(0) + const [currentValue, setCurrentValue] = useState(50) + const [queuedValue, setQueuedValue] = useState(50) + + function processQueueItem(item: number) { + setQueuedValue(item) + } + + // Create the simplified queuer function + const queueValue = useCallback( + queue(processQueueItem, { + key: 'Range Change Queue', + maxSize: 100, + wait: 100, + onItemsChange: (queue) => { + setQueueItems(queue.peekAllItems()) + setProcessedCount(queue.store.state.executionCount) + }, + }), + [], + ) + + function handleRangeChange(e: JSX.TargetedEvent) { + const newValue = parseInt(e.currentTarget.value, 10) + setCurrentValue(newValue) + queueValue(newValue) + } + + return ( +
+

TanStack Pacer queue Example 3

+
+ +
+
+ +
+ + + + + + + + + + + + + + + +
Queue Size:{queueItems.length}
Items Processed:{processedCount}
Queue Items:{queueItems.join(', ')}
+
+ ) +} + +const root = document.getElementById('root')! +render( +
+ +
+ +
+ +
, + root, +) diff --git a/examples/preact/queue/tsconfig.json b/examples/preact/queue/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/queue/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/queue/vite.config.ts b/examples/preact/queue/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/queue/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/rateLimit/README.md b/examples/preact/rateLimit/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/rateLimit/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/rateLimit/index.html b/examples/preact/rateLimit/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/rateLimit/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/rateLimit/package.json b/examples/preact/rateLimit/package.json new file mode 100644 index 00000000..0980da31 --- /dev/null +++ b/examples/preact/rateLimit/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-rate-limit", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/rateLimit/public/emblem-light.svg b/examples/preact/rateLimit/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/rateLimit/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/rateLimit/src/index.tsx b/examples/preact/rateLimit/src/index.tsx new file mode 100644 index 00000000..36ee9178 --- /dev/null +++ b/examples/preact/rateLimit/src/index.tsx @@ -0,0 +1,253 @@ +import { useCallback, useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { rateLimit } from '@tanstack/preact-pacer/rate-limiter' + +function App1() { + const [windowType, setWindowType] = useState<'fixed' | 'sliding'>('fixed') + // Use your state management library of choice + const [instantCount, setInstantCount] = useState(0) + const [rateLimitedCount, setRateLimitedCount] = useState(0) + + // Create rate-limited setter function - Stable reference required! + const rateLimitedSetCount = useCallback( + rateLimit(setRateLimitedCount, { + limit: 5, + window: 5000, + windowType: windowType, + onReject: (rateLimiter) => + console.log( + 'Rejected by rate limiter', + rateLimiter.getMsUntilNextWindow(), + ), + }), + [windowType], // must be memoized to avoid re-creating the rate limiter on every render (consider using useRateLimiter instead in preact) + ) + + function increment() { + // this pattern helps avoid common bugs with stale closures and state + setInstantCount((c) => { + const newInstantCount = c + 1 // common new value for both + rateLimitedSetCount(newInstantCount) // rate-limited state update + return newInstantCount // instant state update + }) + } + + return ( +
+

TanStack Pacer rateLimit Example 1

+
+ + +
+ + + + + + + + + + + +
Instant Count:{instantCount}
Rate Limited Count:{rateLimitedCount}
+
+ +
+
+ ) +} + +function App2() { + const [windowType, setWindowType] = useState<'fixed' | 'sliding'>('fixed') + const [text, setText] = useState('') + const [rateLimitedText, setRateLimitedText] = useState('') + + // Create rate-limited setter function - Stable reference required! + const rateLimitedSetText = useCallback( + rateLimit(setRateLimitedText, { + limit: 5, + window: 5000, + windowType: windowType, + onReject: (rateLimiter) => + console.log( + 'Rejected by rate limiter', + rateLimiter.getMsUntilNextWindow(), + ), + }), + [windowType], + ) + + function handleTextChange(e: JSX.TargetedEvent) { + const newValue = e.currentTarget.value + setText(newValue) + rateLimitedSetText(newValue) + } + + return ( +
+

TanStack Pacer rateLimit Example 2

+
+ + +
+
+ +
+ + + + + + + + + + + +
Instant Text:{text}
Rate Limited Text:{rateLimitedText}
+
+ ) +} + +function App3() { + const [windowType, setWindowType] = useState<'fixed' | 'sliding'>('fixed') + const [currentValue, setCurrentValue] = useState(50) + const [rateLimitedValue, setRateLimitedValue] = useState(50) + + // Create rate-limited setter function - Stable reference required! + const rateLimitedSetValue = useCallback( + rateLimit(setRateLimitedValue, { + limit: 30, + window: 2000, + windowType: windowType, + onReject: (rateLimiter) => + console.log( + 'Rejected by rate limiter', + rateLimiter.getMsUntilNextWindow(), + ), + }), + [windowType], + ) + + function handleRangeChange(e: JSX.TargetedEvent) { + const newValue = parseInt(e.currentTarget.value, 10) + setCurrentValue(newValue) + rateLimitedSetValue(newValue) + } + + return ( +
+

TanStack Pacer rateLimit Example 3

+
+ + +
+
+ +
+
+ +
+
+

Rate limited to 30 updates per 2000ms window

+
+
+ ) +} + +const root = document.getElementById('root')! +render( +
+ +
+ +
+ +
, + root, +) diff --git a/examples/preact/rateLimit/tsconfig.json b/examples/preact/rateLimit/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/rateLimit/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/rateLimit/vite.config.ts b/examples/preact/rateLimit/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/rateLimit/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/throttle/README.md b/examples/preact/throttle/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/throttle/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/throttle/index.html b/examples/preact/throttle/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/throttle/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/throttle/package.json b/examples/preact/throttle/package.json new file mode 100644 index 00000000..1cb4ce76 --- /dev/null +++ b/examples/preact/throttle/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-throttle", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/throttle/public/emblem-light.svg b/examples/preact/throttle/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/throttle/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/throttle/src/index.tsx b/examples/preact/throttle/src/index.tsx new file mode 100644 index 00000000..9b4634a5 --- /dev/null +++ b/examples/preact/throttle/src/index.tsx @@ -0,0 +1,173 @@ +import { useCallback, useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { throttle } from '@tanstack/preact-pacer/throttler' + +function App1() { + // Use your state management library of choice + const [instantCount, setInstantCount] = useState(0) + const [throttledCount, setThrottledCount] = useState(0) + + // Create throttled setter function - Stable reference required! + const throttledSetCount = useCallback( + throttle(setThrottledCount, { + wait: 1000, + }), + [], // must be memoized to avoid re-creating the throttler on every render (consider using useThrottler instead in preact) + ) + + function increment() { + // this pattern helps avoid common bugs with stale closures and state + setInstantCount((c) => { + const newInstantCount = c + 1 // common new value for both + throttledSetCount(newInstantCount) // throttled state update + return newInstantCount // instant state update + }) + } + + return ( +
+

TanStack Pacer throttle Example 1

+ + + + + + + + + + + +
Instant Count:{instantCount}
Throttled Count:{throttledCount}
+
+ +
+
+ ) +} + +function App2() { + const [text, setText] = useState('') + const [throttledText, setThrottledText] = useState('') + + // Create throttled setter function - Stable reference required! + const throttledSetText = useCallback( + throttle(setThrottledText, { + wait: 1000, + }), + [], + ) + + function handleTextChange(e: JSX.TargetedEvent) { + const newValue = e.currentTarget.value + setText(newValue) + throttledSetText(newValue) + } + + return ( +
+

TanStack Pacer throttle Example 2

+
+ +
+ + + + + + + + + + + +
Instant Text:{text}
Throttled Text:{throttledText}
+
+ ) +} + +function App3() { + const [currentValue, setCurrentValue] = useState(50) + const [throttledValue, setThrottledValue] = useState(50) + const [instantExecutionCount, setInstantExecutionCount] = useState(0) + + // Create throttled setter function - Stable reference required! + const throttledSetValue = useCallback( + throttle(setThrottledValue, { + wait: 250, + }), + [], + ) + + function handleRangeChange(e: JSX.TargetedEvent) { + const newValue = parseInt(e.currentTarget.value, 10) + setCurrentValue(newValue) + setInstantExecutionCount((c) => c + 1) + throttledSetValue(newValue) + } + + return ( +
+

TanStack Pacer throttle Example 3

+
+ +
+
+ +
+ + + + + + + +
Instant Executions:{instantExecutionCount}
+
+

Throttled with 250ms wait time

+
+
+ ) +} + +const root = document.getElementById('root')! +render( +
+ +
+ +
+ +
, + root, +) diff --git a/examples/preact/throttle/tsconfig.json b/examples/preact/throttle/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/throttle/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/throttle/vite.config.ts b/examples/preact/throttle/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/throttle/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useAsyncBatchedCallback/README.md b/examples/preact/useAsyncBatchedCallback/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useAsyncBatchedCallback/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useAsyncBatchedCallback/index.html b/examples/preact/useAsyncBatchedCallback/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useAsyncBatchedCallback/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useAsyncBatchedCallback/package.json b/examples/preact/useAsyncBatchedCallback/package.json new file mode 100644 index 00000000..291246ca --- /dev/null +++ b/examples/preact/useAsyncBatchedCallback/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-async-batched-callback", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useAsyncBatchedCallback/public/emblem-light.svg b/examples/preact/useAsyncBatchedCallback/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useAsyncBatchedCallback/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useAsyncBatchedCallback/src/index.tsx b/examples/preact/useAsyncBatchedCallback/src/index.tsx new file mode 100644 index 00000000..5c256ab0 --- /dev/null +++ b/examples/preact/useAsyncBatchedCallback/src/index.tsx @@ -0,0 +1,479 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import { useAsyncBatchedCallback } from '@tanstack/preact-pacer/async-batcher' + +interface SearchResult { + id: number + title: string + query: string +} + +// Simulate batched API search call +const batchedSearchApi = async ( + queries: Array, +): Promise> => { + await new Promise((resolve) => setTimeout(resolve, 800)) // Simulate network delay + + if (queries.some((q) => q === 'error')) { + throw new Error('Simulated batch API error') + } + + return queries.flatMap((query, index) => [ + { id: index * 10 + 1, title: `${query} result 1`, query }, + { id: index * 10 + 2, title: `${query} result 2`, query }, + ]) +} + +function App1() { + const [searchQueries, setSearchQueries] = useState>([]) + const [results, setResults] = useState>([]) + const [isLoading, setIsLoading] = useState(false) + const [error, setError] = useState(null) + const [batchesProcessed, setBatchesProcessed] = useState(0) + + // Create async batched search function - Stable reference provided by useAsyncBatchedCallback + const batchedSearch = useAsyncBatchedCallback( + async (queries: Array) => { + setIsLoading(true) + setError(null) + + try { + const data = await batchedSearchApi(queries) + setResults((current) => [...current, ...data]) + setBatchesProcessed((count) => count + 1) + return data + } catch (err) { + const errorMessage = + err instanceof Error ? err.message : 'Unknown error' + setError(errorMessage) + throw err + } finally { + setIsLoading(false) + } + }, + { + maxSize: 3, // Process when 3 queries collected + wait: 2000, // Or after 2 seconds + }, + ) + + function handleSearch(query: string) { + if (!query.trim()) return + + setSearchQueries((current) => [...current, query]) + batchedSearch(query) + } + + return ( +
+

TanStack Pacer useAsyncBatchedCallback Example 1

+
+ + + + +
+ + {isLoading &&

Processing batch search...

} + {error &&

Error: {error}

} + + + + + + + + + + + + + + + + +
Total Searches Made:{searchQueries.length}
Results Found:{results.length}
Batches Processed:{batchesProcessed}
+ +
+

Search Results:

+
+ {results.length === 0 ? ( +

No results yet...

+ ) : ( + results.map((result) => ( +
+ {result.query}: {result.title} +
+ )) + )} +
+
+ +

+ Searches are batched - max 3 queries or 2 second wait time +

+
+ ) +} + +interface EmailValidationRequest { + email: string + timestamp: Date +} + +interface EmailValidationResult { + email: string + isValid: boolean + message: string +} + +// Simulate batched email validation API +const batchValidateEmails = async ( + requests: Array, +): Promise> => { + await new Promise((resolve) => setTimeout(resolve, 600)) + + const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ + + return requests.map((request) => ({ + email: request.email, + isValid: emailRegex.test(request.email), + message: emailRegex.test(request.email) + ? 'Email is valid!' + : 'Invalid email format', + })) +} + +function App2() { + const [emailRequests, setEmailRequests] = useState< + Array + >([]) + const [validationResults, setValidationResults] = useState< + Array + >([]) + const [isValidating, setIsValidating] = useState(false) + const [batchesProcessed, setBatchesProcessed] = useState(0) + + // Create async batched email validation function + const batchedValidateEmail = useAsyncBatchedCallback( + async (requests: Array) => { + setIsValidating(true) + + try { + const results = await batchValidateEmails(requests) + setValidationResults((current) => [...current, ...results]) + setBatchesProcessed((count) => count + 1) + return results + } finally { + setIsValidating(false) + } + }, + { + maxSize: 4, // Process when 4 emails collected + wait: 1500, // Or after 1.5 seconds + }, + ) + + function validateEmail(email: string) { + if (!email.trim()) return + + const request: EmailValidationRequest = { + email, + timestamp: new Date(), + } + + setEmailRequests((current) => [...current, request]) + batchedValidateEmail(request) + } + + const sampleEmails = [ + 'user@example.com', + 'invalid-email', + 'test@domain.org', + 'bad@email', + 'good@test.com', + ] + + return ( +
+

TanStack Pacer useAsyncBatchedCallback Example 2

+
+ {sampleEmails.map((email, index) => ( + + ))} +
+ + {isValidating && ( +

Validating email batch...

+ )} + + + + + + + + + + + + + + + + +
Total Validations Requested:{emailRequests.length}
Validations Completed:{validationResults.length}
Batches Processed:{batchesProcessed}
+ +
+

Validation Results:

+
+ {validationResults.length === 0 ? ( +

No validations completed yet...

+ ) : ( + validationResults.map((result, index) => ( +
+ {result.email}: {result.message} +
+ )) + )} +
+
+ +

+ Email validations are batched - max 4 emails or 1.5 second wait time +

+
+ ) +} + +interface DataPoint { + id: string + value: number + category: string +} + +// Simulate batched data processing API +const batchProcessData = async ( + dataPoints: Array, +): Promise<{ processed: Array; summary: any }> => { + await new Promise((resolve) => setTimeout(resolve, 1000)) + + // Simulate processing + const processed = dataPoints.map((point) => ({ + ...point, + value: point.value * 2, // Double the values as "processing" + })) + + const summary = { + totalItems: processed.length, + totalValue: processed.reduce((sum, point) => sum + point.value, 0), + categories: [...new Set(processed.map((p) => p.category))].length, + } + + return { processed, summary } +} + +function App3() { + const [dataQueue, setDataQueue] = useState>([]) + const [processedData, setProcessedData] = useState>([]) + const [summaries, setSummaries] = useState>([]) + const [isProcessing, setIsProcessing] = useState(false) + const [batchesProcessed, setBatchesProcessed] = useState(0) + + // Create async batched data processor + const batchedDataProcessor = useAsyncBatchedCallback( + async (dataPoints: Array) => { + setIsProcessing(true) + + try { + const result = await batchProcessData(dataPoints) + setProcessedData((current) => [...current, ...result.processed]) + setSummaries((current) => [...current, result.summary]) + setBatchesProcessed((count) => count + 1) + return result + } finally { + setIsProcessing(false) + } + }, + { + maxSize: 5, // Process when 5 data points collected + wait: 2500, // Or after 2.5 seconds + }, + ) + + function addDataPoint(category: string) { + const dataPoint: DataPoint = { + id: `dp-${Date.now()}-${Math.random().toString(36).substr(2, 4)}`, + value: Math.floor(Math.random() * 100) + 1, + category, + } + + setDataQueue((current) => [...current, dataPoint]) + batchedDataProcessor(dataPoint) + } + + return ( +
+

TanStack Pacer useAsyncBatchedCallback Example 3

+
+ + + + +
+ + {isProcessing && ( +

Processing data batch...

+ )} + + + + + + + + + + + + + + + + +
Data Points Queued:{dataQueue.length}
Data Points Processed:{processedData.length}
Batches Completed:{batchesProcessed}
+ +
+
+

Processed Data:

+
+ {processedData.length === 0 ? ( +

No data processed yet...

+ ) : ( + processedData.map((point) => ( +
+ {point.category}: {point.value} ({point.id}) +
+ )) + )} +
+
+ +
+

Batch Summaries:

+
+ {summaries.length === 0 ? ( +

No summaries yet...

+ ) : ( + summaries.map((summary, index) => ( +
+ Batch {index + 1}: {summary.totalItems}{' '} + items, total value: {summary.totalValue}, categories:{' '} + {summary.categories} +
+ )) + )} +
+
+
+ +

+ Data processing is batched - max 5 items or 2.5 second wait time +

+
+ ) +} + +const root = document.getElementById('root')! +render( +
+ +
+ +
+ +
, + root, +) diff --git a/examples/preact/useAsyncBatchedCallback/tsconfig.json b/examples/preact/useAsyncBatchedCallback/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useAsyncBatchedCallback/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useAsyncBatchedCallback/vite.config.ts b/examples/preact/useAsyncBatchedCallback/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useAsyncBatchedCallback/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useAsyncBatcher/README.md b/examples/preact/useAsyncBatcher/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useAsyncBatcher/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useAsyncBatcher/index.html b/examples/preact/useAsyncBatcher/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useAsyncBatcher/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useAsyncBatcher/package.json b/examples/preact/useAsyncBatcher/package.json new file mode 100644 index 00000000..d1ed72f0 --- /dev/null +++ b/examples/preact/useAsyncBatcher/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-async-batcher", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useAsyncBatcher/public/emblem-light.svg b/examples/preact/useAsyncBatcher/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useAsyncBatcher/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useAsyncBatcher/src/index.tsx b/examples/preact/useAsyncBatcher/src/index.tsx new file mode 100644 index 00000000..6852618c --- /dev/null +++ b/examples/preact/useAsyncBatcher/src/index.tsx @@ -0,0 +1,218 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import { useAsyncBatcher } from '@tanstack/preact-pacer/async-batcher' +import { PacerProvider } from '@tanstack/preact-pacer/provider' + +const fakeProcessingTime = 1000 + +type Item = { + id: number + value: string + timestamp: number +} + +function App() { + const [processedBatches, setProcessedBatches] = useState< + Array<{ items: Array; result: string; timestamp: number }> + >([]) + const [errors, setErrors] = useState>([]) + + // The async function that will process a batch of items + async function processBatch(items: Array): Promise { + console.log('Processing batch of', items.length, 'items:', items) + + // Simulate async processing time + await new Promise((resolve) => setTimeout(resolve, fakeProcessingTime)) + + // Simulate occasional failures for demo purposes + + // throw new Error(`Processing failed for batch with ${items.length} items`) + + // Return a result from the batch processing + const result = `Processed ${items.length} items: ${items.map((item) => item.value).join(', ')}` + + setProcessedBatches((prev) => [ + ...prev, + { items, result, timestamp: Date.now() }, + ]) + + return result + } + + const asyncBatcher = useAsyncBatcher( + processBatch, + { + maxSize: 5, // Process in batches of 5 (if reached before wait time) + wait: 4000, // Wait up to 4 seconds before processing a batch + getShouldExecute: (items) => + items.some((item) => item.value.includes('urgent')), // Process immediately if any item is marked urgent + throwOnError: false, // Don't throw errors, handle them via onError + onSuccess: (result, batch, batcher) => { + console.log('Batch succeeded:', result) + console.log('Processed batch:', batch) + console.log( + 'Total successful batches:', + batcher.store.state.successCount, + ) + }, + onError: (error: any, _batcher) => { + console.error('Batch failed:', error) + setErrors((prev) => [ + ...prev, + `Error: ${error} (${new Date().toLocaleTimeString()})`, + ]) + }, + onSettled: (batch, batcher) => { + console.log('Batch settled:', batch) + console.log( + 'Total processed items:', + batcher.store.state.totalItemsProcessed, + ) + }, + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + size: state.size, + isExecuting: state.isExecuting, + status: state.status, + successCount: state.successCount, + errorCount: state.errorCount, + totalItemsProcessed: state.totalItemsProcessed, + }), + ) + + const addItem = (isUrgent = false) => { + const nextId = Date.now() + const item: Item = { + id: nextId, + value: isUrgent ? `urgent-${nextId}` : `item-${nextId}`, + timestamp: nextId, + } + asyncBatcher.addItem(item) + } + + const executeCurrentBatch = async () => { + try { + const result = await asyncBatcher.flush() + console.log('Manual execution result:', result) + } catch (error) { + console.error('Manual execution failed:', error) + } + } + + return ( +
+

TanStack Pacer useAsyncBatcher Example

+ +
+

Batch Status

+
Current Batch Size: {asyncBatcher.state.size}
+
Max Batch Size: 5
+
Is Executing: {asyncBatcher.state.isExecuting ? 'Yes' : 'No'}
+
Status: {asyncBatcher.state.status}
+
Successful Batches: {asyncBatcher.state.successCount}
+
Failed Batches: {asyncBatcher.state.errorCount}
+
+ Total Items Processed: {asyncBatcher.state.totalItemsProcessed} +
+
+ +
+

Current Batch Items

+
+ {asyncBatcher.peekAllItems().length === 0 ? ( + No items in current batch + ) : ( + asyncBatcher.peekAllItems().map((item, index) => ( +
+ {index + 1}: {item.value} (added at{' '} + {new Date(item.timestamp).toLocaleTimeString()}) +
+ )) + )} +
+
+ +
+

Controls

+
+ + + + +
+
+ +
+

Processed Batches ({processedBatches.length})

+
+ {processedBatches.length === 0 ? ( + No batches processed yet + ) : ( + processedBatches.map((batch, index) => ( +
+ Batch {index + 1} (processed at{' '} + {new Date(batch.timestamp).toLocaleTimeString()}) +
{batch.result}
+
+ )) + )} +
+
+ + {errors.length > 0 && ( +
+

Errors ({errors.length})

+
+ {errors.map((error, index) => ( +
{error}
+ ))} +
+ +
+ )} + +
+        {JSON.stringify(asyncBatcher.store.state, null, 2)}
+      
+
+ ) +} + +const root = document.getElementById('root')! +render( + // optionally, provide default options to an optional PacerProvider + + + , + root, +) diff --git a/examples/preact/useAsyncBatcher/tsconfig.json b/examples/preact/useAsyncBatcher/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useAsyncBatcher/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useAsyncBatcher/vite.config.ts b/examples/preact/useAsyncBatcher/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useAsyncBatcher/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useAsyncDebouncedCallback/README.md b/examples/preact/useAsyncDebouncedCallback/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useAsyncDebouncedCallback/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useAsyncDebouncedCallback/index.html b/examples/preact/useAsyncDebouncedCallback/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useAsyncDebouncedCallback/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useAsyncDebouncedCallback/package.json b/examples/preact/useAsyncDebouncedCallback/package.json new file mode 100644 index 00000000..57292cc5 --- /dev/null +++ b/examples/preact/useAsyncDebouncedCallback/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-use-async-debounced-callback", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useAsyncDebouncedCallback/public/emblem-light.svg b/examples/preact/useAsyncDebouncedCallback/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useAsyncDebouncedCallback/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useAsyncDebouncedCallback/src/index.tsx b/examples/preact/useAsyncDebouncedCallback/src/index.tsx new file mode 100644 index 00000000..5c522fa2 --- /dev/null +++ b/examples/preact/useAsyncDebouncedCallback/src/index.tsx @@ -0,0 +1,282 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { useAsyncDebouncedCallback } from '@tanstack/preact-pacer/async-debouncer' + +interface SearchResult { + id: number + title: string +} + +// Simulate API call with fake data +const fakeApi = async (term: string): Promise> => { + await new Promise((resolve) => setTimeout(resolve, 500)) // Simulate network delay + if (term === 'error') { + throw new Error('Simulated API error') + } + return [ + { id: 1, title: `${term} result ${Math.floor(Math.random() * 100)}` }, + { id: 2, title: `${term} result ${Math.floor(Math.random() * 100)}` }, + { id: 3, title: `${term} result ${Math.floor(Math.random() * 100)}` }, + ] +} + +function App1() { + const [searchTerm, setSearchTerm] = useState('') + const [results, setResults] = useState>([]) + const [isLoading, setIsLoading] = useState(false) + const [error, setError] = useState(null) + + // Create async debounced function - Stable reference provided by useAsyncDebouncedCallback + const debouncedSearch = useAsyncDebouncedCallback( + async (term: string) => { + if (!term.trim()) { + setResults([]) + return [] + } + + setIsLoading(true) + setError(null) + + try { + const data = await fakeApi(term) + setResults(data) + return data + } catch (err) { + const errorMessage = + err instanceof Error ? err.message : 'Unknown error' + setError(errorMessage) + setResults([]) + throw err + } finally { + setIsLoading(false) + } + }, + { + wait: 500, + // leading: true, // optional, defaults to false + // trailing: true, // optional, defaults to true + }, + ) + + async function handleSearchChange(e: JSX.TargetedEvent) { + const newValue = e.currentTarget.value + setSearchTerm(newValue) + + try { + await debouncedSearch(newValue) + } catch (err) { + // Error is already handled in the debounced function + console.log('Search failed:', err) + } + } + + return ( +
+

TanStack Pacer useAsyncDebouncedCallback Example 1

+
+ +
+ + {isLoading &&

Searching...

} + {error &&

Error: {error}

} + +
+

Current search term: {searchTerm}

+ {results.length > 0 && ( +
+

Results:

+
    + {results.map((result) => ( +
  • {result.title}
  • + ))} +
+
+ )} +
+
+ ) +} + +function App2() { + const [count, setCount] = useState(0) + const [apiCallCount, setApiCallCount] = useState(0) + + // Simulate API call that returns a value + const incrementApi = async (value: number): Promise => { + await new Promise((resolve) => setTimeout(resolve, 300)) + const newCount = value + 1 + setApiCallCount((prev) => prev + 1) + return newCount + } + + // Create async debounced increment function + const debouncedIncrement = useAsyncDebouncedCallback( + async (currentValue: number) => { + const result = await incrementApi(currentValue) + setCount(result) + return result + }, + { + wait: 1000, + leading: false, // Don't execute immediately + trailing: true, // Execute after delay + }, + ) + + function handleIncrement() { + // Update local state immediately for instant feedback + const newCount = count + 1 + setCount(newCount) + + // Debounced API call + debouncedIncrement(newCount) + } + + return ( +
+

TanStack Pacer useAsyncDebouncedCallback Example 2

+ + + + + + + + + + + +
Current Count:{count}
API Calls Made:{apiCallCount}
+
+ +
+

+ Click rapidly - API calls are debounced to 1 second, but UI updates + immediately +

+
+ ) +} + +function App3() { + const [email, setEmail] = useState('') + const [validationResult, setValidationResult] = useState<{ + isValid: boolean + message: string + } | null>(null) + const [isValidating, setIsValidating] = useState(false) + + // Simulate email validation API + const validateEmail = async ( + emailAddress: string, + ): Promise<{ isValid: boolean; message: string }> => { + await new Promise((resolve) => setTimeout(resolve, 400)) + + const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ + const isValid = emailRegex.test(emailAddress) + + return { + isValid, + message: isValid + ? 'Email is valid!' + : 'Please enter a valid email address', + } + } + + // Create debounced validation function + const debouncedValidateEmail = useAsyncDebouncedCallback( + async (emailAddress: string) => { + if (!emailAddress.trim()) { + setValidationResult(null) + return null + } + + setIsValidating(true) + + try { + const result = await validateEmail(emailAddress) + setValidationResult(result) + return result + } finally { + setIsValidating(false) + } + }, + { + wait: 750, + leading: false, + }, + ) + + function handleEmailChange(e: JSX.TargetedEvent) { + const newEmail = e.currentTarget.value + setEmail(newEmail) + debouncedValidateEmail(newEmail) + } + + return ( +
+

TanStack Pacer useAsyncDebouncedCallback Example 3

+
+ +
+ + {isValidating &&

Validating email...

} + + {validationResult && ( +

+ {validationResult.message} +

+ )} + +

+ Email validation is debounced to 750ms after you stop typing +

+
+ ) +} + +const root = document.getElementById('root')! +render( +
+ +
+ +
+ +
, + root, +) diff --git a/examples/preact/useAsyncDebouncedCallback/tsconfig.json b/examples/preact/useAsyncDebouncedCallback/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useAsyncDebouncedCallback/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useAsyncDebouncedCallback/vite.config.ts b/examples/preact/useAsyncDebouncedCallback/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useAsyncDebouncedCallback/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useAsyncDebouncer/README.md b/examples/preact/useAsyncDebouncer/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useAsyncDebouncer/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useAsyncDebouncer/index.html b/examples/preact/useAsyncDebouncer/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useAsyncDebouncer/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useAsyncDebouncer/package.json b/examples/preact/useAsyncDebouncer/package.json new file mode 100644 index 00000000..5c901354 --- /dev/null +++ b/examples/preact/useAsyncDebouncer/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-use-async-debouncer", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useAsyncDebouncer/public/emblem-light.svg b/examples/preact/useAsyncDebouncer/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useAsyncDebouncer/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useAsyncDebouncer/src/index.tsx b/examples/preact/useAsyncDebouncer/src/index.tsx new file mode 100644 index 00000000..c0861672 --- /dev/null +++ b/examples/preact/useAsyncDebouncer/src/index.tsx @@ -0,0 +1,140 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { useAsyncDebouncer } from '@tanstack/preact-pacer/async-debouncer' +import { PacerProvider } from '@tanstack/preact-pacer/provider' + +interface SearchResult { + id: number + title: string +} + +// Simulate API call with fake data +const fakeApi = async (term: string): Promise> => { + await new Promise((resolve) => setTimeout(resolve, 1500)) // Simulate network delay + return [ + { id: 1, title: `${term} result ${Math.floor(Math.random() * 100)}` }, + { id: 2, title: `${term} result ${Math.floor(Math.random() * 100)}` }, + { id: 3, title: `${term} result ${Math.floor(Math.random() * 100)}` }, + ] +} + +function App() { + const [searchTerm, setSearchTerm] = useState('') + const [results, setResults] = useState>([]) + + // The function that will become debounced + const handleSearch = async (term: string) => { + if (!term) { + setResults([]) + return + } + // throw new Error('Test error') // you don't have to catch errors here (though you still can). The onError optional handler will catch it + + const data = await fakeApi(term) + setResults(data) + + return data // this could alternatively be a void function without a return + } + + // hook that gives you an async debouncer instance + const asyncDebouncer = useAsyncDebouncer( + handleSearch, + { + // leading: true, // optional leading execution + wait: 500, // Wait 500ms between API calls + onError: (error) => { + // optional error handler + console.error('Search failed:', error) + setResults([]) + }, + // throwOnError: true, + asyncRetryerOptions: { + maxAttempts: 3, + maxExecutionTime: 1000, + }, + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + isExecuting: state.isExecuting, + isPending: state.isPending, + successCount: state.successCount, + }), + ) + + // get and name our debounced function + const handleSearchDebounced = asyncDebouncer.maybeExecute + + // instant event handler that calls both the instant local state setter and the debounced function + async function onSearchChange(e: JSX.TargetedEvent) { + const newTerm = e.currentTarget.value + setSearchTerm(newTerm) + const result = await handleSearchDebounced(newTerm) // optionally await result if you need to + console.log('result', result) + } + + return ( +
+

TanStack Pacer useAsyncDebouncer Example

+
+ +
+
+ +
+
+

API calls made: {asyncDebouncer.state.successCount}

+ {results.length > 0 && ( +
    + {results.map((item) => ( +
  • {item.title}
  • + ))} +
+ )} + {asyncDebouncer.state.isPending &&

Pending...

} + {asyncDebouncer.state.isExecuting &&

Executing...

} +
+          {JSON.stringify(asyncDebouncer.store.state, null, 2)}
+        
+
+
+ ) +} + +const root = document.getElementById('root')! + +function renderApp(mounted: boolean) { + render( + mounted ? ( + // defaultOptions can be provided to the PacerProvider to set default options for all instances + + + + ) : null, + root, + ) +} + +let mounted = true +renderApp(mounted) + +document.addEventListener('keydown', (e) => { + if (e.shiftKey && e.key === 'Enter') { + mounted = !mounted + renderApp(mounted) + } +}) diff --git a/examples/preact/useAsyncDebouncer/tsconfig.json b/examples/preact/useAsyncDebouncer/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useAsyncDebouncer/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useAsyncDebouncer/vite.config.ts b/examples/preact/useAsyncDebouncer/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useAsyncDebouncer/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useAsyncQueuedState/README.md b/examples/preact/useAsyncQueuedState/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useAsyncQueuedState/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useAsyncQueuedState/index.html b/examples/preact/useAsyncQueuedState/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useAsyncQueuedState/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useAsyncQueuedState/package.json b/examples/preact/useAsyncQueuedState/package.json new file mode 100644 index 00000000..dcbfc596 --- /dev/null +++ b/examples/preact/useAsyncQueuedState/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-async-queued-state", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useAsyncQueuedState/public/emblem-light.svg b/examples/preact/useAsyncQueuedState/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useAsyncQueuedState/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useAsyncQueuedState/src/index.tsx b/examples/preact/useAsyncQueuedState/src/index.tsx new file mode 100644 index 00000000..b243fcd3 --- /dev/null +++ b/examples/preact/useAsyncQueuedState/src/index.tsx @@ -0,0 +1,140 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import { useAsyncQueuedState } from '@tanstack/preact-pacer/async-queuer' + +const fakeWaitTime = 500 + +type Item = number + +function App() { + // Use your state management library of choice + const [concurrency, setConcurrency] = useState(2) + + // The function to process each item (now a number) + async function processItem(item: Item): Promise { + await new Promise((resolve) => setTimeout(resolve, fakeWaitTime)) + console.log(`Processed ${item}`) + } + + const [queueItems, asyncQueuer] = useAsyncQueuedState( + processItem, // your function to queue/process items + { + maxSize: 25, + initialItems: Array.from({ length: 10 }, (_, i) => i + 1), + concurrency, // Process 2 items concurrently + started: false, + wait: 100, // for demo purposes - usually you would not want extra wait time if you are also throttling with concurrency + onReject: (item: Item, asyncQueuer) => { + console.log( + 'Queue is full, rejecting item', + item, + asyncQueuer.store.state.rejectionCount, + ) + }, + onError: (error, item: Item, asyncQueuer) => { + console.error( + `Error processing item: ${item}`, + error, + asyncQueuer.store.state.errorCount, + ) // optionally, handle errors here instead of your own try/catch + }, + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + activeItems: state.activeItems, + isEmpty: state.isEmpty, + isFull: state.isFull, + isIdle: state.isIdle, + isRunning: state.isRunning, + items: state.items, // required for useAsyncQueuedState hook + rejectionCount: state.rejectionCount, + size: state.size, + status: state.status, + successCount: state.successCount, + }), + ) + + return ( +
+

TanStack Pacer useAsyncQueuer Example

+
+
Queue Size: {asyncQueuer.state.size}
+
Queue Max Size: {25}
+
Queue Full: {asyncQueuer.state.isFull ? 'Yes' : 'No'}
+
Queue Empty: {asyncQueuer.state.isEmpty ? 'Yes' : 'No'}
+
Queue Idle: {asyncQueuer.state.isIdle ? 'Yes' : 'No'}
+
Queuer Status: {asyncQueuer.state.status}
+
Items Processed: {asyncQueuer.state.successCount}
+
Items Rejected: {asyncQueuer.state.rejectionCount}
+
Active Tasks: {asyncQueuer.peekActiveItems().length}
+
Pending Tasks: {asyncQueuer.peekPendingItems().length}
+
+ Concurrency:{' '} + + setConcurrency(Math.max(1, parseInt(e.currentTarget.value) || 1)) + } + style={{ width: '60px' }} + /> +
+
+ Queue Items: + {queueItems.map((item, index) => ( +
+ {index}: {item} +
+ ))} +
+
+ + + +
+ + +
+
+        {JSON.stringify(asyncQueuer.store.state, null, 2)}
+      
+
+ ) +} + +const root = document.getElementById('root')! +render(, root) diff --git a/examples/preact/useAsyncQueuedState/tsconfig.json b/examples/preact/useAsyncQueuedState/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useAsyncQueuedState/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useAsyncQueuedState/vite.config.ts b/examples/preact/useAsyncQueuedState/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useAsyncQueuedState/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useAsyncQueuer/README.md b/examples/preact/useAsyncQueuer/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useAsyncQueuer/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useAsyncQueuer/index.html b/examples/preact/useAsyncQueuer/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useAsyncQueuer/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useAsyncQueuer/package.json b/examples/preact/useAsyncQueuer/package.json new file mode 100644 index 00000000..77f2f3da --- /dev/null +++ b/examples/preact/useAsyncQueuer/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-async-queuer", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useAsyncQueuer/public/emblem-light.svg b/examples/preact/useAsyncQueuer/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useAsyncQueuer/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useAsyncQueuer/src/index.tsx b/examples/preact/useAsyncQueuer/src/index.tsx new file mode 100644 index 00000000..0a36ee74 --- /dev/null +++ b/examples/preact/useAsyncQueuer/src/index.tsx @@ -0,0 +1,158 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import { useAsyncQueuer } from '@tanstack/preact-pacer/async-queuer' +import { PacerProvider } from '@tanstack/preact-pacer/provider' + +const fakeWaitTime = 500 + +type Item = number + +function App() { + const [concurrency, setConcurrency] = useState(2) + + // The function to process each item (now a number) + async function processItem(item: Item): Promise { + await new Promise((resolve) => setTimeout(resolve, fakeWaitTime)) + console.log(`Processed ${item}`) + } + + const asyncQueuer = useAsyncQueuer( + processItem, // your function to queue/process items + { + maxSize: 25, + initialItems: Array.from({ length: 10 }, (_, i) => i + 1), + concurrency, // Process 2 items concurrently + started: false, + wait: 100, // for demo purposes - usually you would not want extra wait time if you are also throttling with concurrency + onReject: (item, asyncQueuer) => { + console.log( + 'Queue is full, rejecting item', + item, + asyncQueuer.store.state.rejectionCount, + ) + }, + onError: (error, item: Item, asyncQueuer) => { + console.error( + `Error processing item: ${item}`, + error, + asyncQueuer.store.state.errorCount, + ) // optionally, handle errors here instead of your own try/catch + }, + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + size: state.size, + isFull: state.isFull, + isEmpty: state.isEmpty, + isIdle: state.isIdle, + status: state.status, + successCount: state.successCount, + rejectionCount: state.rejectionCount, + activeItems: state.activeItems, + items: state.items, + isRunning: state.isRunning, + }), + ) + + return ( +
+

TanStack Pacer useAsyncQueuer Example

+
+
Queue Size: {asyncQueuer.state.size}
+
Queue Max Size: {25}
+
Queue Full: {asyncQueuer.state.isFull ? 'Yes' : 'No'}
+
Queue Empty: {asyncQueuer.state.isEmpty ? 'Yes' : 'No'}
+
Queue Idle: {asyncQueuer.state.isIdle ? 'Yes' : 'No'}
+
Queuer Status: {asyncQueuer.state.status}
+
Items Processed: {asyncQueuer.state.successCount}
+
Items Rejected: {asyncQueuer.state.rejectionCount}
+
Active Tasks: {asyncQueuer.state.activeItems.length}
+
Pending Tasks: {asyncQueuer.state.items.length}
+
+ Concurrency:{' '} + + setConcurrency(Math.max(1, parseInt(e.currentTarget.value) || 1)) + } + style={{ width: '60px' }} + /> +
+
+ Queue Items: + {asyncQueuer.peekAllItems().map((item, index) => ( +
+ {index}: {item} +
+ ))} +
+
+ + + + + + + +
+
+        {JSON.stringify(asyncQueuer.store.state, null, 2)}
+      
+
+ ) +} + +const root = document.getElementById('root')! +render( + // optionally, provide default options to an optional PacerProvider + + + , + root, +) diff --git a/examples/preact/useAsyncQueuer/tsconfig.json b/examples/preact/useAsyncQueuer/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useAsyncQueuer/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useAsyncQueuer/vite.config.ts b/examples/preact/useAsyncQueuer/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useAsyncQueuer/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useAsyncRateLimiter/README.md b/examples/preact/useAsyncRateLimiter/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useAsyncRateLimiter/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useAsyncRateLimiter/index.html b/examples/preact/useAsyncRateLimiter/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useAsyncRateLimiter/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useAsyncRateLimiter/package.json b/examples/preact/useAsyncRateLimiter/package.json new file mode 100644 index 00000000..fe9918f5 --- /dev/null +++ b/examples/preact/useAsyncRateLimiter/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-async-rate-limiter", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useAsyncRateLimiter/public/emblem-light.svg b/examples/preact/useAsyncRateLimiter/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useAsyncRateLimiter/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useAsyncRateLimiter/src/index.tsx b/examples/preact/useAsyncRateLimiter/src/index.tsx new file mode 100644 index 00000000..20e7b784 --- /dev/null +++ b/examples/preact/useAsyncRateLimiter/src/index.tsx @@ -0,0 +1,204 @@ +import { useEffect, useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { useAsyncRateLimiter } from '@tanstack/preact-pacer/async-rate-limiter' +import { PacerProvider } from '@tanstack/preact-pacer/provider' + +interface SearchResult { + id: number + title: string +} + +// Simulate API call with fake data +const fakeApi = async (term: string): Promise> => { + await new Promise((resolve) => setTimeout(resolve, 300)) // Simulate network delay + return [ + { id: 1, title: `${term} result ${Math.floor(Math.random() * 100)}` }, + { id: 2, title: `${term} result ${Math.floor(Math.random() * 100)}` }, + { id: 3, title: `${term} result ${Math.floor(Math.random() * 100)}` }, + ] +} + +function App() { + const [windowType, setWindowType] = useState<'fixed' | 'sliding'>('fixed') + const [searchTerm, setSearchTerm] = useState('') + const [results, setResults] = useState>([]) + const [error, setError] = useState(null) + + // The function that will become rate limited + const handleSearch = async (term: string) => { + if (!term) { + setResults([]) + return + } + + // throw new Error('Test error') // you don't have to catch errors here (though you still can). The onError optional handler will catch it + + const data = await fakeApi(term) + setResults(data) + setError(null) + + console.log(setSearchAsyncRateLimiter.state.successCount) + } + + // hook that gives you an async rate limiter instance + const setSearchAsyncRateLimiter = useAsyncRateLimiter( + handleSearch, + { + windowType: windowType, + limit: 3, // Maximum 2 requests + window: 3000, // per 1 second + onReject: (_args, rateLimiter) => { + console.log( + `Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`, + ) + }, + onError: (error) => { + // optional error handler + console.error('Search failed:', error) + setError(error as Error) + setResults([]) + }, + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + successCount: state.successCount, + rejectionCount: state.rejectionCount, + isExecuting: state.isExecuting, + }), + ) + + // get and name our rate limited function + const handleSearchRateLimited = setSearchAsyncRateLimiter.maybeExecute + + useEffect(() => { + console.log('mount') + return () => { + console.log('unmount') + setSearchAsyncRateLimiter.reset() // cancel any pending async calls when the component unmounts + } + }, []) + + // instant event handler that calls both the instant local state setter and the rate limited function + async function onSearchChange(e: JSX.TargetedEvent) { + const newTerm = e.currentTarget.value + setSearchTerm(newTerm) + await handleSearchRateLimited(newTerm) // optionally await if you need to + } + + return ( +
+

TanStack Pacer useAsyncRateLimiter Example

+
+ + +
+
+ +
+ {error &&
Error: {error.message}
} +
+ + + + + + + + + + + + + + + + + + + +
API calls made:{setSearchAsyncRateLimiter.state.successCount}
Rejected calls:{setSearchAsyncRateLimiter.state.rejectionCount}
Is executing: + {setSearchAsyncRateLimiter.state.isExecuting ? 'Yes' : 'No'} +
Results: + {results.length > 0 ? ( +
    + {results.map((item) => ( +
  • {item.title}
  • + ))} +
+ ) : ( + 'No results' + )} +
+
+
+        {JSON.stringify(setSearchAsyncRateLimiter.store.state, null, 2)}
+      
+
+ ) +} + +const root = document.getElementById('root')! + +let mounted = true +render( + // optionally, provide default options to an optional PacerProvider + + + , + root, +) + +// demo unmounting and cancellation +document.addEventListener('keydown', (e) => { + if (e.key === 'Enter') { + mounted = !mounted + render( + mounted ? ( + // optionally, provide default options to an optional PacerProvider + + + + ) : null, + root, + ) + } +}) diff --git a/examples/preact/useAsyncRateLimiter/tsconfig.json b/examples/preact/useAsyncRateLimiter/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useAsyncRateLimiter/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useAsyncRateLimiter/vite.config.ts b/examples/preact/useAsyncRateLimiter/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useAsyncRateLimiter/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useAsyncRateLimiterWithPersister/README.md b/examples/preact/useAsyncRateLimiterWithPersister/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useAsyncRateLimiterWithPersister/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useAsyncRateLimiterWithPersister/index.html b/examples/preact/useAsyncRateLimiterWithPersister/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useAsyncRateLimiterWithPersister/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useAsyncRateLimiterWithPersister/package.json b/examples/preact/useAsyncRateLimiterWithPersister/package.json new file mode 100644 index 00000000..f5e60b2e --- /dev/null +++ b/examples/preact/useAsyncRateLimiterWithPersister/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-async-rate-limiter-with-persister", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useAsyncRateLimiterWithPersister/public/emblem-light.svg b/examples/preact/useAsyncRateLimiterWithPersister/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useAsyncRateLimiterWithPersister/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useAsyncRateLimiterWithPersister/src/index.tsx b/examples/preact/useAsyncRateLimiterWithPersister/src/index.tsx new file mode 100644 index 00000000..c7a54b7a --- /dev/null +++ b/examples/preact/useAsyncRateLimiterWithPersister/src/index.tsx @@ -0,0 +1,190 @@ +import { useEffect, useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { useAsyncRateLimiter } from '@tanstack/preact-pacer/async-rate-limiter' +// import { useStoragePersister } from '@tanstack/preact-persister/storage-persister' +// import type { AsyncRateLimiterState } from '@tanstack/preact-pacer/async-rate-limiter' + +interface SearchResult { + id: number + title: string +} + +// Simulate API call with fake data +const fakeApi = async (term: string): Promise> => { + await new Promise((resolve) => setTimeout(resolve, 300)) // Simulate network delay + return [ + { id: 1, title: `${term} result ${Math.floor(Math.random() * 100)}` }, + { id: 2, title: `${term} result ${Math.floor(Math.random() * 100)}` }, + { id: 3, title: `${term} result ${Math.floor(Math.random() * 100)}` }, + ] +} + +function App() { + const [windowType, setWindowType] = useState<'fixed' | 'sliding'>('fixed') + const [searchTerm, setSearchTerm] = useState('') + const [results, setResults] = useState>([]) + const [error, setError] = useState(null) + + // The function that will become rate limited + const handleSearch = async (term: string) => { + if (!term) { + setResults([]) + return + } + + // throw new Error('Test error') // you don't have to catch errors here (though you still can). The onError optional handler will catch it + + const data = await fakeApi(term) + setResults(data) + setError(null) + + console.log(setSearchAsyncRateLimiter.state.successCount) + } + + // const rateLimiterPersister = useStoragePersister< + // AsyncRateLimiterState + // >({ + // key: 'my-async-rate-limiter', + // storage: localStorage, + // maxAge: 1000 * 60, // 1 minute + // buster: 'v1', + // }) + + // hook that gives you an async rate limiter instance + const setSearchAsyncRateLimiter = useAsyncRateLimiter( + handleSearch, + { + windowType: windowType, + limit: 3, // Maximum 2 requests + window: 3000, // per 1 second + onReject: (_args, rateLimiter) => { + console.log( + `Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`, + ) + }, + onError: (error) => { + // optional error handler + console.error('Search failed:', error) + setError(error as Error) + setResults([]) + }, + // optionally, you can persist the rate limiter state to localStorage + // initialState: rateLimiterPersister.loadState(), + }, + // Optional Selector function to pick the state you want to track and use + (state) => state, // entire state subscription for persister - don't do this unless you need to + ) + + // useEffect(() => { + // rateLimiterPersister.saveState(setSearchAsyncRateLimiter.state) + // }, [setSearchAsyncRateLimiter.state]) + + // get and name our rate limited function + const handleSearchRateLimited = setSearchAsyncRateLimiter.maybeExecute + + useEffect(() => { + console.log('mount') + return () => { + console.log('unmount') + setSearchAsyncRateLimiter.reset() // cancel any pending async calls when the component unmounts + } + }, []) + + // instant event handler that calls both the instant local state setter and the rate limited function + async function onSearchChange(e: JSX.TargetedEvent) { + const newTerm = e.currentTarget.value + setSearchTerm(newTerm) + await handleSearchRateLimited(newTerm) // optionally await if you need to + } + + return ( +
+

TanStack Pacer useAsyncRateLimiter Example (with persister)

+
+ + +
+
+ +
+ {error &&
Error: {error.message}
} +
+ + + + + + + + + + + + + + + + + + + +
API calls made:{setSearchAsyncRateLimiter.state.successCount}
Rejected calls:{setSearchAsyncRateLimiter.state.rejectionCount}
Is executing: + {setSearchAsyncRateLimiter.state.isExecuting ? 'Yes' : 'No'} +
Results: + {results.length > 0 ? ( +
    + {results.map((item) => ( +
  • {item.title}
  • + ))} +
+ ) : ( + 'No results' + )} +
+
+
+        {JSON.stringify(setSearchAsyncRateLimiter.store.state, null, 2)}
+      
+
+ ) +} + +const root = document.getElementById('root')! + +let mounted = true +render(, root) + +// demo unmounting and cancellation +document.addEventListener('keydown', (e) => { + if (e.key === 'Enter') { + mounted = !mounted + render(mounted ? : null, root) + } +}) diff --git a/examples/preact/useAsyncRateLimiterWithPersister/tsconfig.json b/examples/preact/useAsyncRateLimiterWithPersister/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useAsyncRateLimiterWithPersister/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useAsyncRateLimiterWithPersister/vite.config.ts b/examples/preact/useAsyncRateLimiterWithPersister/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useAsyncRateLimiterWithPersister/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useAsyncThrottledCallback/README.md b/examples/preact/useAsyncThrottledCallback/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useAsyncThrottledCallback/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useAsyncThrottledCallback/index.html b/examples/preact/useAsyncThrottledCallback/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useAsyncThrottledCallback/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useAsyncThrottledCallback/package.json b/examples/preact/useAsyncThrottledCallback/package.json new file mode 100644 index 00000000..e5470f54 --- /dev/null +++ b/examples/preact/useAsyncThrottledCallback/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-async-throttled-callback", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useAsyncThrottledCallback/public/emblem-light.svg b/examples/preact/useAsyncThrottledCallback/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useAsyncThrottledCallback/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useAsyncThrottledCallback/src/index.tsx b/examples/preact/useAsyncThrottledCallback/src/index.tsx new file mode 100644 index 00000000..1ec863ce --- /dev/null +++ b/examples/preact/useAsyncThrottledCallback/src/index.tsx @@ -0,0 +1,264 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { useAsyncThrottledCallback } from '@tanstack/preact-pacer/async-throttler' + +interface SearchResult { + id: number + title: string +} + +// Simulate API call with fake data +const fakeApi = async (term: string): Promise> => { + await new Promise((resolve) => setTimeout(resolve, 500)) // Simulate network delay + if (term === 'error') { + throw new Error('Simulated API error') + } + return [ + { id: 1, title: `${term} result ${Math.floor(Math.random() * 100)}` }, + { id: 2, title: `${term} result ${Math.floor(Math.random() * 100)}` }, + { id: 3, title: `${term} result ${Math.floor(Math.random() * 100)}` }, + ] +} + +function App1() { + const [searchTerm, setSearchTerm] = useState('') + const [results, setResults] = useState>([]) + const [isLoading, setIsLoading] = useState(false) + const [error, setError] = useState(null) + + // Create async throttled function - Stable reference provided by useAsyncThrottledCallback + const throttledSearch = useAsyncThrottledCallback( + async (term: string) => { + if (!term.trim()) { + setResults([]) + return [] + } + + setIsLoading(true) + setError(null) + + try { + const data = await fakeApi(term) + setResults(data) + return data + } catch (err) { + const errorMessage = + err instanceof Error ? err.message : 'Unknown error' + setError(errorMessage) + setResults([]) + throw err + } finally { + setIsLoading(false) + } + }, + { + wait: 1000, + // leading: true, // optional, defaults to true + // trailing: true, // optional, defaults to true + }, + ) + + async function handleSearchChange(e: JSX.TargetedEvent) { + const newValue = e.currentTarget.value + setSearchTerm(newValue) + + try { + await throttledSearch(newValue) + } catch (err) { + // Error is already handled in the throttled function + console.log('Search failed:', err) + } + } + + return ( +
+

TanStack Pacer useAsyncThrottledCallback Example 1

+
+ +
+ + {isLoading &&

Searching...

} + {error &&

Error: {error}

} + +
+

Current search term: {searchTerm}

+ {results.length > 0 && ( +
+

Results:

+
    + {results.map((result) => ( +
  • {result.title}
  • + ))} +
+
+ )} +
+
+ ) +} + +function App2() { + const [count, setCount] = useState(0) + const [apiCallCount, setApiCallCount] = useState(0) + + // Simulate API call that returns a value + const incrementApi = async (value: number): Promise => { + await new Promise((resolve) => setTimeout(resolve, 300)) + const newCount = value + 1 + setApiCallCount((prev) => prev + 1) + return newCount + } + + // Create async throttled increment function + const throttledIncrement = useAsyncThrottledCallback( + async (currentValue: number) => { + const result = await incrementApi(currentValue) + setCount(result) + return result + }, + { + wait: 1000, + leading: true, // Execute immediately on first call + trailing: true, // Execute after throttle period ends + }, + ) + + function handleIncrement() { + // Update local state immediately for instant feedback + setCount((prev) => { + const newCount = prev + 1 + throttledIncrement(newCount) + return newCount + }) + } + + return ( +
+

TanStack Pacer useAsyncThrottledCallback Example 2

+ + + + + + + + + + + +
Current Count:{count}
API Calls Made:{apiCallCount}
+
+ +
+

+ Click rapidly - API calls are throttled to 1 second, but UI updates + immediately. First click executes immediately, then at most once per + second. +

+
+ ) +} + +function App3() { + const [scrollPosition, setScrollPosition] = useState(0) + const [saveCount, setSaveCount] = useState(0) + const [lastSaved, setLastSaved] = useState(null) + const [isSaving, setIsSaving] = useState(false) + + // Simulate saving scroll position to server + const saveScrollPosition = async ( + position: number, + ): Promise<{ success: boolean; position: number }> => { + await new Promise((resolve) => setTimeout(resolve, 300)) + return { success: true, position } + } + + // Create throttled save function + const throttledSave = useAsyncThrottledCallback( + async (position: number) => { + setIsSaving(true) + + try { + const result = await saveScrollPosition(position) + setSaveCount((prev) => prev + 1) + setLastSaved(new Date()) + return result + } finally { + setIsSaving(false) + } + }, + { + wait: 1000, + leading: true, + trailing: true, + }, + ) + + function handleScroll(e: JSX.TargetedEvent) { + const position = e.currentTarget.scrollTop + setScrollPosition(position) + throttledSave(position) + } + + return ( +
+

TanStack Pacer useAsyncThrottledCallback Example 3

+
+
+

Scroll this area to trigger throttled saves!

+

Current scroll position: {Math.round(scrollPosition)}px

+ {isSaving &&

Saving position...

} +
+

Saves triggered: {saveCount}

+ {lastSaved && ( +

Last saved at: {lastSaved.toLocaleTimeString()}

+ )} +
+
+

Keep scrolling...

+

More content...

+

Even more content...

+

Almost there...

+

You made it to the end!

+
+
+
+ +

+ Scroll position is saved at most once per second, but updates instantly + on screen +

+
+ ) +} + +const root = document.getElementById('root')! +render( +
+ +
+ +
+ +
, + root, +) diff --git a/examples/preact/useAsyncThrottledCallback/tsconfig.json b/examples/preact/useAsyncThrottledCallback/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useAsyncThrottledCallback/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useAsyncThrottledCallback/vite.config.ts b/examples/preact/useAsyncThrottledCallback/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useAsyncThrottledCallback/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useAsyncThrottler/README.md b/examples/preact/useAsyncThrottler/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useAsyncThrottler/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useAsyncThrottler/index.html b/examples/preact/useAsyncThrottler/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useAsyncThrottler/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useAsyncThrottler/package.json b/examples/preact/useAsyncThrottler/package.json new file mode 100644 index 00000000..154edb30 --- /dev/null +++ b/examples/preact/useAsyncThrottler/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-async-throttler", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useAsyncThrottler/public/emblem-light.svg b/examples/preact/useAsyncThrottler/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useAsyncThrottler/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useAsyncThrottler/src/index.tsx b/examples/preact/useAsyncThrottler/src/index.tsx new file mode 100644 index 00000000..715d8e3e --- /dev/null +++ b/examples/preact/useAsyncThrottler/src/index.tsx @@ -0,0 +1,127 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { useAsyncThrottler } from '@tanstack/preact-pacer/async-throttler' +import { PacerProvider } from '@tanstack/preact-pacer/provider' + +interface SearchResult { + id: number + title: string +} + +// Simulate API call with fake data +const fakeApi = async (term: string): Promise> => { + await new Promise((resolve) => setTimeout(resolve, 500)) // Simulate network delay + return [ + { id: 1, title: `${term} result ${Math.floor(Math.random() * 100)}` }, + { id: 2, title: `${term} result ${Math.floor(Math.random() * 100)}` }, + { id: 3, title: `${term} result ${Math.floor(Math.random() * 100)}` }, + ] +} + +function App() { + const [searchTerm, setSearchTerm] = useState('') + const [results, setResults] = useState>([]) + const [error, setError] = useState(null) + + // The function that will become throttled + const handleSearch = async (term: string) => { + if (!term) { + setResults([]) + return + } + + // throw new Error('Test error') // you don't have to catch errors here (though you still can). The onError optional handler will catch it + + const data = await fakeApi(term) + setResults(data) + setError(null) + + return data // this could alternatively be a void function without a return + } + + // hook that gives you an async throttler instance + const setSearchAsyncThrottler = useAsyncThrottler( + handleSearch, + { + // leading: true, // default + // trailing: true, // default + wait: 1000, // Wait 1 second between API calls + onError: (error) => { + // optional error handler + console.error('Search failed:', error) + setError(error as Error) + setResults([]) + }, + // throwOnError: true, + }, + // Optional Selector function to pick the state you want to track and use + (state) => state, + ) + + // get and name our throttled function + const handleSearchThrottled = setSearchAsyncThrottler.maybeExecute + + // instant event handler that calls both the instant local state setter and the throttled function + async function onSearchChange(e: JSX.TargetedEvent) { + const newTerm = e.currentTarget.value + setSearchTerm(newTerm) + const result = await handleSearchThrottled(newTerm) // optionally await if you need to + console.log('result', result) + } + + return ( +
+

TanStack Pacer useAsyncThrottler Example

+
+ +
+
+ +
+ {error &&
Error: {error.message}
} +
+

API calls made: {setSearchAsyncThrottler.state.successCount}

+ {results.length > 0 && ( +
    + {results.map((item) => ( +
  • {item.title}
  • + ))} +
+ )} + {setSearchAsyncThrottler.state.isPending ? ( +

Pending...

+ ) : setSearchAsyncThrottler.state.isExecuting ? ( +

Executing...

+ ) : null} +
+          {JSON.stringify(setSearchAsyncThrottler.store.state, null, 2)}
+        
+
+
+ ) +} + +const root = document.getElementById('root')! + +// optionally, provide default options to an optional PacerProvider +render( + + + , + root, +) diff --git a/examples/preact/useAsyncThrottler/tsconfig.json b/examples/preact/useAsyncThrottler/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useAsyncThrottler/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useAsyncThrottler/vite.config.ts b/examples/preact/useAsyncThrottler/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useAsyncThrottler/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useBatchedCallback/README.md b/examples/preact/useBatchedCallback/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useBatchedCallback/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useBatchedCallback/index.html b/examples/preact/useBatchedCallback/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useBatchedCallback/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useBatchedCallback/package.json b/examples/preact/useBatchedCallback/package.json new file mode 100644 index 00000000..3bc17a31 --- /dev/null +++ b/examples/preact/useBatchedCallback/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-batched-callback", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useBatchedCallback/public/emblem-light.svg b/examples/preact/useBatchedCallback/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useBatchedCallback/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useBatchedCallback/src/index.tsx b/examples/preact/useBatchedCallback/src/index.tsx new file mode 100644 index 00000000..180eaf4c --- /dev/null +++ b/examples/preact/useBatchedCallback/src/index.tsx @@ -0,0 +1,369 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import { useBatchedCallback } from '@tanstack/preact-pacer/batcher' + +interface LogEntry { + id: number + message: string + timestamp: Date +} + +function App1() { + const [logs, setLogs] = useState([]) + const [logCount, setLogCount] = useState(0) + + // Create batched logger function - Stable reference provided by useBatchedCallback + const batchedLogger = useBatchedCallback( + (entries: LogEntry[]) => { + console.log('Processing batch of logs:', entries) + setLogs((current) => [...current, ...entries]) + }, + { + maxSize: 3, // Process when 3 logs collected + wait: 2000, // Or after 2 seconds + }, + ) + + function addLog(message: string) { + const newLog: LogEntry = { + id: Date.now() + Math.random(), + message, + timestamp: new Date(), + } + setLogCount((c) => c + 1) + batchedLogger(newLog) + } + + return ( +
+

TanStack Pacer useBatchedCallback Example 1

+
+ + + +
+ + + + + + + + + + + + +
Total Logs Created:{logCount}
Logs Processed:{logs.length}
+ +
+

Processed Logs:

+
+ {logs.length === 0 ? ( +

No logs processed yet...

+ ) : ( + logs.map((log) => ( +
+ {log.timestamp.toLocaleTimeString()}:{' '} + {log.message} +
+ )) + )} +
+
+ +

+ Logs are batched - max 3 items or 2 second wait time +

+
+ ) +} + +interface AnalyticsEvent { + type: string + target: string + timestamp: Date +} + +function App2() { + const [events, setEvents] = useState([]) + const [totalEvents, setTotalEvents] = useState(0) + const [batchesProcessed, setBatchesProcessed] = useState(0) + + // Create batched analytics tracker - Stable reference provided by useBatchedCallback + const trackEvents = useBatchedCallback( + (events: AnalyticsEvent[]) => { + console.log('Sending analytics batch:', events) + setEvents((current) => [...current, ...events]) + setBatchesProcessed((count) => count + 1) + }, + { + maxSize: 5, // Send when 5 events collected + wait: 3000, // Or after 3 seconds + }, + ) + + function trackEvent(type: string, target: string) { + const event: AnalyticsEvent = { + type, + target, + timestamp: new Date(), + } + setTotalEvents((count) => count + 1) + trackEvents(event) + } + + return ( +
+

TanStack Pacer useBatchedCallback Example 2

+
+ + + + +
+ + + + + + + + + + + + + + + + +
Total Events Created:{totalEvents}
Events Sent:{events.length}
Batches Processed:{batchesProcessed}
+ +
+

Sent Analytics Events:

+
+ {events.length === 0 ? ( +

No events sent yet...

+ ) : ( + events.map((event, index) => ( +
+ {event.timestamp.toLocaleTimeString()}:{' '} + {event.type} - {event.target} +
+ )) + )} +
+
+ +

+ Analytics events are batched - max 5 events or 3 second wait time +

+
+ ) +} + +interface ApiRequest { + id: string + data: any +} + +function App3() { + const [requests, setRequests] = useState([]) + const [totalRequests, setTotalRequests] = useState(0) + const [processedRequests, setProcessedRequests] = useState([]) + + // Create batched API request handler - Stable reference provided by useBatchedCallback + const batchApiRequests = useBatchedCallback( + (requests: ApiRequest[]) => { + console.log('Processing batch of API requests:', requests) + // Simulate API processing + setProcessedRequests((current) => [...current, ...requests]) + }, + { + maxSize: 4, // Process when 4 requests collected + wait: 1500, // Or after 1.5 seconds + }, + ) + + function makeApiRequest(data: any) { + const request: ApiRequest = { + id: `req-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, + data, + } + setTotalRequests((count) => count + 1) + setRequests((current) => [...current, request]) + batchApiRequests(request) + } + + return ( +
+

TanStack Pacer useBatchedCallback Example 3

+
+ + + + +
+ + + + + + + + + + + + + + + + +
Total Requests Made:{totalRequests}
Requests Queued:{requests.length - processedRequests.length}
Requests Processed:{processedRequests.length}
+ +
+
+

Queued Requests:

+
+ {requests.filter( + (req) => !processedRequests.some((p) => p.id === req.id), + ).length === 0 ? ( +

No requests queued...

+ ) : ( + requests + .filter( + (req) => !processedRequests.some((p) => p.id === req.id), + ) + .map((request) => ( +
+ {request.id}: {JSON.stringify(request.data)} +
+ )) + )} +
+
+ +
+

Processed Requests:

+
+ {processedRequests.length === 0 ? ( +

No requests processed yet...

+ ) : ( + processedRequests.map((request) => ( +
+ {request.id}: {JSON.stringify(request.data)} +
+ )) + )} +
+
+
+ +

+ API requests are batched - max 4 requests or 1.5 second wait time +

+
+ ) +} + +const root = document.getElementById('root')! +render( +
+ +
+ +
+ +
, + root, +) diff --git a/examples/preact/useBatchedCallback/tsconfig.json b/examples/preact/useBatchedCallback/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useBatchedCallback/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useBatchedCallback/vite.config.ts b/examples/preact/useBatchedCallback/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useBatchedCallback/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useBatcher/README.md b/examples/preact/useBatcher/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useBatcher/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useBatcher/index.html b/examples/preact/useBatcher/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useBatcher/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useBatcher/package.json b/examples/preact/useBatcher/package.json new file mode 100644 index 00000000..f3a1401f --- /dev/null +++ b/examples/preact/useBatcher/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-LBatcher", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useBatcher/public/emblem-light.svg b/examples/preact/useBatcher/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useBatcher/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useBatcher/src/index.tsx b/examples/preact/useBatcher/src/index.tsx new file mode 100644 index 00000000..1e7c3098 --- /dev/null +++ b/examples/preact/useBatcher/src/index.tsx @@ -0,0 +1,101 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import { useBatcher } from '@tanstack/preact-pacer/batcher' +import { PacerProvider } from '@tanstack/preact-pacer/provider' + +function App1() { + // Use your state management library of choice + const [processedBatches, setProcessedBatches] = useState< + Array> + >([]) + + // The function that will process a batch of items + function processBatch(items: Array) { + setProcessedBatches((prev) => [...prev, items]) + console.log('processing batch', items) + } + + const batcher = useBatcher( + processBatch, + { + // started: false, // true by default + maxSize: 5, // Process in batches of 5 (if comes before wait time) + wait: 3000, // wait up to 3 seconds before processing a batch (if time elapses before maxSize is reached) + getShouldExecute: (items, _batcher) => items.includes(42), // or pass in a custom function to determine if the batch should be processed + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + size: state.size, + executionCount: state.executionCount, + totalItemsProcessed: state.totalItemsProcessed, + }), + ) + + return ( +
+

TanStack Pacer useBatcher Example 1

+
Batch Size: {batcher.state.size}
+
Batch Max Size: {3}
+
Batch Items: {batcher.peekAllItems().join(', ')}
+
Batches Processed: {batcher.state.executionCount}
+
Items Processed: {batcher.state.totalItemsProcessed}
+
+ Processed Batches:{' '} + {processedBatches.map((b, i) => ( + <> + [{b.join(', ')}],{' '} + + ))} +
+
+ + +
+
+        {JSON.stringify(batcher.store.state, null, 2)}
+      
+
+ ) +} + +const root = document.getElementById('root')! +render( + // optionally, provide default options to an optional PacerProvider + +
+ +
+
+
, + root, +) diff --git a/examples/preact/useBatcher/tsconfig.json b/examples/preact/useBatcher/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useBatcher/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useBatcher/vite.config.ts b/examples/preact/useBatcher/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useBatcher/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useDebouncedCallback/README.md b/examples/preact/useDebouncedCallback/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useDebouncedCallback/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useDebouncedCallback/index.html b/examples/preact/useDebouncedCallback/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useDebouncedCallback/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useDebouncedCallback/package.json b/examples/preact/useDebouncedCallback/package.json new file mode 100644 index 00000000..509c8c84 --- /dev/null +++ b/examples/preact/useDebouncedCallback/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-use-debounced-callback", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useDebouncedCallback/public/emblem-light.svg b/examples/preact/useDebouncedCallback/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useDebouncedCallback/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useDebouncedCallback/src/index.tsx b/examples/preact/useDebouncedCallback/src/index.tsx new file mode 100644 index 00000000..8fdf11a6 --- /dev/null +++ b/examples/preact/useDebouncedCallback/src/index.tsx @@ -0,0 +1,157 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { useDebouncedCallback } from '@tanstack/preact-pacer/debouncer' + +function App1() { + // Use your state management library of choice + const [instantCount, setInstantCount] = useState(0) + const [debouncedCount, setDebouncedCount] = useState(0) + + // Create debounced setter function - Stable reference provided by useDebouncedCallback + const debouncedSetCount = useDebouncedCallback(setDebouncedCount, { + wait: 500, + // enabled: () => instantCount > 2, // optional, defaults to true + // leading: true, // optional, defaults to false + }) + + function increment() { + // this pattern helps avoid common bugs with stale closures and state + setInstantCount((c) => { + const newInstantCount = c + 1 // common new value for both + debouncedSetCount(newInstantCount) // debounced state update + return newInstantCount // instant state update + }) + } + + return ( +
+

TanStack Pacer useDebouncedCallback Example 1

+ + + + + + + + + + + +
Instant Count:{instantCount}
Debounced Count:{debouncedCount}
+
+ +
+
+ ) +} + +function App2() { + const [searchText, setSearchText] = useState('') + const [debouncedSearchText, setDebouncedSearchText] = useState('') + + // Create debounced setter function - Stable reference provided by useDebouncedCallback + const debouncedSetSearch = useDebouncedCallback(setDebouncedSearchText, { + wait: 500, + enabled: () => searchText.length > 2, + }) + + function handleSearchChange(e: JSX.TargetedEvent) { + const newValue = e.currentTarget.value + setSearchText(newValue) + debouncedSetSearch(newValue) + } + + return ( +
+

TanStack Pacer useDebouncedCallback Example 2

+
+ +
+ + + + + + + + + + + +
Instant Search:{searchText}
Debounced Search:{debouncedSearchText}
+
+ ) +} + +function App3() { + const [currentValue, setCurrentValue] = useState(50) + const [debouncedValue, setDebouncedValue] = useState(50) + + // Create debounced setter function - Stable reference provided by useDebouncedCallback + const debouncedSetValue = useDebouncedCallback(setDebouncedValue, { + wait: 250, + }) + + function handleRangeChange(e: JSX.TargetedEvent) { + const newValue = parseInt(e.currentTarget.value, 10) + setCurrentValue(newValue) + debouncedSetValue(newValue) + } + + return ( +
+

TanStack Pacer useDebouncedCallback Example 3

+
+ +
+
+ +
+
+

Debounced to 250ms wait time

+
+
+ ) +} + +const root = document.getElementById('root')! +render( +
+ +
+ +
+ +
, + root, +) diff --git a/examples/preact/useDebouncedCallback/tsconfig.json b/examples/preact/useDebouncedCallback/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useDebouncedCallback/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useDebouncedCallback/vite.config.ts b/examples/preact/useDebouncedCallback/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useDebouncedCallback/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useDebouncedState/README.md b/examples/preact/useDebouncedState/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useDebouncedState/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useDebouncedState/index.html b/examples/preact/useDebouncedState/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useDebouncedState/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useDebouncedState/package.json b/examples/preact/useDebouncedState/package.json new file mode 100644 index 00000000..4462e4da --- /dev/null +++ b/examples/preact/useDebouncedState/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-use-debounced-state", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useDebouncedState/public/emblem-light.svg b/examples/preact/useDebouncedState/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useDebouncedState/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useDebouncedState/src/index.tsx b/examples/preact/useDebouncedState/src/index.tsx new file mode 100644 index 00000000..083cf825 --- /dev/null +++ b/examples/preact/useDebouncedState/src/index.tsx @@ -0,0 +1,248 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { useDebouncedState } from '@tanstack/preact-pacer/debouncer' + +function App1() { + const [instantCount, setInstantCount] = useState(0) + + // higher-level hook that uses Preact.useState with the state setter automatically debounced + // optionally, grab the debouncer from the last index of the returned array + const [debouncedCount, setDebouncedCount, debouncer] = useDebouncedState( + instantCount, + { + wait: 500, + // enabled: () => instantCount > 2, // optional, defaults to true + // leading: true, // optional, defaults to false + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + isPending: state.isPending, + executionCount: state.executionCount, + }), + ) + + function increment() { + // this pattern helps avoid common bugs with stale closures and state + setInstantCount((c) => { + const newInstantCount = c + 1 // common new value for both + setDebouncedCount(newInstantCount) // debounced state update + return newInstantCount // instant state update + }) + } + + return ( +
+

TanStack Pacer useDebouncedState Example 1

+ + + + + + + + + + + + + + + + + + + + + + +
Is Pending:{debouncer.state.isPending.toString()}
Execution Count:{debouncer.state.executionCount}
+
+
Instant Count:{instantCount}
Debounced Count:{debouncedCount}
+
+ +
+
+        {JSON.stringify(debouncer.store.state, null, 2)}
+      
+
+ ) +} + +function App2() { + const [instantSearch, setInstantSearch] = useState('') + + // higher-level hook that uses Preact.useState with the state setter automatically debounced + const [debouncedSearch, setDebouncedSearch, debouncer] = useDebouncedState( + instantSearch, + { + wait: 500, + enabled: instantSearch.length > 2, // optional, defaults to true + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + isPending: state.isPending, + executionCount: state.executionCount, + }), + ) + + function handleSearchChange(e: JSX.TargetedEvent) { + const newValue = e.currentTarget.value + setInstantSearch(newValue) + setDebouncedSearch(newValue) + } + + return ( +
+

TanStack Pacer useDebouncedState Example 2

+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +
Is Pending:{debouncer.state.isPending.toString()}
Execution Count:{debouncer.state.executionCount}
+
+
Instant Search:{instantSearch}
Debounced Search:{debouncedSearch}
+
+        {JSON.stringify(debouncer.store.state, null, 2)}
+      
+
+ ) +} + +function App3() { + const [currentValue, setCurrentValue] = useState(50) + const [instantExecutionCount, setInstantExecutionCount] = useState(0) + + // higher-level hook that uses Preact.useState with the state setter automatically debounced + const [debouncedValue, setDebouncedValue, debouncer] = useDebouncedState( + currentValue, + { + wait: 250, + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + isPending: state.isPending, + executionCount: state.executionCount, + }), + ) + + function handleRangeChange(e: JSX.TargetedEvent) { + const newValue = parseInt(e.currentTarget.value, 10) + setCurrentValue(newValue) + setInstantExecutionCount((c) => c + 1) + setDebouncedValue(newValue) + } + + return ( +
+

TanStack Pacer useDebouncedState Example 3

+
+ +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Is Pending:{debouncer.state.isPending.toString()}
Instant Executions:{instantExecutionCount}
Debounced Executions:{debouncer.state.executionCount}
Saved Executions:{instantExecutionCount - debouncer.state.executionCount}
% Reduction: + {instantExecutionCount === 0 + ? '0' + : Math.round( + ((instantExecutionCount - debouncer.state.executionCount) / + instantExecutionCount) * + 100, + )} + % +
+
+

Debounced to 250ms wait time

+
+
+        {JSON.stringify(debouncer.store.state, null, 2)}
+      
+
+ ) +} + +const root = document.getElementById('root')! +render( +
+ +
+ +
+ +
, + root, +) diff --git a/examples/preact/useDebouncedState/tsconfig.json b/examples/preact/useDebouncedState/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useDebouncedState/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useDebouncedState/vite.config.ts b/examples/preact/useDebouncedState/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useDebouncedState/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useDebouncedValue/README.md b/examples/preact/useDebouncedValue/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useDebouncedValue/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useDebouncedValue/index.html b/examples/preact/useDebouncedValue/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useDebouncedValue/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useDebouncedValue/package.json b/examples/preact/useDebouncedValue/package.json new file mode 100644 index 00000000..afc8dd63 --- /dev/null +++ b/examples/preact/useDebouncedValue/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-use-debounced-value", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useDebouncedValue/public/emblem-light.svg b/examples/preact/useDebouncedValue/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useDebouncedValue/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useDebouncedValue/src/index.tsx b/examples/preact/useDebouncedValue/src/index.tsx new file mode 100644 index 00000000..048a2e08 --- /dev/null +++ b/examples/preact/useDebouncedValue/src/index.tsx @@ -0,0 +1,202 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { useDebouncedValue } from '@tanstack/preact-pacer/debouncer' + +function App1() { + const [instantCount, setInstantCount] = useState(0) + + function increment() { + setInstantCount((c) => c + 1) + } + + // highest-level hook that watches an instant local state value and returns a debounced value + const [debouncedCount] = useDebouncedValue( + instantCount, + { + wait: 500, + // enabled: () => instantCount > 2, // optional, defaults to true + // leading: true, // optional, defaults to false + }, + // Optional Selector function to pick the state you want to track and use + (_state) => ({}), // No specific state access needed for this example + ) + + return ( +
+

TanStack Pacer useDebouncedValue Example 1

+ + + + + + + + + + + +
Instant Count:{instantCount}
Debounced Count:{debouncedCount}
+
+ +
+
+ ) +} + +function App2() { + const [instantSearch, setInstantSearch] = useState('') + + // highest-level hook that watches an instant local state value and returns a debounced value + // optionally, grab the debouncer from the last index of the returned array + const [debouncedSearch] = useDebouncedValue( + instantSearch, + { + wait: 500, + enabled: instantSearch.length > 2, // optional, defaults to true + }, + // Optional Selector function to pick the state you want to track and use + (_state) => ({}), // No specific state access needed for this example + ) + + function handleSearchChange(e: JSX.TargetedEvent) { + setInstantSearch(e.currentTarget.value) + } + + return ( +
+

TanStack Pacer useDebouncedValue Example 2

+
+ +
+ + + + + + + + + + + +
Instant Search:{instantSearch}
Debounced Search:{debouncedSearch}
+
+ ) +} + +function App3() { + const [currentValue, setCurrentValue] = useState(50) + const [instantExecutionCount, setInstantExecutionCount] = useState(0) + + // highest-level hook that watches an instant local state value and returns a debounced value + const [debouncedValue, debouncer] = useDebouncedValue( + currentValue, + { + wait: 250, + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + isPending: state.isPending, + executionCount: state.executionCount, + }), + ) + + function handleRangeChange(e: JSX.TargetedEvent) { + const newValue = parseInt(e.currentTarget.value, 10) + setCurrentValue(newValue) + setInstantExecutionCount((c) => c + 1) + } + + return ( +
+

TanStack Pacer useDebouncedValue Example 3

+
+ +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Is Pending:{debouncer.state.isPending.toString()}
Instant Executions:{instantExecutionCount}
Debounced Executions:{debouncer.state.executionCount}
Saved Executions:{instantExecutionCount - debouncer.state.executionCount}
% Reduction: + {instantExecutionCount === 0 + ? '0' + : Math.round( + ((instantExecutionCount - debouncer.state.executionCount) / + instantExecutionCount) * + 100, + )} + % +
+
+

Debounced to 250ms wait time

+
+
+        {JSON.stringify(debouncer.store.state, null, 2)}
+      
+
+ ) +} + +const root = document.getElementById('root')! +render( +
+ +
+ +
+ +
, + root, +) diff --git a/examples/preact/useDebouncedValue/tsconfig.json b/examples/preact/useDebouncedValue/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useDebouncedValue/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useDebouncedValue/vite.config.ts b/examples/preact/useDebouncedValue/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useDebouncedValue/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useDebouncer/README.md b/examples/preact/useDebouncer/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useDebouncer/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useDebouncer/index.html b/examples/preact/useDebouncer/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useDebouncer/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useDebouncer/package.json b/examples/preact/useDebouncer/package.json new file mode 100644 index 00000000..77b8bd00 --- /dev/null +++ b/examples/preact/useDebouncer/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-use-debouncer", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useDebouncer/public/emblem-light.svg b/examples/preact/useDebouncer/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useDebouncer/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useDebouncer/src/index.tsx b/examples/preact/useDebouncer/src/index.tsx new file mode 100644 index 00000000..0a9d9b99 --- /dev/null +++ b/examples/preact/useDebouncer/src/index.tsx @@ -0,0 +1,276 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { useDebouncer } from '@tanstack/preact-pacer/debouncer' +import { PacerProvider } from '@tanstack/preact-pacer/provider' + +function App1() { + // Use your state management library of choice + const [instantCount, setInstantCount] = useState(0) + const [debouncedCount, setDebouncedCount] = useState(0) + + // Lower-level useDebouncer hook - requires you to manage your own state + const debouncer = useDebouncer( + setDebouncedCount, + { + wait: 800, + enabled: () => instantCount > 2, // optional, defaults to true + // leading: true, // optional, defaults to false + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + status: state.status, + executionCount: state.executionCount, + }), + ) + + function increment() { + // this pattern helps avoid common bugs with stale closures and state + setInstantCount((c) => { + const newInstantCount = c + 1 // common new value for both + debouncer.maybeExecute(newInstantCount) // debounced state update + return newInstantCount // instant state update + }) + } + + return ( +
+

TanStack Pacer useDebouncer Example 1

+ + + + + + + + + + + + + + + + + + + + + + +
Status:{debouncer.state.status}
Execution Count:{debouncer.state.executionCount}
+
+
Instant Count:{instantCount}
Debounced Count:{debouncedCount}
+
+ + +
+
+        {JSON.stringify(debouncer.store.state, null, 2)}
+      
+
+ ) +} + +function App2() { + const [searchText, setSearchText] = useState('') + const [debouncedSearchText, setDebouncedSearchText] = useState('') + + // Lower-level useDebouncer hook - requires you to manage your own state + const setSearchDebouncer = useDebouncer( + setDebouncedSearchText, + { + wait: 500, + enabled: () => searchText.length > 2, // optional, defaults to true + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + isPending: state.isPending, + executionCount: state.executionCount, + }), + ) + + function handleSearchChange(e: JSX.TargetedEvent) { + const newValue = e.currentTarget.value + setSearchText(newValue) + setSearchDebouncer.maybeExecute(newValue) + } + + return ( +
+

TanStack Pacer useDebouncer Example 2

+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +
Is Pending:{setSearchDebouncer.state.isPending.toString()}
Execution Count:{setSearchDebouncer.state.executionCount}
+
+
Instant Search:{searchText}
Debounced Search:{debouncedSearchText}
+
+ +
+
+        {JSON.stringify(setSearchDebouncer.store.state, null, 2)}
+      
+
+ ) +} + +function App3() { + const [currentValue, setCurrentValue] = useState(50) + const [debouncedValue, setDebouncedValue] = useState(50) + const [instantExecutionCount, setInstantExecutionCount] = useState(0) + + // Lower-level useDebouncer hook - requires you to manage your own state + const setValueDebouncer = useDebouncer( + setDebouncedValue, + { + wait: 250, + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + isPending: state.isPending, + executionCount: state.executionCount, + }), + ) + + function handleRangeChange(e: JSX.TargetedEvent) { + const newValue = parseInt(e.currentTarget.value, 10) + setCurrentValue(newValue) + setInstantExecutionCount((c) => c + 1) + setValueDebouncer.maybeExecute(newValue) + } + + return ( +
+

TanStack Pacer useDebouncer Example 3

+
+ +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
Is Pending:{setValueDebouncer.state.isPending.toString()}
Instant Executions:{instantExecutionCount}
Debounced Executions:{setValueDebouncer.state.executionCount}
Saved Executions: + {instantExecutionCount - setValueDebouncer.state.executionCount} +
% Reduction: + {instantExecutionCount === 0 + ? '0' + : Math.round( + ((instantExecutionCount - + setValueDebouncer.state.executionCount) / + instantExecutionCount) * + 100, + )} + % +
+
+

Debounced to 250ms wait time

+
+
+ +
+
+        {JSON.stringify(setValueDebouncer.store.state, null, 2)}
+      
+
+ ) +} + +const root = document.getElementById('root')! +render( + // optionally, provide default options to an optional PacerProvider + +
+ +
+ +
+ +
+
, + root, +) diff --git a/examples/preact/useDebouncer/tsconfig.json b/examples/preact/useDebouncer/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useDebouncer/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useDebouncer/vite.config.ts b/examples/preact/useDebouncer/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useDebouncer/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useQueuedState/README.md b/examples/preact/useQueuedState/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useQueuedState/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useQueuedState/index.html b/examples/preact/useQueuedState/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useQueuedState/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useQueuedState/package.json b/examples/preact/useQueuedState/package.json new file mode 100644 index 00000000..7e02ae94 --- /dev/null +++ b/examples/preact/useQueuedState/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-queued-state", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useQueuedState/public/emblem-light.svg b/examples/preact/useQueuedState/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useQueuedState/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useQueuedState/src/index.tsx b/examples/preact/useQueuedState/src/index.tsx new file mode 100644 index 00000000..b06cb4f7 --- /dev/null +++ b/examples/preact/useQueuedState/src/index.tsx @@ -0,0 +1,231 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { useQueuedState } from '@tanstack/preact-pacer/queuer' + +function App1() { + // Queuer that uses Preact.useState under the hood + function processItem(item: number) { + console.log('processing item', item) + } + + const [queueItems, addItem, queuer] = useQueuedState( + processItem, + { + maxSize: 25, + initialItems: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], + started: false, + wait: 1000, // wait 1 second between processing items - wait is optional! + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + items: state.items, // required for useQueuedState + size: state.size, + isFull: state.isFull, + isEmpty: state.isEmpty, + isIdle: state.isIdle, + status: state.status, + executionCount: state.executionCount, + isRunning: state.isRunning, + }), + ) + + return ( +
+

TanStack Pacer useQueuedState Example 1

+
Queue Size: {queuer.state.size}
+
Queue Max Size: {25}
+
Queue Full: {queuer.state.isFull ? 'Yes' : 'No'}
+
Queue Peek: {queuer.peekNextItem()}
+
Queue Empty: {queuer.state.isEmpty ? 'Yes' : 'No'}
+
Queue Idle: {queuer.state.isIdle ? 'Yes' : 'No'}
+
Queuer Status: {queuer.state.status}
+
Items Processed: {queuer.state.executionCount}
+
Queue Items: {queueItems.join(', ')}
+
+ + + + + + +
+
+        {JSON.stringify(queuer.store.state, null, 2)}
+      
+
+ ) +} + +function App2() { + const [currentValue, setCurrentValue] = useState(50) + const [queuedValue, setQueuedValue] = useState(50) + const [instantExecutionCount, setInstantExecutionCount] = useState(0) + + // Queuer that processes a single value with delays + const [, addItem, queuer] = useQueuedState( + (item: number) => { + setQueuedValue(item) + }, + { + maxSize: 100, + started: true, + wait: 100, + }, + (state) => ({ + items: state.items, // required for useQueuedState + size: state.size, + isFull: state.isFull, + isEmpty: state.isEmpty, + isIdle: state.isIdle, + status: state.status, + executionCount: state.executionCount, + isRunning: state.isRunning, + }), + ) + + function handleRangeChange(e: JSX.TargetedEvent) { + const newValue = parseInt(e.currentTarget.value, 10) + setCurrentValue(newValue) + setInstantExecutionCount((c) => c + 1) + addItem(newValue) + } + + return ( +
+

TanStack Pacer useQueuedState Example 2

+
+ +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Queue Size:{queuer.state.size}
Queue Full:{queuer.state.isFull ? 'Yes' : 'No'}
Queue Empty:{queuer.state.isEmpty ? 'Yes' : 'No'}
Queue Idle:{queuer.state.isIdle ? 'Yes' : 'No'}
Queuer Status:{queuer.state.status}
Instant Executions:{instantExecutionCount}
Items Processed:{queuer.state.executionCount}
Saved Executions:{instantExecutionCount - queuer.state.executionCount}
% Reduction: + {instantExecutionCount === 0 + ? '0' + : Math.round( + ((instantExecutionCount - queuer.state.executionCount) / + instantExecutionCount) * + 100, + )} + % +
+
+

Queued with 100ms wait time

+
+
+        {JSON.stringify(queuer.store.state, null, 2)}
+      
+
+ ) +} + +const root = document.getElementById('root')! +render( +
+ +
+ +
, + root, +) diff --git a/examples/preact/useQueuedState/tsconfig.json b/examples/preact/useQueuedState/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useQueuedState/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useQueuedState/vite.config.ts b/examples/preact/useQueuedState/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useQueuedState/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useQueuedValue/README.md b/examples/preact/useQueuedValue/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useQueuedValue/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useQueuedValue/index.html b/examples/preact/useQueuedValue/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useQueuedValue/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useQueuedValue/package.json b/examples/preact/useQueuedValue/package.json new file mode 100644 index 00000000..31560abc --- /dev/null +++ b/examples/preact/useQueuedValue/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-queued-value", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useQueuedValue/public/emblem-light.svg b/examples/preact/useQueuedValue/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useQueuedValue/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useQueuedValue/src/index.tsx b/examples/preact/useQueuedValue/src/index.tsx new file mode 100644 index 00000000..1647f4a0 --- /dev/null +++ b/examples/preact/useQueuedValue/src/index.tsx @@ -0,0 +1,222 @@ +import { render } from 'preact' +import type { JSX } from 'preact' +import { useQueuedValue } from '@tanstack/preact-pacer/queuer' +import { useState } from 'preact/hooks' + +function App1() { + const [instantSearchValue, setInstantSearchValue] = useState('') + + // Queuer that processes a single value with delays + const [value, queuer] = useQueuedValue( + instantSearchValue, + { + maxSize: 25, + wait: 500, // wait 500ms between processing value changes + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + executionCount: state.executionCount, + isEmpty: state.isEmpty, + isFull: state.isFull, + isIdle: state.isIdle, + isRunning: state.isRunning, + items: state.items, // required for useQueuedValue hook + size: state.size, + status: state.status, + }), + ) + + return ( +
+

TanStack Pacer useQueuedValue Example 1

+
Current Value: {value}
+
+
Queue Size: {queuer.state.size}
+
Queue Full: {queuer.state.isFull ? 'Yes' : 'No'}
+
Queue Peek: {queuer.peekNextItem()}
+
Queue Empty: {queuer.state.isEmpty ? 'Yes' : 'No'}
+
Queue Idle: {queuer.state.isIdle ? 'Yes' : 'No'}
+
Queuer Status: {queuer.state.status}
+
Items Processed: {queuer.state.executionCount}
+
Queue Items: {queuer.peekAllItems().join(', ')}
+
+ { + setInstantSearchValue(e.currentTarget.value) // instantly update the local search value + }} + placeholder="Enter search term..." + disabled={queuer.state.isFull} + /> + + + + + +
+
+        {JSON.stringify(queuer.store.state, null, 2)}
+      
+
+ ) +} + +function App2() { + const [currentValue, setCurrentValue] = useState(50) + const [instantExecutionCount, setInstantExecutionCount] = useState(0) + + // Queuer that processes a single value with delays + const [queuedValue, queuer] = useQueuedValue( + currentValue, + { + maxSize: 100, + wait: 100, + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + executionCount: state.executionCount, + isEmpty: state.isEmpty, + isFull: state.isFull, + isIdle: state.isIdle, + items: state.items, // required for useQueuedValue hook + size: state.size, + status: state.status, + }), + ) + + function handleRangeChange(e: JSX.TargetedEvent) { + const newValue = parseInt(e.currentTarget.value, 10) + setCurrentValue(newValue) + setInstantExecutionCount((c) => c + 1) + } + + return ( +
+

TanStack Pacer useQueuedValue Example 2

+
+ +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Queue Size:{queuer.state.size}
Queue Full:{queuer.state.isFull ? 'Yes' : 'No'}
Queue Empty:{queuer.state.isEmpty ? 'Yes' : 'No'}
Queue Idle:{queuer.state.isIdle ? 'Yes' : 'No'}
Queuer Status:{queuer.state.status}
Instant Executions:{instantExecutionCount}
Items Processed:{queuer.state.executionCount}
Saved Executions:{instantExecutionCount - queuer.state.executionCount}
% Reduction: + {instantExecutionCount === 0 + ? '0' + : Math.round( + ((instantExecutionCount - queuer.state.executionCount) / + instantExecutionCount) * + 100, + )} + % +
+
+

Queued with 100ms wait time

+
+
+        {JSON.stringify(queuer.store.state, null, 2)}
+      
+
+ ) +} + +const root = document.getElementById('root')! +render( +
+ +
+ +
, + root, +) diff --git a/examples/preact/useQueuedValue/tsconfig.json b/examples/preact/useQueuedValue/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useQueuedValue/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useQueuedValue/vite.config.ts b/examples/preact/useQueuedValue/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useQueuedValue/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useQueuer/README.md b/examples/preact/useQueuer/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useQueuer/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useQueuer/index.html b/examples/preact/useQueuer/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useQueuer/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useQueuer/package.json b/examples/preact/useQueuer/package.json new file mode 100644 index 00000000..ceb07404 --- /dev/null +++ b/examples/preact/useQueuer/package.json @@ -0,0 +1,33 @@ +{ + "name": "@tanstack/pacer-example-preact-queuer", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-devtools": "^0.9.2", + "@tanstack/preact-pacer": "^0.17.3", + "@tanstack/preact-pacer-devtools": "workspace:*", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useQueuer/public/emblem-light.svg b/examples/preact/useQueuer/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useQueuer/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useQueuer/src/index.tsx b/examples/preact/useQueuer/src/index.tsx new file mode 100644 index 00000000..dc4340a6 --- /dev/null +++ b/examples/preact/useQueuer/src/index.tsx @@ -0,0 +1,258 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { useQueuer } from '@tanstack/preact-pacer/queuer' +import { PacerProvider } from '@tanstack/preact-pacer/provider' +import { PacerDevtoolsPanel } from '@tanstack/preact-pacer-devtools' +import { TanStackDevtools } from '@tanstack/preact-devtools' + +function App1() { + // The function that we will be queuing + function processItem(item: number) { + console.log('processing item', item) + } + + const queuer = useQueuer( + processItem, + { + key: 'Add Number Queue', + initialItems: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], + maxSize: 25, // optional, defaults to Infinity + started: false, // optional, defaults to true + wait: 1000, // wait 1 second between processing items - wait is optional! + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + size: state.size, + isFull: state.isFull, + isEmpty: state.isEmpty, + isIdle: state.isIdle, + isRunning: state.isRunning, + status: state.status, + executionCount: state.executionCount, + items: state.items, + }), + ) + + return ( +
+

TanStack Pacer useQueuer Example 1

+
Queue Size: {queuer.state.size}
+
Queue Max Size: {25}
+
Queue Full: {queuer.state.isFull ? 'Yes' : 'No'}
+
Queue Peek: {queuer.peekNextItem()}
+
Queue Empty: {queuer.state.isEmpty ? 'Yes' : 'No'}
+
Queue Idle: {queuer.state.isIdle ? 'Yes' : 'No'}
+
Queuer Status: {queuer.state.status}
+
Items Processed: {queuer.state.executionCount}
+
Queue Items: {queuer.state.items.join(', ')}
+
+ + + + + + + +
+
+        {JSON.stringify(queuer.store.state, null, 2)}
+      
+
+ ) +} + +function App2() { + const [currentValue, setCurrentValue] = useState(50) + const [queuedValue, setQueuedValue] = useState(50) + const [instantExecutionCount, setInstantExecutionCount] = useState(0) + + function processItem(item: number) { + setQueuedValue(item) + } + + const queuer = useQueuer( + processItem, + { + key: 'Range Queue', + maxSize: 100, + initialItems: [currentValue], + wait: 100, + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + size: state.size, + isFull: state.isFull, + isEmpty: state.isEmpty, + isIdle: state.isIdle, + isRunning: state.isRunning, + executionCount: state.executionCount, + }), + ) + + function handleRangeChange(e: JSX.TargetedEvent) { + const newValue = parseInt(e.currentTarget.value, 10) + setCurrentValue(newValue) + setInstantExecutionCount((c) => c + 1) + queuer.addItem(newValue) + } + + return ( +
+

TanStack Pacer useQueuer Example 2

+
+ +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Queue Size:{queuer.state.size}
Queue Full:{queuer.state.isFull ? 'Yes' : 'No'}
Queue Empty:{queuer.state.isEmpty ? 'Yes' : 'No'}
Queue Idle:{queuer.state.isIdle ? 'Yes' : 'No'}
Queuer Status:{queuer.state.isRunning ? 'Running' : 'Stopped'}
Instant Executions:{instantExecutionCount}
Items Processed:{queuer.state.executionCount}
Saved Executions:{instantExecutionCount - queuer.state.executionCount}
% Reduction: + {instantExecutionCount === 0 + ? '0' + : Math.round( + ((instantExecutionCount - queuer.state.executionCount) / + instantExecutionCount) * + 100, + )} + % +
+
+

Queued with 100ms wait time

+
+
+ +
+
+        {JSON.stringify(queuer.store.state, null, 2)}
+      
+
+ ) +} + +const root = document.getElementById('root')! +render( + // optionally, provide default options to an optional PacerProvider + +
+ +
+ +
+ }]} + /> +
, + root, +) diff --git a/examples/preact/useQueuer/tsconfig.json b/examples/preact/useQueuer/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useQueuer/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useQueuer/vite.config.ts b/examples/preact/useQueuer/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useQueuer/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useQueuerWithPersister/README.md b/examples/preact/useQueuerWithPersister/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useQueuerWithPersister/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useQueuerWithPersister/index.html b/examples/preact/useQueuerWithPersister/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useQueuerWithPersister/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useQueuerWithPersister/package.json b/examples/preact/useQueuerWithPersister/package.json new file mode 100644 index 00000000..c24d9b8e --- /dev/null +++ b/examples/preact/useQueuerWithPersister/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-queuer-with-persister", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useQueuerWithPersister/public/emblem-light.svg b/examples/preact/useQueuerWithPersister/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useQueuerWithPersister/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useQueuerWithPersister/src/index.tsx b/examples/preact/useQueuerWithPersister/src/index.tsx new file mode 100644 index 00000000..fb05255a --- /dev/null +++ b/examples/preact/useQueuerWithPersister/src/index.tsx @@ -0,0 +1,245 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { useQueuer } from '@tanstack/preact-pacer/queuer' +// import { useStoragePersister } from '@tanstack/preact-persister' +// import type { QueuerState } from '@tanstack/preact-pacer/queuer' + +function App1() { + // optional session storage persister to retain state on page refresh + // const queuerPersister = useStoragePersister>({ + // key: 'my-queuer', + // storage: sessionStorage, + // maxAge: 1000 * 60, // 1 minute + // buster: 'v1', + // }) + // const queuerPersister = undefined as any + + // The function that we will be queuing + function processItem(item: number) { + console.log('processing item', item) + } + + const queuer = useQueuer( + processItem, + { + initialItems: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], + // initialState: queuerPersister?.loadState(), + maxSize: 25, // optional, defaults to Infinity + started: false, // optional, defaults to true + wait: 1000, // wait 1 second between processing items - wait is optional! + }, + // Optional Selector function to pick the state you want to track and use + (state) => state, // entire state subscription for persister - don't do this unless you need to + ) + + // useEffect(() => { + // queuerPersister?.saveState(queuer.state) + // }, [queuer.state]) + + return ( +
+

TanStack Pacer useQueuer Example 1 (with persister)

+
Queue Size: {queuer.state.size}
+
Queue Max Size: {25}
+
Queue Full: {queuer.state.isFull ? 'Yes' : 'No'}
+
Queue Peek: {queuer.peekNextItem()}
+
Queue Empty: {queuer.state.isEmpty ? 'Yes' : 'No'}
+
Queue Idle: {queuer.state.isIdle ? 'Yes' : 'No'}
+
Queuer Status: {queuer.state.status}
+
Items Processed: {queuer.state.executionCount}
+
Queue Items: {queuer.state.items.join(', ')}
+
+ + + + + + + +
+
+        {JSON.stringify(queuer.store.state, null, 2)}
+      
+
+ ) +} + +function App2() { + const [currentValue, setCurrentValue] = useState(50) + const [queuedValue, setQueuedValue] = useState(50) + const [instantExecutionCount, setInstantExecutionCount] = useState(0) + + function processItem(item: number) { + setQueuedValue(item) + } + + const queuer = useQueuer( + processItem, + { + maxSize: 100, + initialItems: [currentValue], + wait: 100, + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + size: state.size, + isFull: state.isFull, + isEmpty: state.isEmpty, + isIdle: state.isIdle, + isRunning: state.isRunning, + executionCount: state.executionCount, + }), + ) + + function handleRangeChange(e: JSX.TargetedEvent) { + const newValue = parseInt(e.currentTarget.value, 10) + setCurrentValue(newValue) + setInstantExecutionCount((c) => c + 1) + queuer.addItem(newValue) + } + + return ( +
+

TanStack Pacer useQueuer Example 2

+
+ +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Queue Size:{queuer.state.size}
Queue Full:{queuer.state.isFull ? 'Yes' : 'No'}
Queue Empty:{queuer.state.isEmpty ? 'Yes' : 'No'}
Queue Idle:{queuer.state.isIdle ? 'Yes' : 'No'}
Queuer Status:{queuer.state.isRunning ? 'Running' : 'Stopped'}
Instant Executions:{instantExecutionCount}
Items Processed:{queuer.state.executionCount}
Saved Executions:{instantExecutionCount - queuer.state.executionCount}
% Reduction: + {instantExecutionCount === 0 + ? '0' + : Math.round( + ((instantExecutionCount - queuer.state.executionCount) / + instantExecutionCount) * + 100, + )} + % +
+
+

Queued with 100ms wait time

+
+
+ +
+
+        {JSON.stringify(queuer.store.state, null, 2)}
+      
+
+ ) +} + +const root = document.getElementById('root')! +render( +
+ +
+ +
, + root, +) diff --git a/examples/preact/useQueuerWithPersister/tsconfig.json b/examples/preact/useQueuerWithPersister/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useQueuerWithPersister/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useQueuerWithPersister/vite.config.ts b/examples/preact/useQueuerWithPersister/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useQueuerWithPersister/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useRateLimitedCallback/README.md b/examples/preact/useRateLimitedCallback/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useRateLimitedCallback/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useRateLimitedCallback/index.html b/examples/preact/useRateLimitedCallback/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useRateLimitedCallback/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useRateLimitedCallback/package.json b/examples/preact/useRateLimitedCallback/package.json new file mode 100644 index 00000000..7d02edcc --- /dev/null +++ b/examples/preact/useRateLimitedCallback/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-rate-limited-callback", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useRateLimitedCallback/public/emblem-light.svg b/examples/preact/useRateLimitedCallback/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useRateLimitedCallback/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useRateLimitedCallback/src/index.tsx b/examples/preact/useRateLimitedCallback/src/index.tsx new file mode 100644 index 00000000..2c6c2a27 --- /dev/null +++ b/examples/preact/useRateLimitedCallback/src/index.tsx @@ -0,0 +1,249 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { useRateLimitedCallback } from '@tanstack/preact-pacer/rate-limiter' + +function App1() { + const [windowType, setWindowType] = useState<'fixed' | 'sliding'>('fixed') + // Use your state management library of choice + const [instantCount, setInstantCount] = useState(0) + const [rateLimitedCount, setRateLimitedCount] = useState(0) + + // Create rateLimited setter function - Stable reference provided by useRateLimitedCallback + const rateLimitedSetCount = useRateLimitedCallback(setRateLimitedCount, { + limit: 5, + window: 5000, + windowType: windowType, + enabled: () => instantCount > 2, + onReject: (rateLimiter) => { + console.log( + `Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`, + ) + }, + }) + + function increment() { + // this pattern helps avoid common bugs with stale closures and state + setInstantCount((c) => { + const newInstantCount = c + 1 // common new value for both + rateLimitedSetCount(newInstantCount) // rateLimited state update + return newInstantCount // instant state update + }) + } + + return ( +
+

TanStack Pacer useRateLimitedCallback Example 1

+
+ + +
+ + + + + + + + + + + +
Instant Count:{instantCount}
RateLimited Count:{rateLimitedCount}
+
+ +
+
+ ) +} + +function App2() { + const [windowType, setWindowType] = useState<'fixed' | 'sliding'>('fixed') + const [searchText, setSearchText] = useState('') + const [rateLimitedSearchText, setRateLimitedSearchText] = useState('') + + // Create rateLimited setter function - Stable reference provided by useRateLimitedCallback + const rateLimitedSetSearch = useRateLimitedCallback( + setRateLimitedSearchText, + { + limit: 5, + window: 5000, + windowType: windowType, + enabled: () => searchText.length > 2, + onReject: (rateLimiter) => { + console.log( + `Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`, + ) + }, + }, + ) + + function handleSearchChange(e: JSX.TargetedEvent) { + const newValue = e.currentTarget.value + setSearchText(newValue) + rateLimitedSetSearch(newValue) + } + + return ( +
+

TanStack Pacer useRateLimitedCallback Example 2

+
+ + +
+
+ +
+ + + + + + + + + + + +
Instant Search:{searchText}
RateLimited Search:{rateLimitedSearchText}
+
+ ) +} + +function App3() { + const [windowType, setWindowType] = useState<'fixed' | 'sliding'>('fixed') + const [currentValue, setCurrentValue] = useState(50) + const [limitedValue, setLimitedValue] = useState(50) + + // Create rateLimited setter function - Stable reference provided by useRateLimitedCallback + const rateLimitedSetValue = useRateLimitedCallback(setLimitedValue, { + limit: 20, + window: 2000, + windowType: windowType, + onReject: (rateLimiter) => { + console.log( + `Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`, + ) + }, + }) + + function handleRangeChange(e: JSX.TargetedEvent) { + const newValue = parseInt(e.currentTarget.value, 10) + setCurrentValue(newValue) + rateLimitedSetValue(newValue) + } + + return ( +
+

TanStack Pacer useRateLimitedCallback Example 3

+
+ + +
+
+ +
+
+ +
+
+

Rate limited to 20 updates per 2 seconds

+
+
+ ) +} + +const root = document.getElementById('root')! +render( +
+ +
+ +
+ +
, + root, +) diff --git a/examples/preact/useRateLimitedCallback/tsconfig.json b/examples/preact/useRateLimitedCallback/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useRateLimitedCallback/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useRateLimitedCallback/vite.config.ts b/examples/preact/useRateLimitedCallback/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useRateLimitedCallback/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useRateLimitedState/README.md b/examples/preact/useRateLimitedState/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useRateLimitedState/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useRateLimitedState/index.html b/examples/preact/useRateLimitedState/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useRateLimitedState/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useRateLimitedState/package.json b/examples/preact/useRateLimitedState/package.json new file mode 100644 index 00000000..1cb77a41 --- /dev/null +++ b/examples/preact/useRateLimitedState/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-rate-limited-state", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useRateLimitedState/public/emblem-light.svg b/examples/preact/useRateLimitedState/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useRateLimitedState/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useRateLimitedState/src/index.tsx b/examples/preact/useRateLimitedState/src/index.tsx new file mode 100644 index 00000000..ec79ad65 --- /dev/null +++ b/examples/preact/useRateLimitedState/src/index.tsx @@ -0,0 +1,345 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { useRateLimitedState } from '@tanstack/preact-pacer/rate-limiter' + +function App1() { + const [windowType, setWindowType] = useState<'fixed' | 'sliding'>('fixed') + const [instantCount, setInstantCount] = useState(0) + + // Using useRateLimiter with a rate limit of 5 executions per 5 seconds + const [limitedCount, setLimitedCount, rateLimiter] = useRateLimitedState( + instantCount, + { + // enabled: () => instantCount > 2, // optional, defaults to true + limit: 5, + window: 5000, + windowType: windowType, + onReject: (rateLimiter) => + console.log( + 'Rejected by rate limiter', + rateLimiter.getMsUntilNextWindow(), + ), + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + executionCount: state.executionCount, + rejectionCount: state.rejectionCount, + }), + ) + + function increment() { + // this pattern helps avoid common bugs with stale closures and state + setInstantCount((c) => { + const newInstantCount = c + 1 // common new value for both + setLimitedCount(newInstantCount) // rate-limited state update + return newInstantCount // instant state update + }) + } + + return ( +
+

TanStack Pacer useRateLimitedState Example 1

+
+ + +
+ + + + + + + + + + + + + + + + + + + +
Execution Count:{rateLimiter.state.executionCount}
Rejection Count:{rateLimiter.state.rejectionCount}
Instant Count:{instantCount}
Rate Limited Count:{limitedCount}
+
+ + + +
+
+        {JSON.stringify(rateLimiter.store.state, null, 2)}
+      
+
+ ) +} + +function App2() { + const [windowType, setWindowType] = useState<'fixed' | 'sliding'>('fixed') + const [instantSearch, setInstantSearch] = useState('') + + // Using useRateLimiter with a rate limit of 5 executions per 5 seconds + const [limitedSearch, setLimitedSearch, rateLimiter] = useRateLimitedState( + instantSearch, + { + // enabled: instantSearch.length > 2, // optional, defaults to true + limit: 5, + window: 5000, + windowType: windowType, + onReject: (rateLimiter) => + console.log( + 'Rejected by rate limiter', + rateLimiter.getMsUntilNextWindow(), + ), + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + executionCount: state.executionCount, + rejectionCount: state.rejectionCount, + }), + ) + + function handleSearchChange(e: JSX.TargetedEvent) { + const newValue = e.currentTarget.value + setInstantSearch(newValue) + setLimitedSearch(newValue) + } + + return ( +
+

TanStack Pacer useRateLimitedState Example 2

+
+ + +
+
+ +
+ + + + + + + + + + + + + + + + + + + +
Execution Count:{rateLimiter.state.executionCount}
Rejection Count:{rateLimiter.state.rejectionCount}
Instant Search:{instantSearch}
Rate Limited Search:{limitedSearch}
+
+ + +
+
+        {JSON.stringify(rateLimiter.store.state, null, 2)}
+      
+
+ ) +} + +function App3() { + const [windowType, setWindowType] = useState<'fixed' | 'sliding'>('fixed') + const [currentValue, setCurrentValue] = useState(50) + const [instantExecutionCount, setInstantExecutionCount] = useState(0) + + // Using useRateLimitedState with a rate limit of 5 executions per 5 seconds + const [limitedValue, setLimitedValue, rateLimiter] = useRateLimitedState( + currentValue, + { + limit: 20, + window: 2000, + windowType: windowType, + onReject: (rateLimiter) => + console.log( + 'Rejected by rate limiter', + rateLimiter.getMsUntilNextWindow(), + ), + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + executionCount: state.executionCount, + rejectionCount: state.rejectionCount, + }), + ) + + function handleRangeChange(e: JSX.TargetedEvent) { + const newValue = parseInt(e.currentTarget.value, 10) + setCurrentValue(newValue) + setInstantExecutionCount((c) => c + 1) + setLimitedValue(newValue) + } + + return ( +
+

TanStack Pacer useRateLimitedState Example 3

+
+ + +
+
+ +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Execution Count:{rateLimiter.state.executionCount}
Rejection Count:{rateLimiter.state.rejectionCount}
Remaining in Window:{rateLimiter.getRemainingInWindow()}
Ms Until Next Window:{rateLimiter.getMsUntilNextWindow()}
Instant Executions:{instantExecutionCount}
Saved Executions:{instantExecutionCount - rateLimiter.state.executionCount}
% Reduction: + {instantExecutionCount === 0 + ? '0' + : Math.round( + ((instantExecutionCount - + rateLimiter.state.executionCount) / + instantExecutionCount) * + 100, + )} + % +
+
+

Rate limited to 20 updates per 2 seconds

+
+
+        {JSON.stringify(rateLimiter.store.state, null, 2)}
+      
+
+ ) +} + +const root = document.getElementById('root')! +render( +
+ +
+ +
+ +
, + root, +) diff --git a/examples/preact/useRateLimitedState/tsconfig.json b/examples/preact/useRateLimitedState/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useRateLimitedState/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useRateLimitedState/vite.config.ts b/examples/preact/useRateLimitedState/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useRateLimitedState/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useRateLimitedValue/README.md b/examples/preact/useRateLimitedValue/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useRateLimitedValue/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useRateLimitedValue/index.html b/examples/preact/useRateLimitedValue/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useRateLimitedValue/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useRateLimitedValue/package.json b/examples/preact/useRateLimitedValue/package.json new file mode 100644 index 00000000..83d9c4a0 --- /dev/null +++ b/examples/preact/useRateLimitedValue/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-rate-limited-value", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useRateLimitedValue/public/emblem-light.svg b/examples/preact/useRateLimitedValue/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useRateLimitedValue/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useRateLimitedValue/src/index.tsx b/examples/preact/useRateLimitedValue/src/index.tsx new file mode 100644 index 00000000..0c976eec --- /dev/null +++ b/examples/preact/useRateLimitedValue/src/index.tsx @@ -0,0 +1,300 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { useRateLimitedValue } from '@tanstack/preact-pacer/rate-limiter' + +function App1() { + const [windowType, setWindowType] = useState<'fixed' | 'sliding'>('fixed') + const [instantCount, setInstantCount] = useState(0) + + // Using useRateLimitedValue with a rate limit of 5 executions per 5 seconds + // optionally, grab the rate limiter from the last index of the returned array + const [limitedCount] = useRateLimitedValue( + instantCount, + { + // enabled: () => instantCount > 2, // optional, defaults to true + limit: 5, + window: 5000, + windowType: windowType, + onReject: (rateLimiter) => + console.log( + 'Rejected by rate limiter', + rateLimiter.getMsUntilNextWindow(), + ), + }, + // Optional Selector function to pick the state you want to track and use + (_state) => ({}), // No specific state access needed for this example + ) + + function increment() { + setInstantCount((c) => c + 1) + } + + return ( +
+

TanStack Pacer useRateLimitedValue Example 1

+
+ + +
+ + + + + + + + + + + +
Instant Count:{instantCount}
Rate Limited Count:{limitedCount}
+
+ +
+
+ ) +} + +function App2() { + const [windowType, setWindowType] = useState<'fixed' | 'sliding'>('fixed') + const [instantSearch, setInstantSearch] = useState('') + + // Using useRateLimitedValue with a rate limit of 5 executions per 5 seconds + const [limitedSearch] = useRateLimitedValue( + instantSearch, + { + // enabled: instantSearch.length > 2, // optional, defaults to true + limit: 5, + window: 5000, + windowType: windowType, + onReject: (rateLimiter) => + console.log( + 'Rejected by rate limiter', + rateLimiter.getMsUntilNextWindow(), + ), + }, + // Optional Selector function to pick the state you want to track and use + (_state) => ({}), // No specific state access needed for this example + ) + + function handleSearchChange(e: JSX.TargetedEvent) { + setInstantSearch(e.currentTarget.value) + } + + return ( +
+

TanStack Pacer useRateLimitedValue Example 2

+
+ + +
+
+ +
+ + + + + + + + + + + +
Instant Search:{instantSearch}
Rate Limited Search:{limitedSearch}
+
+ ) +} + +function App3() { + const [windowType, setWindowType] = useState<'fixed' | 'sliding'>('fixed') + const [currentValue, setCurrentValue] = useState(50) + const [instantExecutionCount, setInstantExecutionCount] = useState(0) + + // Using useRateLimitedValue with a rate limit of 5 executions per 5 seconds + const [limitedValue, rateLimiter] = useRateLimitedValue( + currentValue, + { + limit: 20, + window: 2000, + windowType: windowType, + onReject: (rateLimiter) => + console.log( + 'Rejected by rate limiter', + rateLimiter.getMsUntilNextWindow(), + ), + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + executionCount: state.executionCount, + rejectionCount: state.rejectionCount, + }), + ) + + function handleRangeChange(e: JSX.TargetedEvent) { + const newValue = parseInt(e.currentTarget.value, 10) + setCurrentValue(newValue) + setInstantExecutionCount((c) => c + 1) + } + + return ( +
+

TanStack Pacer useRateLimitedValue Example 3

+
+ + +
+
+ +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Execution Count:{rateLimiter.state.executionCount}
Rejection Count:{rateLimiter.state.rejectionCount}
Remaining in Window:{rateLimiter.getRemainingInWindow()}
Ms Until Next Window:{rateLimiter.getMsUntilNextWindow()}
Instant Executions:{instantExecutionCount}
Saved Executions:{instantExecutionCount - rateLimiter.state.executionCount}
% Reduction: + {instantExecutionCount === 0 + ? '0' + : Math.round( + ((instantExecutionCount - + rateLimiter.state.executionCount) / + instantExecutionCount) * + 100, + )} + % +
+
+

Rate limited to 20 updates per 2 seconds

+
+
+        {JSON.stringify(rateLimiter.store.state, null, 2)}
+      
+
+ ) +} + +const root = document.getElementById('root')! +render( +
+ +
+ +
+ +
, + root, +) diff --git a/examples/preact/useRateLimitedValue/tsconfig.json b/examples/preact/useRateLimitedValue/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useRateLimitedValue/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useRateLimitedValue/vite.config.ts b/examples/preact/useRateLimitedValue/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useRateLimitedValue/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useRateLimiter/README.md b/examples/preact/useRateLimiter/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useRateLimiter/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useRateLimiter/index.html b/examples/preact/useRateLimiter/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useRateLimiter/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useRateLimiter/package.json b/examples/preact/useRateLimiter/package.json new file mode 100644 index 00000000..bc28acbe --- /dev/null +++ b/examples/preact/useRateLimiter/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-rate-limiter", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useRateLimiter/public/emblem-light.svg b/examples/preact/useRateLimiter/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useRateLimiter/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useRateLimiter/src/index.tsx b/examples/preact/useRateLimiter/src/index.tsx new file mode 100644 index 00000000..13dcd060 --- /dev/null +++ b/examples/preact/useRateLimiter/src/index.tsx @@ -0,0 +1,338 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { + rateLimiterOptions, + useRateLimiter, +} from '@tanstack/preact-pacer/rate-limiter' +import { PacerProvider } from '@tanstack/preact-pacer/provider' + +const commonRateLimiterOptions = rateLimiterOptions({ + limit: 5, + window: 5000, +}) + +function App1() { + const [windowType, setWindowType] = useState<'fixed' | 'sliding'>('fixed') + + // Use your state management library of choice + const [instantCount, setInstantCount] = useState(0) // not rate-limited + const [limitedCount, setLimitedCount] = useState(0) // rate-limited + + // Using useRateLimiter with a rate limit of 5 executions per 5 seconds + const rateLimiter = useRateLimiter( + setLimitedCount, + { + // enabled: () => instantCount > 2, + ...commonRateLimiterOptions, + windowType: windowType, + onReject: (rateLimiter) => + console.log( + 'Rejected by rate limiter', + rateLimiter.getMsUntilNextWindow(), + ), + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + executionCount: state.executionCount, + rejectionCount: state.rejectionCount, + }), + ) + + function increment() { + // this pattern helps avoid common bugs with stale closures and state + setInstantCount((c) => { + const newCount = c + 1 // common new value for both + rateLimiter.maybeExecute(newCount) // rate-limited state update + return newCount // instant state update + }) + } + + return ( +
+

TanStack Pacer useRateLimiter Example 1

+
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Execution Count:{rateLimiter.state.executionCount}
Rejection Count:{rateLimiter.state.rejectionCount}
Remaining in Window:{rateLimiter.getRemainingInWindow()}
Ms Until Next Window:{rateLimiter.getMsUntilNextWindow()}
+
+
Instant Count:{instantCount}
Rate Limited Count:{limitedCount}
+
+ + +
+
+        {JSON.stringify(rateLimiter.store.state, null, 2)}
+      
+
+ ) +} + +function App2() { + const [instantSearch, setInstantSearch] = useState('') + const [limitedSearch, setLimitedSearch] = useState('') + + // Using useRateLimiter with a rate limit of 5 executions per 5 seconds + const rateLimiter = useRateLimiter( + setLimitedSearch, + { + enabled: instantSearch.length > 2, // optional, defaults to true + ...commonRateLimiterOptions, + // windowType: 'sliding', // default is 'fixed' + onReject: (rateLimiter) => + console.log( + 'Rejected by rate limiter', + rateLimiter.getMsUntilNextWindow(), + ), + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + executionCount: state.executionCount, + rejectionCount: state.rejectionCount, + }), + ) + + function handleSearchChange(e: JSX.TargetedEvent) { + const newValue = e.currentTarget.value + setInstantSearch(newValue) + rateLimiter.maybeExecute(newValue) + } + + return ( +
+

TanStack Pacer useRateLimiter Example 2

+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Execution Count:{rateLimiter.state.executionCount}
Rejection Count:{rateLimiter.state.rejectionCount}
Remaining in Window:{rateLimiter.getRemainingInWindow()}
Ms Until Next Window:{rateLimiter.getMsUntilNextWindow()}
+
+
Instant Search:
Rate Limited Search:{limitedSearch}
+
+ +
+
+        {JSON.stringify(rateLimiter.store.state, null, 2)}
+      
+
+ ) +} + +function App3() { + const [currentValue, setCurrentValue] = useState(50) + const [limitedValue, setLimitedValue] = useState(50) + const [instantExecutionCount, setInstantExecutionCount] = useState(0) + + // Using useRateLimiter with a rate limit of 5 executions per 5 seconds + const rateLimiter = useRateLimiter( + setLimitedValue, + { + limit: 20, + window: 2000, + onReject: (rateLimiter) => + console.log( + 'Rejected by rate limiter', + rateLimiter.getMsUntilNextWindow(), + ), + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + executionCount: state.executionCount, + rejectionCount: state.rejectionCount, + }), + ) + + function handleRangeChange(e: JSX.TargetedEvent) { + const newValue = parseInt(e.currentTarget.value, 10) + setCurrentValue(newValue) + setInstantExecutionCount((c) => c + 1) + rateLimiter.maybeExecute(newValue) + } + + return ( +
+

TanStack Pacer useRateLimiter Example 3

+
+ +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Execution Count:{rateLimiter.state.executionCount}
Rejection Count:{rateLimiter.state.rejectionCount}
Remaining in Window:{rateLimiter.getRemainingInWindow()}
Ms Until Next Window:{rateLimiter.getMsUntilNextWindow()}
Instant Executions:{instantExecutionCount}
Saved Executions:{instantExecutionCount - rateLimiter.state.executionCount}
% Reduction: + {instantExecutionCount === 0 + ? '0' + : Math.round( + ((instantExecutionCount - + rateLimiter.state.executionCount) / + instantExecutionCount) * + 100, + )} + % +
+
+

Rate limited to 20 updates per 2 seconds

+
+
+        {JSON.stringify(rateLimiter.store.state, null, 2)}
+      
+
+ ) +} + +const root = document.getElementById('root')! +render( + // optionally, provide default options to an optional PacerProvider + +
+ +
+ +
+ +
+
, + root, +) diff --git a/examples/preact/useRateLimiter/tsconfig.json b/examples/preact/useRateLimiter/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useRateLimiter/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useRateLimiter/vite.config.ts b/examples/preact/useRateLimiter/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useRateLimiter/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useRateLimiterWithPersister/README.md b/examples/preact/useRateLimiterWithPersister/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useRateLimiterWithPersister/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useRateLimiterWithPersister/index.html b/examples/preact/useRateLimiterWithPersister/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useRateLimiterWithPersister/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useRateLimiterWithPersister/package.json b/examples/preact/useRateLimiterWithPersister/package.json new file mode 100644 index 00000000..f990c8ce --- /dev/null +++ b/examples/preact/useRateLimiterWithPersister/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-rate-limiter-with-persister", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useRateLimiterWithPersister/public/emblem-light.svg b/examples/preact/useRateLimiterWithPersister/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useRateLimiterWithPersister/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useRateLimiterWithPersister/src/index.tsx b/examples/preact/useRateLimiterWithPersister/src/index.tsx new file mode 100644 index 00000000..abb1c0ea --- /dev/null +++ b/examples/preact/useRateLimiterWithPersister/src/index.tsx @@ -0,0 +1,335 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { useRateLimiter } from '@tanstack/preact-pacer/rate-limiter' +// import { useStoragePersister } from '@tanstack/preact-persister/storage-persister' +// import type { RateLimiterState } from '@tanstack/preact-pacer/rate-limiter' + +function App1() { + const [windowType, setWindowType] = useState<'fixed' | 'sliding'>('fixed') + + // Use your state management library of choice + const [instantCount, setInstantCount] = useState(0) // not rate-limited + const [limitedCount, setLimitedCount] = useState(0) // rate-limited + + // const rateLimiterPersister = useStoragePersister({ + // key: 'my-rate-limiter', + // storage: localStorage, + // maxAge: 1000 * 60, // 1 minute + // buster: 'v1', + // }) + // const rateLimiterPersister = undefined as any + + // Using useRateLimiter with a rate limit of 5 executions per 5 seconds + const rateLimiter = useRateLimiter( + setLimitedCount, + { + // enabled: () => instantCount > 2, + limit: 5, + window: 5000, + windowType: windowType, + onReject: (rateLimiter) => + console.log( + 'Rejected by rate limiter', + rateLimiter.getMsUntilNextWindow(), + ), + // optional local storage persister to retain state on page refresh + // initialState: rateLimiterPersister?.loadState(), + }, + // Optional Selector function to pick the state you want to track and use + (state) => state, // entire state subscription for persister - don't do this unless you need to + ) + + // useEffect(() => { + // rateLimiterPersister?.saveState(rateLimiter.state) + // }, [rateLimiter.state]) + + function increment() { + // this pattern helps avoid common bugs with stale closures and state + setInstantCount((c) => { + const newCount = c + 1 // common new value for both + rateLimiter.maybeExecute(newCount) // rate-limited state update + return newCount // instant state update + }) + } + + return ( +
+

TanStack Pacer useRateLimiter Example 1 (with persister)

+
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Execution Count:{rateLimiter.state.executionCount}
Rejection Count:{rateLimiter.state.rejectionCount}
Remaining in Window:{rateLimiter.getRemainingInWindow()}
Ms Until Next Window:{rateLimiter.getMsUntilNextWindow()}
+
+
Instant Count:{instantCount}
Rate Limited Count:{limitedCount}
+
+ + +
+
+        {JSON.stringify(rateLimiter.store.state, null, 2)}
+      
+
+ ) +} + +function App2() { + const [instantSearch, setInstantSearch] = useState('') + const [limitedSearch, setLimitedSearch] = useState('') + + // Using useRateLimiter with a rate limit of 5 executions per 5 seconds + const rateLimiter = useRateLimiter( + setLimitedSearch, + { + enabled: instantSearch.length > 2, // optional, defaults to true + limit: 5, + window: 5000, + // windowType: 'sliding', // default is 'fixed' + onReject: (rateLimiter) => + console.log( + 'Rejected by rate limiter', + rateLimiter.getMsUntilNextWindow(), + ), + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + executionCount: state.executionCount, + rejectionCount: state.rejectionCount, + }), + ) + + function handleSearchChange(e: JSX.TargetedEvent) { + const newValue = e.currentTarget.value + setInstantSearch(newValue) + rateLimiter.maybeExecute(newValue) + } + + return ( +
+

TanStack Pacer useRateLimiter Example 2

+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Execution Count:{rateLimiter.state.executionCount}
Rejection Count:{rateLimiter.state.rejectionCount}
Remaining in Window:{rateLimiter.getRemainingInWindow()}
Ms Until Next Window:{rateLimiter.getMsUntilNextWindow()}
+
+
Instant Search:
Rate Limited Search:{limitedSearch}
+
+ +
+
+        {JSON.stringify(rateLimiter.store.state, null, 2)}
+      
+
+ ) +} + +function App3() { + const [currentValue, setCurrentValue] = useState(50) + const [limitedValue, setLimitedValue] = useState(50) + const [instantExecutionCount, setInstantExecutionCount] = useState(0) + + // Using useRateLimiter with a rate limit of 5 executions per 5 seconds + const rateLimiter = useRateLimiter( + setLimitedValue, + { + limit: 20, + window: 2000, + onReject: (rateLimiter) => + console.log( + 'Rejected by rate limiter', + rateLimiter.getMsUntilNextWindow(), + ), + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + executionCount: state.executionCount, + rejectionCount: state.rejectionCount, + }), + ) + + function handleRangeChange(e: JSX.TargetedEvent) { + const newValue = parseInt(e.currentTarget.value, 10) + setCurrentValue(newValue) + setInstantExecutionCount((c) => c + 1) + rateLimiter.maybeExecute(newValue) + } + + return ( +
+

TanStack Pacer useRateLimiter Example 3

+
+ +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Execution Count:{rateLimiter.state.executionCount}
Rejection Count:{rateLimiter.state.rejectionCount}
Remaining in Window:{rateLimiter.getRemainingInWindow()}
Ms Until Next Window:{rateLimiter.getMsUntilNextWindow()}
Instant Executions:{instantExecutionCount}
Saved Executions:{instantExecutionCount - rateLimiter.state.executionCount}
% Reduction: + {instantExecutionCount === 0 + ? '0' + : Math.round( + ((instantExecutionCount - + rateLimiter.state.executionCount) / + instantExecutionCount) * + 100, + )} + % +
+
+

Rate limited to 20 updates per 2 seconds

+
+
+        {JSON.stringify(rateLimiter.store.state, null, 2)}
+      
+
+ ) +} + +const root = document.getElementById('root')! +render( +
+ +
+ +
+ +
, + root, +) diff --git a/examples/preact/useRateLimiterWithPersister/tsconfig.json b/examples/preact/useRateLimiterWithPersister/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useRateLimiterWithPersister/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useRateLimiterWithPersister/vite.config.ts b/examples/preact/useRateLimiterWithPersister/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useRateLimiterWithPersister/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useThrottledCallback/README.md b/examples/preact/useThrottledCallback/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useThrottledCallback/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useThrottledCallback/index.html b/examples/preact/useThrottledCallback/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useThrottledCallback/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useThrottledCallback/package.json b/examples/preact/useThrottledCallback/package.json new file mode 100644 index 00000000..f33fab8f --- /dev/null +++ b/examples/preact/useThrottledCallback/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-use-throttled-callback", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useThrottledCallback/public/emblem-light.svg b/examples/preact/useThrottledCallback/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useThrottledCallback/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useThrottledCallback/src/index.tsx b/examples/preact/useThrottledCallback/src/index.tsx new file mode 100644 index 00000000..7676e969 --- /dev/null +++ b/examples/preact/useThrottledCallback/src/index.tsx @@ -0,0 +1,156 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { useThrottledCallback } from '@tanstack/preact-pacer/throttler' + +function App1() { + // Use your state management library of choice + const [instantCount, setInstantCount] = useState(0) + const [throttledCount, setThrottledCount] = useState(0) + + // Create throttled setter function - Stable reference provided by useThrottledCallback + const throttledSetCount = useThrottledCallback(setThrottledCount, { + wait: 1000, + enabled: () => instantCount > 2, + }) + + function increment() { + // this pattern helps avoid common bugs with stale closures and state + setInstantCount((c) => { + const newInstantCount = c + 1 // common new value for both + throttledSetCount(newInstantCount) // throttled state update + return newInstantCount // instant state update + }) + } + + return ( +
+

TanStack Pacer useThrottledCallback Example 1

+ + + + + + + + + + + +
Instant Count:{instantCount}
Throttled Count:{throttledCount}
+
+ +
+
+ ) +} + +function App2() { + const [searchText, setSearchText] = useState('') + const [throttledSearchText, setThrottledSearchText] = useState('') + + // Create throttled setter function - Stable reference provided by useThrottledCallback + const throttledSetSearch = useThrottledCallback(setThrottledSearchText, { + wait: 1000, + enabled: () => searchText.length > 2, + }) + + function handleSearchChange(e: JSX.TargetedEvent) { + const newValue = e.currentTarget.value + setSearchText(newValue) + throttledSetSearch(newValue) + } + + return ( +
+

TanStack Pacer useThrottledCallback Example 2

+
+ +
+ + + + + + + + + + + +
Instant Search:{searchText}
Throttled Search:{throttledSearchText}
+
+ ) +} + +function App3() { + const [currentValue, setCurrentValue] = useState(50) + const [throttledValue, setThrottledValue] = useState(50) + + // Create throttled setter function - Stable reference provided by useThrottledCallback + const throttledSetValue = useThrottledCallback(setThrottledValue, { + wait: 250, + }) + + function handleRangeChange(e: JSX.TargetedEvent) { + const newValue = parseInt(e.currentTarget.value, 10) + setCurrentValue(newValue) + throttledSetValue(newValue) + } + + return ( +
+

TanStack Pacer useThrottledCallback Example 3

+
+ +
+
+ +
+
+

Throttled to 1 update per 250ms

+
+
+ ) +} + +const root = document.getElementById('root')! +render( +
+ +
+ +
+ +
, + root, +) diff --git a/examples/preact/useThrottledCallback/tsconfig.json b/examples/preact/useThrottledCallback/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useThrottledCallback/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useThrottledCallback/vite.config.ts b/examples/preact/useThrottledCallback/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useThrottledCallback/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useThrottledState/README.md b/examples/preact/useThrottledState/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useThrottledState/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useThrottledState/index.html b/examples/preact/useThrottledState/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useThrottledState/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useThrottledState/package.json b/examples/preact/useThrottledState/package.json new file mode 100644 index 00000000..dd62fe25 --- /dev/null +++ b/examples/preact/useThrottledState/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-use-throttled-state", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useThrottledState/public/emblem-light.svg b/examples/preact/useThrottledState/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useThrottledState/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useThrottledState/src/index.tsx b/examples/preact/useThrottledState/src/index.tsx new file mode 100644 index 00000000..8bbff926 --- /dev/null +++ b/examples/preact/useThrottledState/src/index.tsx @@ -0,0 +1,219 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { useThrottledState } from '@tanstack/preact-pacer/throttler' + +function App1() { + const [instantCount, setInstantCount] = useState(0) + + // higher-level hook that uses Preact.useState with the state setter automatically throttled + // optionally, grab the throttler from the last index of the returned array + const [throttledCount, setThrottledCount, throttler] = useThrottledState( + instantCount, + { + wait: 1000, + // enabled: () => instantCount > 2, // optional, defaults to true + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + executionCount: state.executionCount, + }), + ) + + function increment() { + // this pattern helps avoid common bugs with stale closures and state + setInstantCount((c) => { + const newInstantCount = c + 1 // common new value for both + setThrottledCount(newInstantCount) // throttled state update + return newInstantCount // instant state update + }) + } + + return ( +
+

TanStack Pacer useThrottledState Example 1

+ + + + + + + + + + + + + + + +
Execution Count:{throttler.state.executionCount}
Instant Count:{instantCount}
Throttled Count:{throttledCount}
+
+ +
+
+        {JSON.stringify(throttler.store.state, null, 2)}
+      
+
+ ) +} + +function App2() { + const [instantSearch, setInstantSearch] = useState('') + + // higher-level hook that uses Preact.useState with the state setter automatically throttled + const [throttledSearch, setThrottledSearch, throttler] = useThrottledState( + instantSearch, + { + wait: 1000, + // enabled: instantSearch.length > 2, // optional, defaults to true + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + executionCount: state.executionCount, + }), + ) + + function handleSearchChange(e: JSX.TargetedEvent) { + const newValue = e.currentTarget.value + setInstantSearch(newValue) + setThrottledSearch(newValue) + } + + return ( +
+

TanStack Pacer useThrottledState Example 2

+
+ +
+ + + + + + + + + + + + + + + +
Execution Count:{throttler.state.executionCount}
Instant Search:{instantSearch}
Throttled Search:{throttledSearch}
+
+        {JSON.stringify(throttler.store.state, null, 2)}
+      
+
+ ) +} + +function App3() { + const [instantExecutionCount, setInstantExecutionCount] = useState(0) + const [currentValue, setCurrentValue] = useState(50) + + // higher-level hook that uses Preact.useState with the state setter automatically throttled + const [throttledValue, setThrottledValue, throttler] = useThrottledState( + currentValue, + { + wait: 250, + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + executionCount: state.executionCount, + }), + ) + + function handleRangeChange(e: JSX.TargetedEvent) { + const newValue = parseInt(e.currentTarget.value, 10) + setCurrentValue(newValue) + setThrottledValue(newValue) + setInstantExecutionCount((c) => c + 1) + } + + return ( +
+

TanStack Pacer useThrottledState Example 3

+
+ +
+
+ +
+ + + + + + + + + + + + + + + +
Instant Execution Count:{instantExecutionCount}
Throttled Execution Count:{throttler.state.executionCount}
Saved Executions: + {instantExecutionCount - throttler.state.executionCount} ( + {instantExecutionCount > 0 + ? ( + ((instantExecutionCount - throttler.state.executionCount) / + instantExecutionCount) * + 100 + ).toFixed(2) + : 0} + % Reduction in execution calls) +
+
+

Throttled to 1 update per 250ms

+
+
+        {JSON.stringify(throttler.store.state, null, 2)}
+      
+
+ ) +} + +const root = document.getElementById('root')! +render( +
+ +
+ +
+ +
, + root, +) diff --git a/examples/preact/useThrottledState/tsconfig.json b/examples/preact/useThrottledState/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useThrottledState/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useThrottledState/vite.config.ts b/examples/preact/useThrottledState/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useThrottledState/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useThrottledValue/README.md b/examples/preact/useThrottledValue/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useThrottledValue/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useThrottledValue/index.html b/examples/preact/useThrottledValue/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useThrottledValue/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useThrottledValue/package.json b/examples/preact/useThrottledValue/package.json new file mode 100644 index 00000000..f7a1e39b --- /dev/null +++ b/examples/preact/useThrottledValue/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-use-throttled-value", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useThrottledValue/public/emblem-light.svg b/examples/preact/useThrottledValue/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useThrottledValue/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useThrottledValue/src/index.tsx b/examples/preact/useThrottledValue/src/index.tsx new file mode 100644 index 00000000..5761ad36 --- /dev/null +++ b/examples/preact/useThrottledValue/src/index.tsx @@ -0,0 +1,193 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { useThrottledValue } from '@tanstack/preact-pacer/throttler' + +function App1() { + const [instantCount, setInstantCount] = useState(0) + + function increment() { + setInstantCount((c) => c + 1) + } + + // highest-level hook that watches an instant local state value and returns a throttled value + // optionally, grab the throttler from the last index of the returned array + const [throttledCount] = useThrottledValue( + instantCount, + { + wait: 1000, + // enabled: () => instantCount > 2, // optional, defaults to true + }, + // Optional Selector function to pick the state you want to track and use + (_state) => ({}), // No specific state access needed for this example + ) + + return ( +
+

TanStack Pacer useThrottledValue Example 1

+ + + + + + + + + + + +
Instant Count:{instantCount}
Throttled Count:{throttledCount}
+
+ +
+
+ ) +} + +function App2() { + const [instantSearch, setInstantSearch] = useState('') + + // highest-level hook that watches an instant local state value and returns a throttled value + const [throttledSearch] = useThrottledValue( + instantSearch, + { + wait: 1000, + // enabled: instantSearch.length > 2, // optional, defaults to true + }, + // Optional Selector function to pick the state you want to track and use + (_state) => ({}), // No specific state access needed for this example + ) + + function handleSearchChange(e: JSX.TargetedEvent) { + setInstantSearch(e.currentTarget.value) + } + + return ( +
+

TanStack Pacer useThrottledValue Example 2

+
+ +
+ + + + + + + + + + + +
Instant Search:{instantSearch}
Throttled Search:{throttledSearch}
+
+ ) +} + +function App3() { + const [instantExecutionCount, setInstantExecutionCount] = useState(0) + const [currentValue, setCurrentValue] = useState(50) + + // highest-level hook that watches an instant local state value and returns a throttled value + const [throttledValue, throttler] = useThrottledValue( + currentValue, + { + wait: 250, + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ + executionCount: state.executionCount, + }), + ) + + function handleRangeChange(e: JSX.TargetedEvent) { + const newValue = parseInt(e.currentTarget.value, 10) + setCurrentValue(newValue) + setInstantExecutionCount((c) => c + 1) + } + + return ( +
+

TanStack Pacer useThrottledValue Example 3

+
+ +
+
+ +
+ + + + + + + + + + + + + + + +
Instant Execution Count:{instantExecutionCount}
Throttled Execution Count:{throttler.state.executionCount}
Saved Executions: + {instantExecutionCount - throttler.state.executionCount} ( + {instantExecutionCount > 0 + ? ( + ((instantExecutionCount - throttler.state.executionCount) / + instantExecutionCount) * + 100 + ).toFixed(2) + : 0} + % Reduction in execution calls) +
+
+

Throttled to 1 update per 250ms

+
+
+        {JSON.stringify(throttler.store.state, null, 2)}
+      
+
+ ) +} + +const root = document.getElementById('root')! +render( +
+ +
+ +
+ +
, + root, +) diff --git a/examples/preact/useThrottledValue/tsconfig.json b/examples/preact/useThrottledValue/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useThrottledValue/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useThrottledValue/vite.config.ts b/examples/preact/useThrottledValue/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useThrottledValue/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/useThrottler/README.md b/examples/preact/useThrottler/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/useThrottler/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/useThrottler/index.html b/examples/preact/useThrottler/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/useThrottler/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/useThrottler/package.json b/examples/preact/useThrottler/package.json new file mode 100644 index 00000000..097a8bed --- /dev/null +++ b/examples/preact/useThrottler/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tanstack/pacer-example-preact-use-throttler", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-pacer": "^0.17.3", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/useThrottler/public/emblem-light.svg b/examples/preact/useThrottler/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/useThrottler/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/useThrottler/src/index.tsx b/examples/preact/useThrottler/src/index.tsx new file mode 100644 index 00000000..c600f191 --- /dev/null +++ b/examples/preact/useThrottler/src/index.tsx @@ -0,0 +1,248 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { useThrottler } from '@tanstack/preact-pacer/throttler' +import { PacerProvider } from '@tanstack/preact-pacer/provider' + +function App1() { + // Use your state management library of choice + const [instantCount, setInstantCount] = useState(0) + const [throttledCount, setThrottledCount] = useState(0) + + // Lower-level useThrottler hook - requires you to manage your own state + const setCountThrottler = useThrottler( + setThrottledCount, + { + wait: 1000, + // leading: true, // default + // trailing: true, // default + // enabled: () => instantCount > 2, + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ executionCount: state.executionCount }), + ) + + function increment() { + // this pattern helps avoid common bugs with stale closures and state + setInstantCount((c) => { + const newInstantCount = c + 1 // common new value for both + setCountThrottler.maybeExecute(newInstantCount) // throttled state update + return newInstantCount // instant state update + }) + } + + return ( +
+

TanStack Pacer useThrottler Example 1

+ + + + + + + + + + + + + + + +
Execution Count:{setCountThrottler.state.executionCount}
Instant Count:{instantCount}
Throttled Count:{throttledCount}
+
+ + +
+
+        {JSON.stringify(setCountThrottler.store.state, null, 2)}
+      
+
+ ) +} + +function App2() { + const [instantSearch, setInstantSearch] = useState('') + const [throttledSearch, setThrottledSearch] = useState('') + + // Lower-level useThrottler hook - requires you to manage your own state + const setSearchThrottler = useThrottler( + setThrottledSearch, + { + wait: 1000, + enabled: instantSearch.length > 2, + }, + // Optional Selector function to pick the state you want to track and use + + (state) => ({ executionCount: state.executionCount }), + ) + + function handleSearchChange(e: JSX.TargetedEvent) { + const newValue = e.currentTarget.value + setInstantSearch(newValue) + setSearchThrottler.maybeExecute(newValue) + } + + return ( +
+

TanStack Pacer useThrottler Example 2

+
+ +
+ + + + + + + + + + + + + + + +
Execution Count:{setSearchThrottler.state.executionCount}
Instant Search:{instantSearch}
Throttled Search:{throttledSearch}
+
+ +
+
+        {JSON.stringify(setSearchThrottler.store.state, null, 2)}
+      
+
+ ) +} + +function App3() { + const [instantExecutionCount, setInstantExecutionCount] = useState(0) + const [currentValue, setCurrentValue] = useState(50) + const [throttledValue, setThrottledValue] = useState(50) + + // Lower-level useThrottler hook - requires you to manage your own state + const setValueThrottler = useThrottler( + setThrottledValue, + { + wait: 250, + // leading: true, // default + // trailing: true, // default + }, + // Optional Selector function to pick the state you want to track and use + (state) => ({ executionCount: state.executionCount }), + ) + + function handleRangeChange(e: JSX.TargetedEvent) { + const newValue = parseInt(e.currentTarget.value, 10) + + // instant state update + setCurrentValue(newValue) + setInstantExecutionCount((c) => c + 1) + + // throttled state update + setValueThrottler.maybeExecute(newValue) + } + + return ( +
+

TanStack Pacer useThrottler Example 3

+
+ +
+
+ +
+ + + + + + + + + + + + + + + +
Instant Execution Count:{instantExecutionCount}
Throttled Execution Count:{setValueThrottler.state.executionCount}
Saved Executions: + {instantExecutionCount - setValueThrottler.state.executionCount} ( + {instantExecutionCount > 0 + ? ( + ((instantExecutionCount - + setValueThrottler.state.executionCount) / + instantExecutionCount) * + 100 + ).toFixed(2) + : 0} + % Reduction in execution calls) +
+
+

Throttled to 1 update per 250ms (trailing edge)

+
+
+ +
+
+        {JSON.stringify(setValueThrottler.store.state, null, 2)}
+      
+
+ ) +} + +const root = document.getElementById('root')! +render( + // optionally, provide default options to an optional PacerProvider + +
+ +
+ +
+ +
+
, + root, +) diff --git a/examples/preact/useThrottler/tsconfig.json b/examples/preact/useThrottler/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/useThrottler/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/useThrottler/vite.config.ts b/examples/preact/useThrottler/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/useThrottler/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/preact/util-comparison/README.md b/examples/preact/util-comparison/README.md new file mode 100644 index 00000000..1cf88926 --- /dev/null +++ b/examples/preact/util-comparison/README.md @@ -0,0 +1,6 @@ +# Example + +To run this example: + +- `npm install` +- `npm run dev` diff --git a/examples/preact/util-comparison/index.html b/examples/preact/util-comparison/index.html new file mode 100644 index 00000000..88e31073 --- /dev/null +++ b/examples/preact/util-comparison/index.html @@ -0,0 +1,15 @@ + + + + + + + + TanStack Pacer Example + + + +
+ + + diff --git a/examples/preact/util-comparison/package.json b/examples/preact/util-comparison/package.json new file mode 100644 index 00000000..8876869e --- /dev/null +++ b/examples/preact/util-comparison/package.json @@ -0,0 +1,33 @@ +{ + "name": "@tanstack/pacer-example-preact-util-comparison", + "private": true, + "type": "module", + "scripts": { + "dev": "vite --port=3005", + "build": "vite build", + "preview": "vite preview", + "test:types": "tsc" + }, + "dependencies": { + "@tanstack/preact-devtools": "^0.9.2", + "@tanstack/preact-pacer": "^0.17.3", + "@tanstack/preact-pacer-devtools": "workspace:*", + "preact": "^10.28.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "vite": "^7.2.7" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/preact/util-comparison/public/emblem-light.svg b/examples/preact/util-comparison/public/emblem-light.svg new file mode 100644 index 00000000..a1b982cf --- /dev/null +++ b/examples/preact/util-comparison/public/emblem-light.svg @@ -0,0 +1,14 @@ + + + + emblem-light + Created with Sketch. + + + + + + + + + diff --git a/examples/preact/util-comparison/src/index.tsx b/examples/preact/util-comparison/src/index.tsx new file mode 100644 index 00000000..57ffe3ac --- /dev/null +++ b/examples/preact/util-comparison/src/index.tsx @@ -0,0 +1,462 @@ +import { useState } from 'preact/hooks' +import { render } from 'preact' +import type { JSX } from 'preact' +import { useDebouncer } from '@tanstack/preact-pacer/debouncer' +import { useThrottler } from '@tanstack/preact-pacer/throttler' +import { useRateLimiter } from '@tanstack/preact-pacer/rate-limiter' +import { useQueuer } from '@tanstack/preact-pacer/queuer' +import { useBatcher } from '@tanstack/preact-pacer/batcher' +import { pacerDevtoolsPlugin } from '@tanstack/preact-pacer-devtools' +import { TanStackDevtools } from '@tanstack/preact-devtools' + +function ComparisonApp() { + const [currentValue, setCurrentValue] = useState(50) + const [instantExecutionCount, setInstantExecutionCount] = useState(0) + + // State for each utility + const [debouncedValue, setDebouncedValue] = useState(50) + const [throttledValue, setThrottledValue] = useState(50) + const [rateLimitedValue, setRateLimitedValue] = useState(50) + const [queuedValue, setQueuedValue] = useState(50) + const [batchedValue, setBatchedValue] = useState(50) + + // Initialize each utility + const debouncer = useDebouncer( + setDebouncedValue, + { + key: 'my-debouncer', + wait: 600, + }, + (state) => state, + ) + + const throttler = useThrottler( + setThrottledValue, + { + key: 'my-throttler', + wait: 600, + }, + (state) => state, + ) + + const rateLimiter = useRateLimiter( + setRateLimitedValue, + { + key: 'my-rate-limiter', + limit: 20, + window: 2000, + windowType: 'sliding', + }, + (state) => state, + ) + + const queuer = useQueuer( + setQueuedValue, + { + key: 'my-queuer', + wait: 100, + maxSize: 50, + }, + (state) => state, + ) + + const batcher = useBatcher( + (items: Array) => { + // Use the last item in the batch as the displayed value + if (items.length > 0) { + setBatchedValue(items[items.length - 1]) + } + }, + { + key: 'my-batcher', + wait: 600, + maxSize: 5, + }, + (state) => state, + ) + + function handleRangeChange(e: JSX.TargetedEvent) { + const newValue = parseInt(e.currentTarget.value, 10) + setCurrentValue(newValue) + setInstantExecutionCount((c) => c + 1) + + // Trigger each utility + debouncer.maybeExecute(newValue) + throttler.maybeExecute(newValue) + rateLimiter.maybeExecute(newValue) + queuer.addItem(newValue) + batcher.addItem(newValue) + } + + // Helper function to determine sync status + function getSyncStatus(processedValue: number, utilityName: string) { + const isOutOfSync = processedValue !== currentValue + const isPending = + (utilityName === 'Debouncer' && debouncer.state.status === 'pending') || + (utilityName === 'Throttler' && throttler.state.status === 'pending') || + (utilityName === 'Queuer' && queuer.state.status === 'running') || + (utilityName === 'Batcher' && batcher.state.status === 'pending') + + // Tooltip explanations for why certain utilities become out of sync + const getTooltip = () => { + if (!isOutOfSync) return undefined + + switch (utilityName) { + case 'Rate Limiter': + return isPending + ? 'Rate limiter is processing within limits' + : 'Rate limiters reject executions when the limit is exceeded. Rejected calls are discarded entirely and never processed, causing the value to lag behind rapid changes.' + case 'Queuer': + return isPending + ? 'Queuer is processing items from the queue' + : 'Queuers reject new items when their buffer is full. If items are added faster than they can be processed, the buffer overflows and newer items are dropped.' + default: + return undefined + } + } + + return { + isOutOfSync, + isPending, + statusText: isOutOfSync + ? isPending + ? 'Processing...' + : 'Out of sync' + : 'Synced', + tooltip: getTooltip(), + } + } + + // Warning icon SVG + const WarningIcon = ({ size = 16 }: { size?: number }) => ( + + + + + + ) + + // Success icon SVG + const SuccessIcon = ({ size = 16 }: { size?: number }) => ( + + + + + ) + + const utilityData = [ + { + name: 'Debouncer', + value: debouncedValue, + state: debouncer.state, + description: `Delays execution until after ${debouncer.options.wait}ms of inactivity`, + color: '#3b82f6', // blue + flush: () => debouncer.flush(), + }, + { + name: 'Throttler', + value: throttledValue, + state: throttler.state, + description: `Limits execution to once every ${throttler.options.wait}ms`, + color: '#0891b2', // cyan + flush: () => throttler.flush(), + }, + { + name: 'Rate Limiter', + value: rateLimitedValue, + state: rateLimiter.state, + description: `Allows max ${rateLimiter.options.limit} executions per ${rateLimiter.options.window}ms window`, + color: '#ea580c', // orange + }, + { + name: 'Queuer', + value: queuedValue, + state: queuer.state, + description: `Processes items sequentially with ${queuer.options.wait}ms delay`, + color: '#db2777', // pink + flush: () => queuer.flush(), + }, + { + name: 'Batcher', + value: batchedValue, + state: batcher.state, + description: `Processes in batches of ${batcher.options.maxSize} or after ${batcher.options.wait}ms`, + color: '#8b5cf6', // purple + flush: () => batcher.flush(), + }, + ] as const + + return ( +
+

+ TanStack Pacer Utilities Comparison +

+ +
+

+ Instant Slider (Move this slider to see the utilities in action) +

+
+ +
+
+ Total Interactions: {instantExecutionCount} +
+
+ +
+ {utilityData.map((utility) => { + const syncStatus = getSyncStatus(utility.value, utility.name) + return ( +
+

+ {utility.name} +

+

+ {utility.description} +

+ +
+
+ + Value: {utility.value} + +
+
+ {syncStatus.isOutOfSync ? ( + + + {syncStatus.statusText} + + ) : ( + + + {syncStatus.statusText} + + )} +
+ + alert( + 'These sliders are read-only. Move the main slider at the top', + ) + } + type="range" + min="0" + max="100" + value={utility.value} + readOnly + style={{ + width: '100%', + margin: '2px 0', + accentColor: utility.color, + }} + /> +
+ +
+
+ Executions: {utility.state.executionCount} +
+
+ Reduction:{' '} + {instantExecutionCount === 0 + ? '0' + : Math.round( + ((instantExecutionCount - + utility.state.executionCount) / + instantExecutionCount) * + 100, + )} + % +
+ {utility.name === 'Rate Limiter' && ( +
+ Rejections:{' '} + {(utility.state as any).rejectionCount} +
+ )} + {utility.name === 'Queuer' && ( + <> +
+ Queue Size: {utility.state.size} +
+ + )} + {utility.name === 'Batcher' && ( + <> +
+ Batch Size: {utility.state.size} +
+
+ Items Processed:{' '} + {(utility.state as any).totalItemsProcessed} +
+ + )} +
+ Status: {utility.state.status} +
+
+ {'flush' in utility && typeof utility.flush === 'function' && ( + + )} +
+ ) + })} +
+ +
+

+ Detailed States +

+
+ {utilityData.map((utility) => ( +
+

+ {utility.name} State +

+
+                {JSON.stringify(utility.state, null, 2)}
+              
+
+ ))} +
+
+ +
+ ) +} + +const root = document.getElementById('root')! +render(, root) diff --git a/examples/preact/util-comparison/tsconfig.json b/examples/preact/util-comparison/tsconfig.json new file mode 100644 index 00000000..857b1ed4 --- /dev/null +++ b/examples/preact/util-comparison/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + "jsxImportSource": "preact", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src", "vite.config.ts"] +} diff --git a/examples/preact/util-comparison/vite.config.ts b/examples/preact/util-comparison/vite.config.ts new file mode 100644 index 00000000..b995c32c --- /dev/null +++ b/examples/preact/util-comparison/vite.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from 'vite' +import preact from '@preact/preset-vite' + +// https://vite.dev/config/ +export default defineConfig({ + plugins: [preact()], +}) diff --git a/examples/react/asyncBatch/package.json b/examples/react/asyncBatch/package.json index 1aacb7ac..5b7475ef 100644 --- a/examples/react/asyncBatch/package.json +++ b/examples/react/asyncBatch/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/asyncDebounce/package.json b/examples/react/asyncDebounce/package.json index 6c2871d1..8d1a7f28 100644 --- a/examples/react/asyncDebounce/package.json +++ b/examples/react/asyncDebounce/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/asyncRateLimit/package.json b/examples/react/asyncRateLimit/package.json index 1faf3317..af2b15b7 100644 --- a/examples/react/asyncRateLimit/package.json +++ b/examples/react/asyncRateLimit/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/asyncRetry/package.json b/examples/react/asyncRetry/package.json index d3eac511..41cdba30 100644 --- a/examples/react/asyncRetry/package.json +++ b/examples/react/asyncRetry/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/asyncThrottle/package.json b/examples/react/asyncThrottle/package.json index 74ef0525..c48d7520 100644 --- a/examples/react/asyncThrottle/package.json +++ b/examples/react/asyncThrottle/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/batch/package.json b/examples/react/batch/package.json index 8849c99f..34b47645 100644 --- a/examples/react/batch/package.json +++ b/examples/react/batch/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/debounce/package.json b/examples/react/debounce/package.json index 3ee4902a..4c9c7146 100644 --- a/examples/react/debounce/package.json +++ b/examples/react/debounce/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/queue/package.json b/examples/react/queue/package.json index 980382ed..de45f050 100644 --- a/examples/react/queue/package.json +++ b/examples/react/queue/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@tanstack/react-devtools": "0.8.4", diff --git a/examples/react/rateLimit/package.json b/examples/react/rateLimit/package.json index 39070dec..ce8b34aa 100644 --- a/examples/react/rateLimit/package.json +++ b/examples/react/rateLimit/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/react-query-debounced-prefetch/package.json b/examples/react/react-query-debounced-prefetch/package.json index 7d1d7f3c..ce212afb 100644 --- a/examples/react/react-query-debounced-prefetch/package.json +++ b/examples/react/react-query-debounced-prefetch/package.json @@ -12,8 +12,8 @@ "@tanstack/react-pacer": "^0.17.4", "@tanstack/react-query": "^5.90.12", "@tanstack/react-query-devtools": "^5.91.1", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/react-query-queued-prefetch/package.json b/examples/react/react-query-queued-prefetch/package.json index e1450c41..b9873b08 100644 --- a/examples/react/react-query-queued-prefetch/package.json +++ b/examples/react/react-query-queued-prefetch/package.json @@ -12,8 +12,8 @@ "@tanstack/react-pacer": "^0.17.4", "@tanstack/react-query": "^5.90.12", "@tanstack/react-query-devtools": "^5.91.1", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/react-query-throttled-prefetch/package.json b/examples/react/react-query-throttled-prefetch/package.json index 7fd259b9..559aacc2 100644 --- a/examples/react/react-query-throttled-prefetch/package.json +++ b/examples/react/react-query-throttled-prefetch/package.json @@ -12,8 +12,8 @@ "@tanstack/react-pacer": "^0.17.4", "@tanstack/react-query": "^5.90.12", "@tanstack/react-query-devtools": "^5.91.1", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/throttle/package.json b/examples/react/throttle/package.json index ae53750e..488deaa7 100644 --- a/examples/react/throttle/package.json +++ b/examples/react/throttle/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useAsyncBatchedCallback/package.json b/examples/react/useAsyncBatchedCallback/package.json index b11671ce..d14b9419 100644 --- a/examples/react/useAsyncBatchedCallback/package.json +++ b/examples/react/useAsyncBatchedCallback/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useAsyncBatcher/package.json b/examples/react/useAsyncBatcher/package.json index 4641d622..5684179e 100644 --- a/examples/react/useAsyncBatcher/package.json +++ b/examples/react/useAsyncBatcher/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useAsyncDebouncedCallback/package.json b/examples/react/useAsyncDebouncedCallback/package.json index d89b1b0e..9700c721 100644 --- a/examples/react/useAsyncDebouncedCallback/package.json +++ b/examples/react/useAsyncDebouncedCallback/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useAsyncDebouncer/package.json b/examples/react/useAsyncDebouncer/package.json index 259321cd..50bad233 100644 --- a/examples/react/useAsyncDebouncer/package.json +++ b/examples/react/useAsyncDebouncer/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useAsyncQueuedState/package.json b/examples/react/useAsyncQueuedState/package.json index ddb9d2e0..b97e7a14 100644 --- a/examples/react/useAsyncQueuedState/package.json +++ b/examples/react/useAsyncQueuedState/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useAsyncQueuer/package.json b/examples/react/useAsyncQueuer/package.json index 54fba950..9fdb6347 100644 --- a/examples/react/useAsyncQueuer/package.json +++ b/examples/react/useAsyncQueuer/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useAsyncRateLimiter/package.json b/examples/react/useAsyncRateLimiter/package.json index 194a37fa..7c1c3695 100644 --- a/examples/react/useAsyncRateLimiter/package.json +++ b/examples/react/useAsyncRateLimiter/package.json @@ -11,8 +11,8 @@ "dependencies": { "@tanstack/react-pacer": "^0.17.4", "@tanstack/react-persister": "^0.1.1", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useAsyncRateLimiterWithPersister/package.json b/examples/react/useAsyncRateLimiterWithPersister/package.json index 4f2e41ba..a65b02d0 100644 --- a/examples/react/useAsyncRateLimiterWithPersister/package.json +++ b/examples/react/useAsyncRateLimiterWithPersister/package.json @@ -11,8 +11,8 @@ "dependencies": { "@tanstack/react-pacer": "^0.17.4", "@tanstack/react-persister": "^0.1.1", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useAsyncThrottledCallback/package.json b/examples/react/useAsyncThrottledCallback/package.json index a1168783..66c0860e 100644 --- a/examples/react/useAsyncThrottledCallback/package.json +++ b/examples/react/useAsyncThrottledCallback/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useAsyncThrottler/package.json b/examples/react/useAsyncThrottler/package.json index 9d9a9d22..68e6b5c2 100644 --- a/examples/react/useAsyncThrottler/package.json +++ b/examples/react/useAsyncThrottler/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useBatchedCallback/package.json b/examples/react/useBatchedCallback/package.json index 6e057b5d..78919a31 100644 --- a/examples/react/useBatchedCallback/package.json +++ b/examples/react/useBatchedCallback/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useBatcher/package.json b/examples/react/useBatcher/package.json index 0ff731a8..5f82266e 100644 --- a/examples/react/useBatcher/package.json +++ b/examples/react/useBatcher/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useDebouncedCallback/package.json b/examples/react/useDebouncedCallback/package.json index 4f47c574..8fb37da7 100644 --- a/examples/react/useDebouncedCallback/package.json +++ b/examples/react/useDebouncedCallback/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useDebouncedState/package.json b/examples/react/useDebouncedState/package.json index 86738ee1..676f57d3 100644 --- a/examples/react/useDebouncedState/package.json +++ b/examples/react/useDebouncedState/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useDebouncedValue/package.json b/examples/react/useDebouncedValue/package.json index 7577ff6e..f4954ac9 100644 --- a/examples/react/useDebouncedValue/package.json +++ b/examples/react/useDebouncedValue/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useDebouncer/package.json b/examples/react/useDebouncer/package.json index 718f8ab2..d637cddb 100644 --- a/examples/react/useDebouncer/package.json +++ b/examples/react/useDebouncer/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useQueuedState/package.json b/examples/react/useQueuedState/package.json index b0c5229e..17246712 100644 --- a/examples/react/useQueuedState/package.json +++ b/examples/react/useQueuedState/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useQueuedValue/package.json b/examples/react/useQueuedValue/package.json index 8ed3d966..5637f7d5 100644 --- a/examples/react/useQueuedValue/package.json +++ b/examples/react/useQueuedValue/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useQueuer/package.json b/examples/react/useQueuer/package.json index 6f675a4b..0de2a90c 100644 --- a/examples/react/useQueuer/package.json +++ b/examples/react/useQueuer/package.json @@ -11,8 +11,8 @@ "dependencies": { "@tanstack/react-pacer": "^0.17.4", "@tanstack/react-persister": "^0.1.1", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@tanstack/react-devtools": "0.8.4", diff --git a/examples/react/useQueuerWithPersister/package.json b/examples/react/useQueuerWithPersister/package.json index 11450860..57c5e25e 100644 --- a/examples/react/useQueuerWithPersister/package.json +++ b/examples/react/useQueuerWithPersister/package.json @@ -11,8 +11,8 @@ "dependencies": { "@tanstack/react-pacer": "^0.17.4", "@tanstack/react-persister": "^0.1.1", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useRateLimitedCallback/package.json b/examples/react/useRateLimitedCallback/package.json index b76c5f38..1f598075 100644 --- a/examples/react/useRateLimitedCallback/package.json +++ b/examples/react/useRateLimitedCallback/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useRateLimitedState/package.json b/examples/react/useRateLimitedState/package.json index 42b70f16..3ca2594c 100644 --- a/examples/react/useRateLimitedState/package.json +++ b/examples/react/useRateLimitedState/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useRateLimitedValue/package.json b/examples/react/useRateLimitedValue/package.json index 17028081..1a8a3112 100644 --- a/examples/react/useRateLimitedValue/package.json +++ b/examples/react/useRateLimitedValue/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useRateLimiter/package.json b/examples/react/useRateLimiter/package.json index 0e19e69e..260b2b10 100644 --- a/examples/react/useRateLimiter/package.json +++ b/examples/react/useRateLimiter/package.json @@ -11,8 +11,8 @@ "dependencies": { "@tanstack/react-pacer": "^0.17.4", "@tanstack/react-persister": "^0.1.1", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useRateLimiterWithPersister/package.json b/examples/react/useRateLimiterWithPersister/package.json index b5e00f80..cca1a69d 100644 --- a/examples/react/useRateLimiterWithPersister/package.json +++ b/examples/react/useRateLimiterWithPersister/package.json @@ -11,8 +11,8 @@ "dependencies": { "@tanstack/react-pacer": "^0.17.4", "@tanstack/react-persister": "^0.1.1", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useThrottledCallback/package.json b/examples/react/useThrottledCallback/package.json index be63ac96..eb8833bc 100644 --- a/examples/react/useThrottledCallback/package.json +++ b/examples/react/useThrottledCallback/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useThrottledState/package.json b/examples/react/useThrottledState/package.json index 0a0c20de..c84c7c91 100644 --- a/examples/react/useThrottledState/package.json +++ b/examples/react/useThrottledState/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useThrottledValue/package.json b/examples/react/useThrottledValue/package.json index a06b40a5..2afaf4ba 100644 --- a/examples/react/useThrottledValue/package.json +++ b/examples/react/useThrottledValue/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/useThrottler/package.json b/examples/react/useThrottler/package.json index 3e13e334..1eb1fce6 100644 --- a/examples/react/useThrottler/package.json +++ b/examples/react/useThrottler/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@types/react": "^19.2.7", diff --git a/examples/react/util-comparison/package.json b/examples/react/util-comparison/package.json index 35d89073..5136de61 100644 --- a/examples/react/util-comparison/package.json +++ b/examples/react/util-comparison/package.json @@ -10,8 +10,8 @@ }, "dependencies": { "@tanstack/react-pacer": "^0.17.4", - "react": "^19.2.1", - "react-dom": "^19.2.1" + "react": "^19.2.3", + "react-dom": "^19.2.3" }, "devDependencies": { "@tanstack/react-devtools": "0.8.4", diff --git a/package.json b/package.json index 6c947359..d8bd1304 100644 --- a/package.json +++ b/package.json @@ -8,26 +8,26 @@ "packageManager": "pnpm@10.25.0", "type": "module", "scripts": { - "build": "nx affected --skip-nx-cache --targets=build --exclude=examples/** && size-limit && pnpm run copy:readme", - "build:all": "nx run-many --targets=build --exclude=examples/** && size-limit && pnpm run copy:readme", - "build:core": "nx run-many --targets=build --projects=packages/pacer,packages/persister && size-limit && pnpm run copy:readme", + "build": "nx affected --skip-nx-cache --targets=build --exclude=examples/** && size-limit && pnpm run", + "build:all": "nx run-many --targets=build --exclude=examples/** && size-limit && pnpm run", + "build:core": "nx run-many --targets=build --projects=packages/pacer,packages/persister && size-limit && pnpm run", "changeset": "changeset", "changeset:publish": "changeset publish", "changeset:version": "changeset version && pnpm install --no-frozen-lockfile && pnpm format", "clean": "find . -name 'dist' -type d -prune -exec rm -rf {} +", "clean:node_modules": "find . -name 'node_modules' -type d -prune -exec rm -rf {} +", "clean:all": "pnpm run clean && pnpm run clean:node_modules", - "copy:readme": "cp README.md packages/pacer/README.md && cp README.md packages/pacer-devtools/README.md && cp README.md packages/pacer-lite/README.md && cp README.md packages/react-pacer/README.md && cp README.md packages/react-pacer-devtools/README.md && cp README.md packages/solid-pacer/README.md && cp README.md packages/solid-pacer-devtools/README.md", + "copy:readme": "cp README.md packages/pacer/README.md && cp README.md packages/pacer-devtools/README.md && cp README.md packages/pacer-lite/README.md && cp README.md packages/react-pacer/README.md && cp README.md packages/react-pacer-devtools/README.md && cp README.md packages/solid-pacer/README.md && cp README.md packages/solid-pacer-devtools/README.md && cp README.md packages/preact-pacer-devtools/README.md", "dev": "pnpm run watch", - "generate-docs": "node scripts/generate-docs.ts", + "format": "prettier --experimental-cli --ignore-unknown '**/*' --write", + "generate-docs": "node scripts/generate-docs.ts && pnpm run copy:readme", "lint:fix": "nx affected --target=lint:fix --exclude=examples/**", "lint:fix:all": "nx run-many --targets=lint --fix", - "format": "prettier --experimental-cli --ignore-unknown '**/*' --write", "size": "size-limit", "test": "pnpm run test:ci", "test:ci": "nx run-many --targets=test:eslint,test:sherif,test:knip,test:docs,test:lib,test:types,build", - "test:eslint": "nx affected --target=test:eslint --exclude=examples/**", "test:docs": "node scripts/verify-links.ts", + "test:eslint": "nx affected --target=test:eslint --exclude=examples/**", "test:knip": "knip", "test:lib": "nx affected --targets=test:lib --exclude=examples/**", "test:lib:dev": "pnpm test:lib && nx watch --all -- pnpm test:lib", @@ -57,22 +57,33 @@ "@tanstack/eslint-config": "0.3.4", "@tanstack/typedoc-config": "0.3.3", "@testing-library/jest-dom": "^6.9.1", - "@types/node": "^24.10.1", + "@types/node": "^25.0.0", "eslint": "^9.39.1", "eslint-plugin-unused-imports": "^4.3.0", "happy-dom": "^20.0.11", - "knip": "^5.72.0", + "knip": "^5.73.3", "markdown-link-extractor": "^4.0.3", - "nx": "^22.2.0", + "nx": "^22.2.1", "premove": "^4.0.0", "prettier": "^3.7.4", "prettier-plugin-svelte": "^3.4.0", - "publint": "^0.3.15", + "publint": "^0.3.16", "sherif": "^1.9.0", "size-limit": "^12.0.0", "tinyglobby": "^0.2.15", "tsdown": "^0.17.2", "typescript": "5.9.3", "vitest": "^4.0.15" + }, + "overrides": { + "@tanstack/pacer": "workspace:*", + "@tanstack/pacer-devtools": "workspace:*", + "@tanstack/pacer-lite": "workspace:*", + "@tanstack/preact-pacer": "workspace:*", + "@tanstack/preact-pacer-devtools": "workspace:*", + "@tanstack/react-pacer": "workspace:*", + "@tanstack/react-pacer-devtools": "workspace:*", + "@tanstack/solid-pacer": "workspace:*", + "@tanstack/solid-pacer-devtools": "workspace:*" } } diff --git a/packages/pacer-devtools/README.md b/packages/pacer-devtools/README.md index 42347dcc..5a42510f 100644 --- a/packages/pacer-devtools/README.md +++ b/packages/pacer-devtools/README.md @@ -89,9 +89,9 @@ A lightweight timing and scheduling library for debouncing, throttling, rate lim > You may know **TanSack Pacer** by our adapter names, too! > > - [**React Pacer**](https://tanstack.com/pacer/latest/docs/framework/react/react-pacer) +> - [**Preact Pacer**](https://tanstack.com/pacer/latest/docs/framework/preact/preact-pacer) > - [**Solid Pacer**](https://tanstack.com/pacer/latest/docs/framework/solid/solid-pacer) > - Angular Pacer - needs a contributor! -> - Preact Pacer - Coming soon! (After React Pacer is more fleshed out) > - Svelte Pacer - needs a contributor! > - Vue Pacer - needs a contributor! diff --git a/packages/pacer-lite/README.md b/packages/pacer-lite/README.md index 42347dcc..5a42510f 100644 --- a/packages/pacer-lite/README.md +++ b/packages/pacer-lite/README.md @@ -89,9 +89,9 @@ A lightweight timing and scheduling library for debouncing, throttling, rate lim > You may know **TanSack Pacer** by our adapter names, too! > > - [**React Pacer**](https://tanstack.com/pacer/latest/docs/framework/react/react-pacer) +> - [**Preact Pacer**](https://tanstack.com/pacer/latest/docs/framework/preact/preact-pacer) > - [**Solid Pacer**](https://tanstack.com/pacer/latest/docs/framework/solid/solid-pacer) > - Angular Pacer - needs a contributor! -> - Preact Pacer - Coming soon! (After React Pacer is more fleshed out) > - Svelte Pacer - needs a contributor! > - Vue Pacer - needs a contributor! diff --git a/packages/pacer/README.md b/packages/pacer/README.md index 42347dcc..5a42510f 100644 --- a/packages/pacer/README.md +++ b/packages/pacer/README.md @@ -89,9 +89,9 @@ A lightweight timing and scheduling library for debouncing, throttling, rate lim > You may know **TanSack Pacer** by our adapter names, too! > > - [**React Pacer**](https://tanstack.com/pacer/latest/docs/framework/react/react-pacer) +> - [**Preact Pacer**](https://tanstack.com/pacer/latest/docs/framework/preact/preact-pacer) > - [**Solid Pacer**](https://tanstack.com/pacer/latest/docs/framework/solid/solid-pacer) > - Angular Pacer - needs a contributor! -> - Preact Pacer - Coming soon! (After React Pacer is more fleshed out) > - Svelte Pacer - needs a contributor! > - Vue Pacer - needs a contributor! diff --git a/packages/preact-pacer-devtools/README.md b/packages/preact-pacer-devtools/README.md new file mode 100644 index 00000000..5a42510f --- /dev/null +++ b/packages/preact-pacer-devtools/README.md @@ -0,0 +1,165 @@ +
+ +
+ +
+ + + + + +
+ +### [Become a Sponsor!](https://github.com/sponsors/tannerlinsley/) +
+ +# TanStack Pacer + +A lightweight timing and scheduling library for debouncing, throttling, rate limiting, queuing, and batching. + +> [!NOTE] +> TanStack Pacer is currently mostly a client-side only library, but it is being designed to be able to potentially be used on the server-side as well. + +- **Debouncing** + - Delay execution until after a period of inactivity for when you only care about the last execution in a sequence. + - Synchronous or Asynchronous Debounce utilities with promise support and error handling + - Control of leading, trailing, and enabled options +- **Throttling** + - Smoothly limit the rate at which a function can fire + - Synchronous or Asynchronous Throttle utilities with promise support and error handling + - Control of leading, trailing, and enabled options. +- **Rate Limiting** + - Limit the rate at which a function can fire over a period of time + - Synchronous or Asynchronous Rate Limiting utilities with promise support and error handling + - Fixed or Sliding Window variations of Rate Limiting +- **Queuing** + - Queue functions to be executed in a specific order + - Choose from FIFO, LIFO, and Priority queue implementations + - Control processing speed with configurable wait times or concurrency limits + - Manage queue execution with start/stop capabilities + - Expire items from the queue after a configurable duration +- **Batching** + - Chunk up multiple operations into larger batches to reduce total back-and-forth operations + - Batch by time period, batch size, whichever comes first, or a custom condition to trigger batch executions +- **Async or Sync Variations** + - Choose between synchronous and asynchronous versions of each utility + - Optional error, success, and settled handling for async variations + - Retry and Abort support for async variations +- **State Management** + - Uses TanStack Store under the hood for state management with fine-grained reactivity + - Easily integrate with your own state management library of choice + - Persist state to local or session storage for some utilities like rate limiting and queuing +- **Convenient Hooks** + - Reduce boilerplate code with pre-built hooks like `useDebouncedCallback`, `useThrottledValue`, and `useQueuedState`, and more. + - Multiple layers of abstraction to choose from depending on your use case. + - Works with each framework's default state management solutions, or with whatever custom state management library that you prefer. +- **Type Safety** + - Full type safety with TypeScript that makes sure that your functions will always be called with the correct arguments + - Generics for flexible and reusable utilities +- **Framework Adapters** + - React, Solid, and more +- **Tree Shaking** + - We, of course, get tree-shaking right for your applications by default, but we also provide extra deep imports for each utility, making it easier to embed these utilities into your libraries without increasing the bundle-phobia reports of your library. + +### Read the docs → + +
+ +> [!NOTE] +> You may know **TanSack Pacer** by our adapter names, too! +> +> - [**React Pacer**](https://tanstack.com/pacer/latest/docs/framework/react/react-pacer) +> - [**Preact Pacer**](https://tanstack.com/pacer/latest/docs/framework/preact/preact-pacer) +> - [**Solid Pacer**](https://tanstack.com/pacer/latest/docs/framework/solid/solid-pacer) +> - Angular Pacer - needs a contributor! +> - Svelte Pacer - needs a contributor! +> - Vue Pacer - needs a contributor! + +## Get Involved + +- We welcome issues and pull requests! +- Participate in [GitHub discussions](https://github.com/TanStack/pacer/discussions) +- Chat with the community on [Discord](https://discord.com/invite/WrRKjPJ) +- See [CONTRIBUTING.md](./CONTRIBUTING.md) for setup instructions + +## Partners + + + + + + + +
+ + + + + CodeRabbit + + + + + + + + Cloudflare + + + + + + + + Unkey + + +
+ +
+Pacer & you? +

+We're looking for TanStack Pacer Partners to join our mission! Partner with us to push the boundaries of TanStack Pacer and build amazing things together. +

+LET'S CHAT +
+ + + +## Explore the TanStack Ecosystem + +- TanStack Config – Tooling for JS/TS packages +- TanStack DB – Reactive sync client store +- TanStack DevTools – Unified devtools panel +- TanStack Form – Type‑safe form state +- TanStack Query – Async state & caching +- TanStack Ranger – Range & slider primitives +- TanStack Router – Type‑safe routing, caching & URL state +- TanStack Start – Full‑stack SSR & streaming +- TanStack Store – Reactive data store +- TanStack Table – Headless datagrids +- TanStack Virtual – Virtualized rendering + +… and more at TanStack.com » + + diff --git a/packages/preact-pacer-devtools/eslint.config.js b/packages/preact-pacer-devtools/eslint.config.js new file mode 100644 index 00000000..c61c24df --- /dev/null +++ b/packages/preact-pacer-devtools/eslint.config.js @@ -0,0 +1,11 @@ +// @ts-check + +import rootConfig from '../../eslint.config.js' + +/** @type {import('eslint').Linter.Config[]} */ +export default [ + ...rootConfig, + { + rules: {}, + }, +] diff --git a/packages/preact-pacer-devtools/package.json b/packages/preact-pacer-devtools/package.json new file mode 100644 index 00000000..414b7c88 --- /dev/null +++ b/packages/preact-pacer-devtools/package.json @@ -0,0 +1,65 @@ +{ + "name": "@tanstack/preact-pacer-devtools", + "version": "0.4.0", + "description": "Preact adapter for devtools for Pacer.", + "author": "Tanner Linsley", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/TanStack/pacer.git", + "directory": "packages/pacer" + }, + "homepage": "https://tanstack.com/pacer", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + }, + "keywords": [ + "preact", + "debounce", + "throttle", + "rate-limit", + "queuer", + "queue", + "pacer" + ], + "type": "module", + "types": "./dist/index.d.ts", + "module": "./dist/index.js", + "exports": { + ".": "./dist/index.js", + "./production": "./dist/production.js", + "./package.json": "./package.json" + }, + "sideEffects": false, + "engines": { + "node": ">=18" + }, + "files": [ + "dist/", + "src" + ], + "scripts": { + "clean": "premove ./build ./dist", + "lint:fix": "eslint ./src --fix", + "test:eslint": "eslint ./src", + "test:lib": "vitest", + "test:lib:dev": "pnpm test:lib --watch", + "test:types": "tsc", + "test:build": "publint --strict", + "build": "tsdown" + }, + "peerDependencies": { + "preact": ">=10.0.0" + }, + "dependencies": { + "@tanstack/devtools-utils": "^0.1.0", + "@tanstack/pacer-devtools": "workspace:*" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "@testing-library/preact": "^3.2.4", + "preact": "^10.28.0" + }, + "main": "./dist/index.js" +} diff --git a/packages/preact-pacer-devtools/src/PreactPacerDevtools.tsx b/packages/preact-pacer-devtools/src/PreactPacerDevtools.tsx new file mode 100644 index 00000000..2444d02a --- /dev/null +++ b/packages/preact-pacer-devtools/src/PreactPacerDevtools.tsx @@ -0,0 +1,10 @@ +import { createPreactPanel } from '@tanstack/devtools-utils/preact' +import { PacerDevtoolsCore } from '@tanstack/pacer-devtools' +import type { DevtoolsPanelProps } from '@tanstack/devtools-utils/preact' + +export interface PacerDevtoolsPreactInit extends DevtoolsPanelProps {} + +const [PacerDevtoolsPanel, PacerDevtoolsPanelNoOp] = + createPreactPanel(PacerDevtoolsCore) + +export { PacerDevtoolsPanel, PacerDevtoolsPanelNoOp } diff --git a/packages/preact-pacer-devtools/src/index.ts b/packages/preact-pacer-devtools/src/index.ts new file mode 100644 index 00000000..a0017d8e --- /dev/null +++ b/packages/preact-pacer-devtools/src/index.ts @@ -0,0 +1,16 @@ +'use client' + +import * as Devtools from './PreactPacerDevtools' +import * as plugin from './plugin' + +export const PacerDevtoolsPanel = + process.env.NODE_ENV !== 'development' + ? Devtools.PacerDevtoolsPanelNoOp + : Devtools.PacerDevtoolsPanel + +export const pacerDevtoolsPlugin = + process.env.NODE_ENV !== 'development' + ? plugin.pacerDevtoolsNoOpPlugin + : plugin.pacerDevtoolsPlugin + +export type { PacerDevtoolsPreactInit } from './PreactPacerDevtools' diff --git a/packages/preact-pacer-devtools/src/plugin.tsx b/packages/preact-pacer-devtools/src/plugin.tsx new file mode 100644 index 00000000..3a4d186c --- /dev/null +++ b/packages/preact-pacer-devtools/src/plugin.tsx @@ -0,0 +1,9 @@ +import { createPreactPlugin } from '@tanstack/devtools-utils/preact' +import { PacerDevtoolsPanel } from './PreactPacerDevtools' + +const [pacerDevtoolsPlugin, pacerDevtoolsNoOpPlugin] = createPreactPlugin({ + name: 'TanStack Pacer', + Component: PacerDevtoolsPanel, +}) + +export { pacerDevtoolsPlugin, pacerDevtoolsNoOpPlugin } diff --git a/packages/preact-pacer-devtools/src/production.ts b/packages/preact-pacer-devtools/src/production.ts new file mode 100644 index 00000000..54beedc0 --- /dev/null +++ b/packages/preact-pacer-devtools/src/production.ts @@ -0,0 +1,7 @@ +'use client' + +export { PacerDevtoolsPanel } from './PreactPacerDevtools' + +export type { PacerDevtoolsPreactInit } from './PreactPacerDevtools' + +export { pacerDevtoolsPlugin } from './plugin' diff --git a/packages/preact-pacer-devtools/tests/index.test.ts b/packages/preact-pacer-devtools/tests/index.test.ts new file mode 100644 index 00000000..7be68cd7 --- /dev/null +++ b/packages/preact-pacer-devtools/tests/index.test.ts @@ -0,0 +1,7 @@ +import { describe, it, expect } from 'vitest' + +describe('preact-pacer-devtools', () => { + it('should export pacerDevtoolsPlugin', () => { + expect(true).toBe(true) + }) +}) diff --git a/packages/preact-pacer-devtools/tests/test-setup.ts b/packages/preact-pacer-devtools/tests/test-setup.ts new file mode 100644 index 00000000..8fc6d383 --- /dev/null +++ b/packages/preact-pacer-devtools/tests/test-setup.ts @@ -0,0 +1,9 @@ +import { expect, afterEach } from 'vitest' +import { cleanup } from '@testing-library/preact' +import * as matchers from '@testing-library/jest-dom/matchers' + +expect.extend(matchers) + +afterEach(() => { + cleanup() +}) diff --git a/packages/preact-pacer-devtools/tsconfig.json b/packages/preact-pacer-devtools/tsconfig.json new file mode 100644 index 00000000..f233899b --- /dev/null +++ b/packages/preact-pacer-devtools/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src", "vite.config.ts", "tests"], + "exclude": ["eslint.config.js"], + "compilerOptions": { + "jsx": "react-jsx", + "jsxImportSource": "preact" + } +} diff --git a/packages/preact-pacer-devtools/tsdown.config.ts b/packages/preact-pacer-devtools/tsdown.config.ts new file mode 100644 index 00000000..829205a1 --- /dev/null +++ b/packages/preact-pacer-devtools/tsdown.config.ts @@ -0,0 +1,18 @@ +import { defineConfig } from 'tsdown' +import preact from '@preact/preset-vite' + +export default defineConfig({ + plugins: [preact()], + entry: ['./src/index.ts', './src/production.ts'], + format: ['esm'], + unbundle: true, + dts: true, + sourcemap: true, + clean: true, + minify: false, + fixedExtension: false, + exports: true, + publint: { + strict: true, + }, +}) diff --git a/packages/preact-pacer-devtools/vitest.config.ts b/packages/preact-pacer-devtools/vitest.config.ts new file mode 100644 index 00000000..4ec3f84a --- /dev/null +++ b/packages/preact-pacer-devtools/vitest.config.ts @@ -0,0 +1,15 @@ +import { defineConfig } from 'vitest/config' +import preact from '@preact/preset-vite' +import packageJson from './package.json' with { type: 'json' } + +export default defineConfig({ + plugins: [preact()], + test: { + name: packageJson.name, + dir: './', + watch: false, + environment: 'happy-dom', + setupFiles: ['./tests/test-setup.ts'], + globals: true, + }, +}) diff --git a/packages/preact-pacer/CHANGELOG.md b/packages/preact-pacer/CHANGELOG.md new file mode 100644 index 00000000..cb1ec2f9 --- /dev/null +++ b/packages/preact-pacer/CHANGELOG.md @@ -0,0 +1 @@ +# @tanstack/preact-pacer diff --git a/packages/preact-pacer/README.md b/packages/preact-pacer/README.md new file mode 100644 index 00000000..8192960c --- /dev/null +++ b/packages/preact-pacer/README.md @@ -0,0 +1,165 @@ +
+ +
+ +
+ + + + + +
+ +### [Become a Sponsor!](https://github.com/sponsors/tannerlinsley/) +
+ +# TanStack Pacer + +A lightweight timing and scheduling library for debouncing, throttling, rate limiting, queuing, and batching. + +> [!NOTE] +> TanStack Pacer is currently mostly a client-side only library, but it is being designed to be able to potentially be used on the server-side as well. + +- **Debouncing** + - Delay execution until after a period of inactivity for when you only care about the last execution in a sequence. + - Synchronous or Asynchronous Debounce utilities with promise support and error handling + - Control of leading, trailing, and enabled options +- **Throttling** + - Smoothly limit the rate at which a function can fire + - Synchronous or Asynchronous Throttle utilities with promise support and error handling + - Control of leading, trailing, and enabled options. +- **Rate Limiting** + - Limit the rate at which a function can fire over a period of time + - Synchronous or Asynchronous Rate Limiting utilities with promise support and error handling + - Fixed or Sliding Window variations of Rate Limiting +- **Queuing** + - Queue functions to be executed in a specific order + - Choose from FIFO, LIFO, and Priority queue implementations + - Control processing speed with configurable wait times or concurrency limits + - Manage queue execution with start/stop capabilities + - Expire items from the queue after a configurable duration +- **Batching** + - Chunk up multiple operations into larger batches to reduce total back-and-forth operations + - Batch by time period, batch size, whichever comes first, or a custom condition to trigger batch executions +- **Async or Sync Variations** + - Choose between synchronous and asynchronous versions of each utility + - Optional error, success, and settled handling for async variations + - Retry and Abort support for async variations +- **State Management** + - Uses TanStack Store under the hood for state management with fine-grained reactivity + - Easily integrate with your own state management library of choice + - Persist state to local or session storage for some utilities like rate limiting and queuing +- **Convenient Hooks** + - Reduce boilerplate code with pre-built hooks like `useDebouncedCallback`, `useThrottledValue`, and `useQueuedState`, and more. + - Multiple layers of abstraction to choose from depending on your use case. + - Works with each framework's default state management solutions, or with whatever custom state management library that you prefer. +- **Type Safety** + - Full type safety with TypeScript that makes sure that your functions will always be called with the correct arguments + - Generics for flexible and reusable utilities +- **Framework Adapters** + - React, Solid, and more +- **Tree Shaking** + - We, of course, get tree-shaking right for your applications by default, but we also provide extra deep imports for each utility, making it easier to embed these utilities into your libraries without increasing the bundle-phobia reports of your library. + +### Read the docs → + +
+ +> [!NOTE] +> You may know **TanSack Pacer** by our adapter names, too! +> +> - [**React Pacer**](https://tanstack.com/pacer/latest/docs/framework/react/react-pacer) +> - [**Solid Pacer**](https://tanstack.com/pacer/latest/docs/framework/solid/solid-pacer) +> - Angular Pacer - needs a contributor! +> - Preact Pacer - Coming soon! (After React Pacer is more fleshed out) +> - Svelte Pacer - needs a contributor! +> - Vue Pacer - needs a contributor! + +## Get Involved + +- We welcome issues and pull requests! +- Participate in [GitHub discussions](https://github.com/TanStack/pacer/discussions) +- Chat with the community on [Discord](https://discord.com/invite/WrRKjPJ) +- See [CONTRIBUTING.md](./CONTRIBUTING.md) for setup instructions + +## Partners + + + + + + + +
+ + + + + CodeRabbit + + + + + + + + Cloudflare + + + + + + + + Unkey + + +
+ +
+Pacer & you? +

+We're looking for TanStack Pacer Partners to join our mission! Partner with us to push the boundaries of TanStack Pacer and build amazing things together. +

+LET'S CHAT +
+ + + +## Explore the TanStack Ecosystem + +- TanStack Config – Tooling for JS/TS packages +- TanStack DB – Reactive sync client store +- TanStack DevTools – Unified devtools panel +- TanStack Form – Type‑safe form state +- TanStack Query – Async state & caching +- TanStack Ranger – Range & slider primitives +- TanStack Router – Type‑safe routing, caching & URL state +- TanStack Start – Full‑stack SSR & streaming +- TanStack Store – Reactive data store +- TanStack Table – Headless datagrids +- TanStack Virtual – Virtualized rendering + +… and more at TanStack.com » + + diff --git a/packages/preact-pacer/eslint.config.js b/packages/preact-pacer/eslint.config.js new file mode 100644 index 00000000..8f561f82 --- /dev/null +++ b/packages/preact-pacer/eslint.config.js @@ -0,0 +1,18 @@ +// @ts-check + +import pluginReactHooks from 'eslint-plugin-react-hooks' +import rootConfig from '../../eslint.config.js' + +/** @type {import('eslint').Linter.Config[]} */ +export default [ + ...rootConfig, + { + plugins: { + 'react-hooks': pluginReactHooks, + }, + rules: { + 'react-hooks/exhaustive-deps': 'error', + 'react-hooks/rules-of-hooks': 'error', + }, + }, +] diff --git a/packages/preact-pacer/package.json b/packages/preact-pacer/package.json new file mode 100644 index 00000000..f814872c --- /dev/null +++ b/packages/preact-pacer/package.json @@ -0,0 +1,121 @@ +{ + "name": "@tanstack/preact-pacer", + "version": "0.17.3", + "description": "Utilities for debouncing and throttling functions in Preact.", + "author": "Tanner Linsley", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/TanStack/pacer.git", + "directory": "packages/preact-pacer" + }, + "homepage": "https://tanstack.com/pacer", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + }, + "keywords": [ + "preact", + "debounce", + "throttle", + "rate-limit", + "queue", + "async" + ], + "type": "module", + "types": "./dist/index.d.cts", + "main": "./dist/index.cjs", + "module": "./dist/index.js", + "exports": { + ".": { + "require": "./dist/index.cjs", + "import": "./dist/index.js" + }, + "./async-batcher": { + "require": "./dist/async-batcher/index.cjs", + "import": "./dist/async-batcher/index.js" + }, + "./async-debouncer": { + "require": "./dist/async-debouncer/index.cjs", + "import": "./dist/async-debouncer/index.js" + }, + "./async-queuer": { + "require": "./dist/async-queuer/index.cjs", + "import": "./dist/async-queuer/index.js" + }, + "./async-rate-limiter": { + "require": "./dist/async-rate-limiter/index.cjs", + "import": "./dist/async-rate-limiter/index.js" + }, + "./async-retryer": { + "require": "./dist/async-retryer/index.cjs", + "import": "./dist/async-retryer/index.js" + }, + "./async-throttler": { + "require": "./dist/async-throttler/index.cjs", + "import": "./dist/async-throttler/index.js" + }, + "./batcher": { + "require": "./dist/batcher/index.cjs", + "import": "./dist/batcher/index.js" + }, + "./debouncer": { + "require": "./dist/debouncer/index.cjs", + "import": "./dist/debouncer/index.js" + }, + "./provider": { + "require": "./dist/provider/index.cjs", + "import": "./dist/provider/index.js" + }, + "./queuer": { + "require": "./dist/queuer/index.cjs", + "import": "./dist/queuer/index.js" + }, + "./rate-limiter": { + "require": "./dist/rate-limiter/index.cjs", + "import": "./dist/rate-limiter/index.js" + }, + "./throttler": { + "require": "./dist/throttler/index.cjs", + "import": "./dist/throttler/index.js" + }, + "./types": { + "require": "./dist/types/index.cjs", + "import": "./dist/types/index.js" + }, + "./utils": { + "require": "./dist/utils/index.cjs", + "import": "./dist/utils/index.js" + }, + "./package.json": "./package.json" + }, + "sideEffects": false, + "engines": { + "node": ">=18" + }, + "files": [ + "dist", + "src" + ], + "scripts": { + "clean": "premove ./build ./dist", + "test:eslint": "eslint ./src", + "test:lib": "vitest --passWithNoTests", + "test:lib:dev": "pnpm test:lib --watch", + "test:types": "tsc", + "test:build": "publint --strict", + "build": "tsdown" + }, + "dependencies": { + "@tanstack/pacer": "workspace:*", + "@tanstack/preact-store": "^0.10.1" + }, + "devDependencies": { + "@preact/preset-vite": "^2.10.2", + "eslint-plugin-react-hooks": "^7.0.1", + "preact": "^10.28.0" + }, + "peerDependencies": { + "preact": ">=10.0.0" + } +} diff --git a/packages/preact-pacer/src/async-batcher/index.ts b/packages/preact-pacer/src/async-batcher/index.ts new file mode 100644 index 00000000..71e04b3c --- /dev/null +++ b/packages/preact-pacer/src/async-batcher/index.ts @@ -0,0 +1,4 @@ +export * from '@tanstack/pacer/async-batcher' + +export * from './useAsyncBatcher' +export * from './useAsyncBatchedCallback' diff --git a/packages/preact-pacer/src/async-batcher/useAsyncBatchedCallback.ts b/packages/preact-pacer/src/async-batcher/useAsyncBatchedCallback.ts new file mode 100644 index 00000000..990d5e4e --- /dev/null +++ b/packages/preact-pacer/src/async-batcher/useAsyncBatchedCallback.ts @@ -0,0 +1,54 @@ +import { useCallback } from 'preact/hooks' +import { useAsyncBatcher } from './useAsyncBatcher' +import type { AsyncBatcherOptions } from '@tanstack/pacer/async-batcher' +import type { AnyAsyncFunction } from '@tanstack/pacer/types' + +/** + * A Preact hook that creates a batched version of an async callback function. + * This hook is a convenient wrapper around the `useAsyncBatcher` hook, + * providing a stable, batched async function reference for use in Preact components. + * + * The batched async function will collect individual calls into batches and execute them + * when batch conditions are met (max size reached, wait time elapsed, or custom logic). + * The returned function always returns a promise that resolves with undefined (since the + * batch function processes multiple items together). + * + * This hook provides a simpler API compared to `useAsyncBatcher`, making it ideal for basic + * async batching needs. However, it does not expose the underlying AsyncBatcher instance. + * + * For advanced usage requiring features like: + * - Manual batch execution + * - Access to batch results and state + * - Custom useCallback dependencies + * + * Consider using the `useAsyncBatcher` hook instead. + * + * @example + * ```tsx + * // Batch API requests + * const batchApiCall = useAsyncBatchedCallback(async (requests: ApiRequest[]) => { + * const results = await Promise.all(requests.map(req => fetch(req.url))); + * return results.map(res => res.json()); + * }, { + * maxSize: 10, // Process when 10 requests collected + * wait: 1000 // Or after 1 second + * }); + * + * // Use in event handlers + * + * ``` + */ +export function useAsyncBatchedCallback( + fn: (items: Array[0]>) => Promise, + options: AsyncBatcherOptions[0]>, +): (...args: Parameters) => Promise { + const asyncBatchedFn = useAsyncBatcher(fn, options).addItem + return useCallback( + async (...args: Parameters) => { + asyncBatchedFn(args[0]) + }, + [asyncBatchedFn], + ) +} diff --git a/packages/preact-pacer/src/async-batcher/useAsyncBatcher.ts b/packages/preact-pacer/src/async-batcher/useAsyncBatcher.ts new file mode 100644 index 00000000..a9d76ec8 --- /dev/null +++ b/packages/preact-pacer/src/async-batcher/useAsyncBatcher.ts @@ -0,0 +1,198 @@ +import { useMemo, useState } from 'preact/hooks' +import { AsyncBatcher } from '@tanstack/pacer/async-batcher' +import { useStore } from '@tanstack/preact-store' +import { useDefaultPacerOptions } from '../provider/PacerProvider' +import type { Store } from '@tanstack/preact-store' +import type { + AsyncBatcherOptions, + AsyncBatcherState, +} from '@tanstack/pacer/async-batcher' + +export interface ReactAsyncBatcher extends Omit< + AsyncBatcher, + 'store' +> { + /** + * Reactive state that will be updated and re-rendered when the batcher state changes + * + * Use this instead of `batcher.store.state` + */ + readonly state: Readonly + /** + * @deprecated Use `batcher.state` instead of `batcher.store.state` if you want to read reactive state. + * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally. + * Although, you can make the state reactive by using the `useStore` in your own usage. + */ + readonly store: Store>> +} + +/** + * A Preact hook that creates an `AsyncBatcher` instance for managing asynchronous batches of items. + * + * This is the async version of the useBatcher hook. Unlike the sync version, this async batcher: + * - Handles promises and returns results from batch executions + * - Provides error handling with configurable error behavior + * - Tracks success, error, and settle counts separately + * - Has state tracking for when batches are executing + * - Returns the result of the batch function execution + * + * Features: + * - Configurable batch size and wait time + * - Custom batch processing logic via getShouldExecute + * - Event callbacks for monitoring batch operations + * - Error handling for failed batch operations + * - Automatic or manual batch processing + * + * The batcher collects items and processes them in batches based on: + * - Maximum batch size (number of items per batch) + * - Time-based batching (process after X milliseconds) + * - Custom batch processing logic via getShouldExecute + * + * Error Handling: + * - If an `onError` handler is provided, it will be called with the error and batcher instance + * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown + * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed + * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown + * - The error state can be checked using the underlying AsyncBatcher instance + * + * ## State Management and Selector + * + * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you + * to specify which state changes will trigger a re-render, optimizing performance by preventing + * unnecessary re-renders when irrelevant state changes occur. + * + * **By default, there will be no reactive state subscriptions** and you must opt-in to state + * tracking by providing a selector function. This prevents unnecessary re-renders and gives you + * full control over when your component updates. Only when you provide a selector will the + * component re-render when the selected state values change. + * + * Available state properties: + * - `errorCount`: Number of batch executions that have resulted in errors + * - `failedItems`: Array of items that failed during batch processing + * - `isEmpty`: Whether the batcher has no items to process + * - `isExecuting`: Whether a batch is currently being processed asynchronously + * - `isPending`: Whether the batcher is waiting for the timeout to trigger batch processing + * - `isRunning`: Whether the batcher is active and will process items automatically + * - `items`: Array of items currently queued for batch processing + * - `lastResult`: The result from the most recent batch execution + * - `settleCount`: Number of batch executions that have completed (success or error) + * - `size`: Number of items currently in the batch queue + * - `status`: Current processing status ('idle' | 'pending' | 'executing' | 'populated') + * - `successCount`: Number of batch executions that have completed successfully + * - `totalItemsProcessed`: Total number of items processed across all batches + * - `totalItemsFailed`: Total number of items that have failed processing + * + * @example + * ```tsx + * // Basic async batcher for API requests - no reactive state subscriptions + * const asyncBatcher = useAsyncBatcher( + * async (items) => { + * const results = await Promise.all(items.map(item => processItem(item))); + * return results; + * }, + * { maxSize: 10, wait: 2000 } + * ); + * + * // Opt-in to re-render when execution state changes (optimized for loading indicators) + * const asyncBatcher = useAsyncBatcher( + * async (items) => { + * const results = await Promise.all(items.map(item => processItem(item))); + * return results; + * }, + * { maxSize: 10, wait: 2000 }, + * (state) => ({ + * isExecuting: state.isExecuting, + * isPending: state.isPending, + * status: state.status + * }) + * ); + * + * // Opt-in to re-render when results are available (optimized for data display) + * const asyncBatcher = useAsyncBatcher( + * async (items) => { + * const results = await Promise.all(items.map(item => processItem(item))); + * return results; + * }, + * { maxSize: 10, wait: 2000 }, + * (state) => ({ + * lastResult: state.lastResult, + * successCount: state.successCount, + * totalItemsProcessed: state.totalItemsProcessed + * }) + * ); + * + * // Opt-in to re-render when error state changes (optimized for error handling) + * const asyncBatcher = useAsyncBatcher( + * async (items) => { + * const results = await Promise.all(items.map(item => processItem(item))); + * return results; + * }, + * { + * maxSize: 10, + * wait: 2000, + * onError: (error) => console.error('Batch processing failed:', error) + * }, + * (state) => ({ + * errorCount: state.errorCount, + * failedItems: state.failedItems, + * totalItemsFailed: state.totalItemsFailed + * }) + * ); + * + * // Complete example with all callbacks + * const asyncBatcher = useAsyncBatcher( + * async (items) => { + * const results = await Promise.all(items.map(item => processItem(item))); + * return results; + * }, + * { + * maxSize: 10, + * wait: 2000, + * onSuccess: (result) => { + * console.log('Batch processed successfully:', result); + * }, + * onError: (error) => { + * console.error('Batch processing failed:', error); + * } + * } + * ); + * + * // Add items to batch + * asyncBatcher.addItem(newItem); + * + * // Manually execute batch + * const result = await asyncBatcher.execute(); + * + * // Access the selected state (will be empty object {} unless selector provided) + * const { isExecuting, lastResult, size } = asyncBatcher.state; + * ``` + */ +export function useAsyncBatcher( + fn: (items: Array) => Promise, + options: AsyncBatcherOptions = {}, + selector: (state: AsyncBatcherState) => TSelected = () => + ({}) as TSelected, +): ReactAsyncBatcher { + const mergedOptions = { + ...useDefaultPacerOptions().asyncBatcher, + ...options, + } as AsyncBatcherOptions + + const [asyncBatcher] = useState( + () => new AsyncBatcher(fn, mergedOptions), + ) + + asyncBatcher.fn = fn + asyncBatcher.setOptions(mergedOptions) + + const state = useStore(asyncBatcher.store, selector) + + return useMemo( + () => + ({ + ...asyncBatcher, + state, + }) as ReactAsyncBatcher, // omit `store` in favor of `state` + [asyncBatcher, state], + ) +} diff --git a/packages/preact-pacer/src/async-debouncer/index.ts b/packages/preact-pacer/src/async-debouncer/index.ts new file mode 100644 index 00000000..ac389c84 --- /dev/null +++ b/packages/preact-pacer/src/async-debouncer/index.ts @@ -0,0 +1,5 @@ +// re-export everything from the core pacer package, BUT ONLY from the async-debouncer module +export * from '@tanstack/pacer/async-debouncer' + +export * from './useAsyncDebouncer' +export * from './useAsyncDebouncedCallback' diff --git a/packages/preact-pacer/src/async-debouncer/useAsyncDebouncedCallback.ts b/packages/preact-pacer/src/async-debouncer/useAsyncDebouncedCallback.ts new file mode 100644 index 00000000..cfe65b63 --- /dev/null +++ b/packages/preact-pacer/src/async-debouncer/useAsyncDebouncedCallback.ts @@ -0,0 +1,54 @@ +import { useCallback } from 'preact/hooks' +import { useAsyncDebouncer } from './useAsyncDebouncer' +import type { AsyncDebouncerOptions } from '@tanstack/pacer/async-debouncer' +import type { AnyAsyncFunction } from '@tanstack/pacer/types' + +/** + * A Preact hook that creates a debounced version of an async callback function. + * This hook is a convenient wrapper around the `useAsyncDebouncer` hook, + * providing a stable, debounced async function reference for use in Preact components. + * + * The debounced async function will only execute after the specified wait time has elapsed + * since its last invocation. If called again before the wait time expires, the timer + * resets and starts waiting again. The returned function always returns a promise + * that resolves or rejects with the result of the original async function. + * + * This hook provides a simpler API compared to `useAsyncDebouncer`, making it ideal for basic + * async debouncing needs. However, it does not expose the underlying AsyncDebouncer instance. + * + * For advanced usage requiring features like: + * - Manual cancellation + * - Access to execution/error state + * - Custom useCallback dependencies + * + * Consider using the `useAsyncDebouncer` hook instead. + * + * + * @example + * ```tsx + * // Debounce an async search handler + * const handleSearch = useAsyncDebouncedCallback(async (query: string) => { + * const results = await fetchSearchResults(query); + * return results; + * }, { + * wait: 500 // Wait 500ms between executions + * }); + * + * // Use in an input + * handleSearch(e.target.value)} + * /> + * ``` + */ +export function useAsyncDebouncedCallback( + fn: TFn, + options: AsyncDebouncerOptions, +): (...args: Parameters) => Promise> { + const asyncDebouncedFn = useAsyncDebouncer(fn, options).maybeExecute + return useCallback( + (...args: Parameters) => + asyncDebouncedFn(...args) as Promise>, + [asyncDebouncedFn], + ) +} diff --git a/packages/preact-pacer/src/async-debouncer/useAsyncDebouncer.ts b/packages/preact-pacer/src/async-debouncer/useAsyncDebouncer.ts new file mode 100644 index 00000000..963d177b --- /dev/null +++ b/packages/preact-pacer/src/async-debouncer/useAsyncDebouncer.ts @@ -0,0 +1,184 @@ +import { useEffect, useMemo, useState } from 'preact/hooks' +import { AsyncDebouncer } from '@tanstack/pacer/async-debouncer' +import { useStore } from '@tanstack/preact-store' +import { useDefaultPacerOptions } from '../provider/PacerProvider' +import type { Store } from '@tanstack/preact-store' +import type { AnyAsyncFunction } from '@tanstack/pacer/types' +import type { + AsyncDebouncerOptions, + AsyncDebouncerState, +} from '@tanstack/pacer/async-debouncer' + +export interface ReactAsyncDebouncer< + TFn extends AnyAsyncFunction, + TSelected = {}, +> extends Omit, 'store'> { + /** + * Reactive state that will be updated and re-rendered when the debouncer state changes + * + * Use this instead of `debouncer.store.state` + */ + readonly state: Readonly + /** + * @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state. + * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally. + * Although, you can make the state reactive by using the `useStore` in your own usage. + */ + readonly store: Store>> +} + +/** + * A low-level Preact hook that creates an `AsyncDebouncer` instance to delay execution of an async function. + * + * This hook is designed to be flexible and state-management agnostic - it simply returns a debouncer instance that + * you can integrate with any state management solution (useState, Redux, Zustand, Jotai, etc). + * + * Async debouncing ensures that an async function only executes after a specified delay has passed since its last invocation. + * Each new invocation resets the delay timer. This is useful for handling frequent events like window resizing + * or input changes where you only want to execute the handler after the events have stopped occurring. + * + * Unlike throttling which allows execution at regular intervals, debouncing prevents any execution until + * the function stops being called for the specified delay period. + * + * Unlike the non-async Debouncer, this async version supports returning values from the debounced function, + * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call + * instead of setting the result on a state variable from within the debounced function. + * + * Error Handling: + * - If an `onError` handler is provided, it will be called with the error and debouncer instance + * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown + * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed + * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown + * - The error state can be checked using the underlying AsyncDebouncer instance + * + * ## State Management and Selector + * + * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you + * to specify which state changes will trigger a re-render, optimizing performance by preventing + * unnecessary re-renders when irrelevant state changes occur. + * + * **By default, there will be no reactive state subscriptions** and you must opt-in to state + * tracking by providing a selector function. This prevents unnecessary re-renders and gives you + * full control over when your component updates. Only when you provide a selector will the + * component re-render when the selected state values change. + * + * Available state properties: + * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge + * - `errorCount`: Number of function executions that have resulted in errors + * - `isExecuting`: Whether the debounced function is currently executing asynchronously + * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution + * - `lastArgs`: The arguments from the most recent call to maybeExecute + * - `lastResult`: The result from the most recent successful function execution + * - `settleCount`: Number of function executions that have completed (success or error) + * - `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing' | 'settled') + * - `successCount`: Number of function executions that have completed successfully + * + * @example + * ```tsx + * // Default behavior - no reactive state subscriptions + * const searchDebouncer = useAsyncDebouncer( + * async (query: string) => { + * const results = await api.search(query); + * return results; + * }, + * { wait: 500 } + * ); + * + * // Opt-in to re-render when execution state changes (optimized for loading indicators) + * const searchDebouncer = useAsyncDebouncer( + * async (query: string) => { + * const results = await api.search(query); + * return results; + * }, + * { wait: 500 }, + * (state) => ({ + * isExecuting: state.isExecuting, + * isPending: state.isPending + * }) + * ); + * + * // Opt-in to re-render when results are available (optimized for data display) + * const searchDebouncer = useAsyncDebouncer( + * async (query: string) => { + * const results = await api.search(query); + * return results; + * }, + * { wait: 500 }, + * (state) => ({ + * lastResult: state.lastResult, + * successCount: state.successCount + * }) + * ); + * + * // Opt-in to re-render when error state changes (optimized for error handling) + * const searchDebouncer = useAsyncDebouncer( + * async (query: string) => { + * const results = await api.search(query); + * return results; + * }, + * { + * wait: 500, + * onError: (error) => console.error('Search failed:', error) + * }, + * (state) => ({ + * errorCount: state.errorCount, + * status: state.status + * }) + * ); + * + * // With state management + * const [results, setResults] = useState([]); + * const { maybeExecute, state } = useAsyncDebouncer( + * async (searchTerm) => { + * const data = await searchAPI(searchTerm); + * setResults(data); + * }, + * { + * wait: 300, + * leading: true, // Execute immediately on first call + * trailing: false, // Skip trailing edge updates + * onError: (error) => { + * console.error('API call failed:', error); + * } + * } + * ); + * + * // Access the selected state (will be empty object {} unless selector provided) + * const { isExecuting, lastResult } = state; + * ``` + */ +export function useAsyncDebouncer( + fn: TFn, + options: AsyncDebouncerOptions, + selector: (state: AsyncDebouncerState) => TSelected = () => + ({}) as TSelected, +): ReactAsyncDebouncer { + const mergedOptions = { + ...useDefaultPacerOptions().asyncDebouncer, + ...options, + } as AsyncDebouncerOptions + + const [asyncDebouncer] = useState( + () => new AsyncDebouncer(fn, mergedOptions), + ) + + asyncDebouncer.fn = fn + asyncDebouncer.setOptions(mergedOptions) + + const state = useStore(asyncDebouncer.store, selector) + + useEffect(() => { + return () => { + asyncDebouncer.cancel() + } + }, [asyncDebouncer]) + + return useMemo( + () => + ({ + ...asyncDebouncer, + state, + }) as ReactAsyncDebouncer, // omit `store` in favor of `state` + [asyncDebouncer, state], + ) +} diff --git a/packages/preact-pacer/src/async-queuer/index.ts b/packages/preact-pacer/src/async-queuer/index.ts new file mode 100644 index 00000000..aed55d49 --- /dev/null +++ b/packages/preact-pacer/src/async-queuer/index.ts @@ -0,0 +1,4 @@ +export * from '@tanstack/pacer/async-queuer' + +export * from './useAsyncQueuer' +export * from './useAsyncQueuedState' diff --git a/packages/preact-pacer/src/async-queuer/useAsyncQueuedState.ts b/packages/preact-pacer/src/async-queuer/useAsyncQueuedState.ts new file mode 100644 index 00000000..2a6574d0 --- /dev/null +++ b/packages/preact-pacer/src/async-queuer/useAsyncQueuedState.ts @@ -0,0 +1,165 @@ +import { useAsyncQueuer } from './useAsyncQueuer' +import type { ReactAsyncQueuer } from './useAsyncQueuer' +import type { + AsyncQueuerOptions, + AsyncQueuerState, +} from '@tanstack/pacer/async-queuer' + +/** + * A higher-level Preact hook that creates an `AsyncQueuer` instance with built-in state management. + * + * This hook combines an AsyncQueuer with Preact state to automatically track the queue items. + * It returns a tuple containing: + * - The current array of queued items as Preact state + * - The queuer instance with methods to control the queue + * + * The queue can be configured with: + * - Maximum concurrent operations + * - Maximum queue size + * - Processing function for queue items + * - Various lifecycle callbacks + * + * The state will automatically update whenever items are: + * - Added to the queue + * - Removed from the queue + * - Started processing + * - Completed processing + * + * ## State Management and Selector + * + * The hook uses TanStack Store for reactive state management via the underlying async queuer instance. + * The `selector` parameter allows you to specify which async queuer state changes will trigger a re-render, + * optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur. + * + * **By default, there will be no reactive state subscriptions** and you must opt-in to state + * tracking by providing a selector function. This prevents unnecessary re-renders and gives you + * full control over when your component updates. Only when you provide a selector will the + * component re-render when the selected state values change. + * + * Available async queuer state properties: + * - `activeItems`: Items currently being processed by the queuer + * - `errorCount`: Number of task executions that have resulted in errors + * - `expirationCount`: Number of items that have been removed due to expiration + * - `isEmpty`: Whether the queuer has no items to process + * - `isFull`: Whether the queuer has reached its maximum capacity + * - `isIdle`: Whether the queuer is not currently processing any items + * - `isRunning`: Whether the queuer is active and will process items automatically + * - `items`: Array of items currently waiting to be processed + * - `itemTimestamps`: Timestamps when items were added for expiration tracking + * - `lastResult`: The result from the most recent task execution + * - `pendingTick`: Whether the queuer has a pending timeout for processing the next item + * - `rejectionCount`: Number of items that have been rejected from being added + * - `settledCount`: Number of task executions that have completed (success or error) + * - `size`: Number of items currently in the queue + * - `status`: Current processing status ('idle' | 'running' | 'stopped') + * - `successCount`: Number of task executions that have completed successfully + * + * @example + * ```tsx + * // Default behavior - no reactive state subscriptions + * const [queueItems, asyncQueuer] = useAsyncQueuedState( + * async (item) => { + * const result = await processItem(item); + * return result; + * }, + * { + * concurrency: 2, + * maxSize: 100, + * started: true + * } + * ); + * + * // Opt-in to re-render when queue contents change (optimized for displaying queue items) + * const [queueItems, asyncQueuer] = useAsyncQueuedState( + * async (item) => { + * const result = await processItem(item); + * return result; + * }, + * { concurrency: 2, maxSize: 100, started: true }, + * (state) => ({ + * items: state.items, + * size: state.size, + * isEmpty: state.isEmpty, + * isFull: state.isFull + * }) + * ); + * + * // Opt-in to re-render when processing state changes (optimized for loading indicators) + * const [queueItems, asyncQueuer] = useAsyncQueuedState( + * async (item) => { + * const result = await processItem(item); + * return result; + * }, + * { concurrency: 2, maxSize: 100, started: true }, + * (state) => ({ + * isRunning: state.isRunning, + * isIdle: state.isIdle, + * status: state.status, + * activeItems: state.activeItems, + * pendingTick: state.pendingTick + * }) + * ); + * + * // Opt-in to re-render when execution metrics change (optimized for stats display) + * const [queueItems, asyncQueuer] = useAsyncQueuedState( + * async (item) => { + * const result = await processItem(item); + * return result; + * }, + * { concurrency: 2, maxSize: 100, started: true }, + * (state) => ({ + * successCount: state.successCount, + * errorCount: state.errorCount, + * settledCount: state.settledCount, + * expirationCount: state.expirationCount, + * rejectionCount: state.rejectionCount + * }) + * ); + * + * // Opt-in to re-render when results are available (optimized for data display) + * const [queueItems, asyncQueuer] = useAsyncQueuedState( + * async (item) => { + * const result = await processItem(item); + * return result; + * }, + * { concurrency: 2, maxSize: 100, started: true }, + * (state) => ({ + * lastResult: state.lastResult, + * successCount: state.successCount + * }) + * ); + * + * // Add items to queue - state updates automatically + * asyncQueuer.addItem(async () => { + * const result = await fetchData(); + * return result; + * }); + * + * // Start processing + * asyncQueuer.start(); + * + * // Stop processing + * asyncQueuer.stop(); + * + * // queueItems reflects current queue state + * const pendingCount = asyncQueuer.peekPendingItems().length; + * + * // Access the selected async queuer state (will be empty object {} unless selector provided) + * const { size, isRunning, activeItems } = asyncQueuer.state; + * ``` + */ +export function useAsyncQueuedState< + TValue, + TSelected extends Pick, 'items'> = Pick< + AsyncQueuerState, + 'items' + >, +>( + fn: (value: TValue) => Promise, + options: AsyncQueuerOptions = {}, + selector?: (state: AsyncQueuerState) => TSelected, +): [Array, ReactAsyncQueuer] { + const asyncQueuer = useAsyncQueuer(fn, options, selector) + + return [asyncQueuer.state.items, asyncQueuer] +} diff --git a/packages/preact-pacer/src/async-queuer/useAsyncQueuer.ts b/packages/preact-pacer/src/async-queuer/useAsyncQueuer.ts new file mode 100644 index 00000000..6008d816 --- /dev/null +++ b/packages/preact-pacer/src/async-queuer/useAsyncQueuer.ts @@ -0,0 +1,198 @@ +import { useMemo, useState } from 'preact/hooks' +import { AsyncQueuer } from '@tanstack/pacer/async-queuer' +import { useStore } from '@tanstack/preact-store' +import { useDefaultPacerOptions } from '../provider/PacerProvider' +import type { Store } from '@tanstack/preact-store' +import type { + AsyncQueuerOptions, + AsyncQueuerState, +} from '@tanstack/pacer/async-queuer' + +export interface ReactAsyncQueuer extends Omit< + AsyncQueuer, + 'store' +> { + /** + * Reactive state that will be updated and re-rendered when the queuer state changes + * + * Use this instead of `queuer.store.state` + */ + readonly state: Readonly + /** + * @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state. + * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally. + * Although, you can make the state reactive by using the `useStore` in your own usage. + */ + readonly store: Store>> +} + +/** + * A lower-level Preact hook that creates an `AsyncQueuer` instance for managing an async queue of items. + * + * Features: + * - Priority queue support via getPriority option + * - Configurable concurrency limit + * - Task success/error/completion callbacks + * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior + * - Pause/resume task processing + * - Task cancellation + * - Item expiration to clear stale items from the queue + * + * Tasks are processed concurrently up to the configured concurrency limit. When a task completes, + * the next pending task is processed if below the concurrency limit. + * + * Error Handling: + * - If an `onError` handler is provided, it will be called with the error and queuer instance + * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown + * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed + * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown + * - The error state can be checked using the underlying AsyncQueuer instance + * + * ## State Management and Selector + * + * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you + * to specify which state changes will trigger a re-render, optimizing performance by preventing + * unnecessary re-renders when irrelevant state changes occur. + * + * **By default, there will be no reactive state subscriptions** and you must opt-in to state + * tracking by providing a selector function. This prevents unnecessary re-renders and gives you + * full control over when your component updates. Only when you provide a selector will the + * component re-render when the selected state values change. + * + * Available state properties: + * - `activeItems`: Items currently being processed by the queuer + * - `errorCount`: Number of task executions that have resulted in errors + * - `expirationCount`: Number of items that have been removed due to expiration + * - `isEmpty`: Whether the queuer has no items to process + * - `isFull`: Whether the queuer has reached its maximum capacity + * - `isIdle`: Whether the queuer is not currently processing any items + * - `isRunning`: Whether the queuer is active and will process items automatically + * - `items`: Array of items currently waiting to be processed + * - `itemTimestamps`: Timestamps when items were added for expiration tracking + * - `lastResult`: The result from the most recent task execution + * - `pendingTick`: Whether the queuer has a pending timeout for processing the next item + * - `rejectionCount`: Number of items that have been rejected from being added + * - `settledCount`: Number of task executions that have completed (success or error) + * - `size`: Number of items currently in the queue + * - `status`: Current processing status ('idle' | 'running' | 'stopped') + * - `successCount`: Number of task executions that have completed successfully + * + * @example + * ```tsx + * // Default behavior - no reactive state subscriptions + * const asyncQueuer = useAsyncQueuer( + * async (item) => { + * const result = await processItem(item); + * return result; + * }, + * { concurrency: 2, maxSize: 100, started: false } + * ); + * + * // Opt-in to re-render when queue size changes (optimized for displaying queue length) + * const asyncQueuer = useAsyncQueuer( + * async (item) => { + * const result = await processItem(item); + * return result; + * }, + * { concurrency: 2, maxSize: 100, started: false }, + * (state) => ({ + * size: state.size, + * isEmpty: state.isEmpty, + * isFull: state.isFull + * }) + * ); + * + * // Opt-in to re-render when processing state changes (optimized for loading indicators) + * const asyncQueuer = useAsyncQueuer( + * async (item) => { + * const result = await processItem(item); + * return result; + * }, + * { concurrency: 2, maxSize: 100, started: false }, + * (state) => ({ + * isRunning: state.isRunning, + * isIdle: state.isIdle, + * status: state.status, + * activeItems: state.activeItems, + * pendingTick: state.pendingTick + * }) + * ); + * + * // Opt-in to re-render when execution metrics change (optimized for stats display) + * const asyncQueuer = useAsyncQueuer( + * async (item) => { + * const result = await processItem(item); + * return result; + * }, + * { concurrency: 2, maxSize: 100, started: false }, + * (state) => ({ + * successCount: state.successCount, + * errorCount: state.errorCount, + * settledCount: state.settledCount, + * expirationCount: state.expirationCount, + * rejectionCount: state.rejectionCount + * }) + * ); + * + * // Opt-in to re-render when results are available (optimized for data display) + * const asyncQueuer = useAsyncQueuer( + * async (item) => { + * const result = await processItem(item); + * return result; + * }, + * { + * concurrency: 2, + * maxSize: 100, + * started: false, + * onSuccess: (result) => { + * console.log('Item processed:', result); + * }, + * onError: (error) => { + * console.error('Processing failed:', error); + * } + * }, + * (state) => ({ + * lastResult: state.lastResult, + * successCount: state.successCount + * }) + * ); + * + * // Add items to queue + * asyncQueuer.addItem(newItem); + * + * // Start processing + * asyncQueuer.start(); + * + * // Access the selected state (will be empty object {} unless selector provided) + * const { size, isRunning, activeItems } = asyncQueuer.state; + * ``` + */ +export function useAsyncQueuer( + fn: (value: TValue) => Promise, + options: AsyncQueuerOptions = {}, + selector: (state: AsyncQueuerState) => TSelected = () => + ({}) as TSelected, +): ReactAsyncQueuer { + const mergedOptions = { + ...useDefaultPacerOptions().asyncQueuer, + ...options, + } as AsyncQueuerOptions + + const [asyncQueuer] = useState( + () => new AsyncQueuer(fn, mergedOptions), + ) + + asyncQueuer.fn = fn + asyncQueuer.setOptions(mergedOptions) + + const state = useStore(asyncQueuer.store, selector) + + return useMemo( + () => + ({ + ...asyncQueuer, + state, + }) as ReactAsyncQueuer, // omit `store` in favor of `state` + [asyncQueuer, state], + ) +} diff --git a/packages/preact-pacer/src/async-rate-limiter/index.ts b/packages/preact-pacer/src/async-rate-limiter/index.ts new file mode 100644 index 00000000..14a0cc7e --- /dev/null +++ b/packages/preact-pacer/src/async-rate-limiter/index.ts @@ -0,0 +1,5 @@ +// re-export everything from the core pacer package, BUT ONLY from the async-rate-limiter module +export * from '@tanstack/pacer/async-rate-limiter' + +export * from './useAsyncRateLimiter' +export * from './useAsyncRateLimitedCallback' diff --git a/packages/preact-pacer/src/async-rate-limiter/useAsyncRateLimitedCallback.ts b/packages/preact-pacer/src/async-rate-limiter/useAsyncRateLimitedCallback.ts new file mode 100644 index 00000000..bafc89b3 --- /dev/null +++ b/packages/preact-pacer/src/async-rate-limiter/useAsyncRateLimitedCallback.ts @@ -0,0 +1,69 @@ +import { useCallback } from 'preact/hooks' +import { useAsyncRateLimiter } from './useAsyncRateLimiter' +import type { AnyAsyncFunction } from '@tanstack/pacer/types' +import type { AsyncRateLimiterOptions } from '@tanstack/pacer/async-rate-limiter' + +/** + * A Preact hook that creates a rate-limited version of an async callback function. + * This hook is a convenient wrapper around the `useAsyncRateLimiter` hook, + * providing a stable, async rate-limited function reference for use in Preact components. + * + * Async rate limiting is a "hard limit" approach for async functions: it allows all calls + * until the limit is reached, then blocks (rejects) subsequent calls until the window resets. + * Unlike throttling or debouncing, it does not attempt to space out or collapse calls. + * This can lead to bursts of rapid executions followed by periods where all calls are blocked. + * + * The async rate limiter supports two types of windows: + * - 'fixed': A strict window that resets after the window period. All executions within the window count + * towards the limit, and the window resets completely after the period. + * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more + * consistent rate of execution over time. + * + * For smoother execution patterns, consider: + * - useAsyncThrottledCallback: When you want consistent spacing between executions (e.g. UI updates) + * - useAsyncDebouncedCallback: When you want to collapse rapid calls into a single execution (e.g. search input) + * + * Async rate limiting should primarily be used when you need to enforce strict limits + * on async operations, like API rate limits or other scenarios requiring hard caps + * on execution frequency. + * + * This hook provides a simpler API compared to `useAsyncRateLimiter`, making it ideal for basic + * async rate limiting needs. However, it does not expose the underlying AsyncRateLimiter instance. + * + * For advanced usage requiring features like: + * - Manual cancellation + * - Access to execution counts + * - Custom useCallback dependencies + * + * Consider using the `useAsyncRateLimiter` hook instead. + * + * + * @example + * ```tsx + * // Rate limit async API calls to maximum 5 calls per minute with a sliding window + * const makeApiCall = useAsyncRateLimitedCallback( + * async (data: ApiData) => { + * return fetch('/api/endpoint', { method: 'POST', body: JSON.stringify(data) }); + * }, + * { + * limit: 5, + * window: 60000, // 1 minute + * windowType: 'sliding', + * onReject: () => { + * console.warn('API rate limit reached. Please wait before trying again.'); + * } + * } + * ); + * ``` + */ +export function useAsyncRateLimitedCallback( + fn: TFn, + options: AsyncRateLimiterOptions, +): (...args: Parameters) => Promise> { + const asyncRateLimitedFn = useAsyncRateLimiter(fn, options).maybeExecute + return useCallback( + (...args: Parameters) => + asyncRateLimitedFn(...args) as Promise>, + [asyncRateLimitedFn], + ) +} diff --git a/packages/preact-pacer/src/async-rate-limiter/useAsyncRateLimiter.ts b/packages/preact-pacer/src/async-rate-limiter/useAsyncRateLimiter.ts new file mode 100644 index 00000000..72204962 --- /dev/null +++ b/packages/preact-pacer/src/async-rate-limiter/useAsyncRateLimiter.ts @@ -0,0 +1,210 @@ +import { useMemo, useState } from 'preact/hooks' +import { AsyncRateLimiter } from '@tanstack/pacer/async-rate-limiter' +import { useStore } from '@tanstack/preact-store' +import { useDefaultPacerOptions } from '../provider/PacerProvider' +import type { Store } from '@tanstack/preact-store' +import type { AnyAsyncFunction } from '@tanstack/pacer/types' +import type { + AsyncRateLimiterOptions, + AsyncRateLimiterState, +} from '@tanstack/pacer/async-rate-limiter' + +export interface ReactAsyncRateLimiter< + TFn extends AnyAsyncFunction, + TSelected = {}, +> extends Omit, 'store'> { + /** + * Reactive state that will be updated and re-rendered when the rate limiter state changes + * + * Use this instead of `rateLimiter.store.state` + */ + readonly state: Readonly + /** + * @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state. + * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally. + * Although, you can make the state reactive by using the `useStore` in your own usage. + */ + readonly store: Store>> +} + +/** + * A low-level Preact hook that creates an `AsyncRateLimiter` instance to limit how many times an async function can execute within a time window. + * + * This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that + * you can integrate with any state management solution (useState, Redux, Zustand, Jotai, etc). + * + * Rate limiting allows an async function to execute up to a specified limit within a time window, + * then blocks subsequent calls until the window passes. This is useful for respecting API rate limits, + * managing resource constraints, or controlling bursts of async operations. + * + * Unlike the non-async RateLimiter, this async version supports returning values from the rate-limited function, + * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call + * instead of setting the result on a state variable from within the rate-limited function. + * + * The rate limiter supports two types of windows: + * - 'fixed': A strict window that resets after the window period. All executions within the window count + * towards the limit, and the window resets completely after the period. + * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more + * consistent rate of execution over time. + * + * Error Handling: + * - If an `onError` handler is provided, it will be called with the error and rate limiter instance + * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown + * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed + * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown + * - The error state can be checked using the underlying AsyncRateLimiter instance + * - Rate limit rejections (when limit is exceeded) are handled separately from execution errors via the `onReject` handler + * + * ## State Management and Selector + * + * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you + * to specify which state changes will trigger a re-render, optimizing performance by preventing + * unnecessary re-renders when irrelevant state changes occur. + * + * **By default, there will be no reactive state subscriptions** and you must opt-in to state + * tracking by providing a selector function. This prevents unnecessary re-renders and gives you + * full control over when your component updates. Only when you provide a selector will the + * component re-render when the selected state values change. + * + * Available state properties: + * - `errorCount`: Number of function executions that have resulted in errors + * - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations + * - `isExecuting`: Whether the rate-limited function is currently executing asynchronously + * - `lastResult`: The result from the most recent successful function execution + * - `rejectionCount`: Number of function executions that have been rejected due to rate limiting + * - `settleCount`: Number of function executions that have completed (success or error) + * - `successCount`: Number of function executions that have completed successfully + * + * @example + * ```tsx + * // Default behavior - no reactive state subscriptions + * const asyncRateLimiter = useAsyncRateLimiter( + * async (id: string) => { + * const data = await api.fetchData(id); + * return data; // Return value is preserved + * }, + * { limit: 5, window: 1000 } // 5 calls per second + * ); + * + * // Opt-in to re-render when execution state changes (optimized for loading indicators) + * const asyncRateLimiter = useAsyncRateLimiter( + * async (id: string) => { + * const data = await api.fetchData(id); + * return data; + * }, + * { limit: 5, window: 1000 }, + * (state) => ({ isExecuting: state.isExecuting }) + * ); + * + * // Opt-in to re-render when results are available (optimized for data display) + * const asyncRateLimiter = useAsyncRateLimiter( + * async (id: string) => { + * const data = await api.fetchData(id); + * return data; + * }, + * { limit: 5, window: 1000 }, + * (state) => ({ + * lastResult: state.lastResult, + * successCount: state.successCount + * }) + * ); + * + * // Opt-in to re-render when error/rejection state changes (optimized for error handling) + * const asyncRateLimiter = useAsyncRateLimiter( + * async (id: string) => { + * const data = await api.fetchData(id); + * return data; + * }, + * { + * limit: 5, + * window: 1000, + * onError: (error) => console.error('API call failed:', error), + * onReject: (rateLimiter) => console.log('Rate limit exceeded') + * }, + * (state) => ({ + * errorCount: state.errorCount, + * rejectionCount: state.rejectionCount + * }) + * ); + * + * // Opt-in to re-render when execution metrics change (optimized for stats display) + * const asyncRateLimiter = useAsyncRateLimiter( + * async (id: string) => { + * const data = await api.fetchData(id); + * return data; + * }, + * { limit: 5, window: 1000 }, + * (state) => ({ + * successCount: state.successCount, + * errorCount: state.errorCount, + * settleCount: state.settleCount, + * rejectionCount: state.rejectionCount + * }) + * ); + * + * // Opt-in to re-render when execution times change (optimized for window calculations) + * const asyncRateLimiter = useAsyncRateLimiter( + * async (id: string) => { + * const data = await api.fetchData(id); + * return data; + * }, + * { limit: 5, window: 1000 }, + * (state) => ({ executionTimes: state.executionTimes }) + * ); + * + * // With state management and return value + * const [data, setData] = useState(null); + * const { maybeExecute, state } = useAsyncRateLimiter( + * async (query) => { + * const result = await searchAPI(query); + * setData(result); + * return result; // Return value can be used by the caller + * }, + * { + * limit: 10, + * window: 60000, // 10 calls per minute + * onReject: (rateLimiter) => { + * console.log(`Rate limit exceeded. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`); + * }, + * onError: (error) => { + * console.error('API call failed:', error); + * } + * } + * ); + * + * // Access the selected state (will be empty object {} unless selector provided) + * const { isExecuting, lastResult, rejectionCount } = state; + * ``` + */ +export function useAsyncRateLimiter< + TFn extends AnyAsyncFunction, + TSelected = {}, +>( + fn: TFn, + options: AsyncRateLimiterOptions, + selector: (state: AsyncRateLimiterState) => TSelected = () => + ({}) as TSelected, +): ReactAsyncRateLimiter { + const mergedOptions = { + ...useDefaultPacerOptions().asyncRateLimiter, + ...options, + } as AsyncRateLimiterOptions + + const [asyncRateLimiter] = useState( + () => new AsyncRateLimiter(fn, mergedOptions), + ) + + asyncRateLimiter.fn = fn + asyncRateLimiter.setOptions(mergedOptions) + + const state = useStore(asyncRateLimiter.store, selector) + + return useMemo( + () => + ({ + ...asyncRateLimiter, + state, + }) as ReactAsyncRateLimiter, // omit `store` in favor of `state` + [asyncRateLimiter, state], + ) +} diff --git a/packages/preact-pacer/src/async-retryer/index.ts b/packages/preact-pacer/src/async-retryer/index.ts new file mode 100644 index 00000000..371a59aa --- /dev/null +++ b/packages/preact-pacer/src/async-retryer/index.ts @@ -0,0 +1,2 @@ +// re-export everything from the core pacer package, BUT ONLY from the async-retryer module +export * from '@tanstack/pacer/async-retryer' diff --git a/packages/preact-pacer/src/async-throttler/index.ts b/packages/preact-pacer/src/async-throttler/index.ts new file mode 100644 index 00000000..f557de64 --- /dev/null +++ b/packages/preact-pacer/src/async-throttler/index.ts @@ -0,0 +1,5 @@ +// re-export everything from the core pacer package, BUT ONLY from the async-throttler module +export * from '@tanstack/pacer/async-throttler' + +export * from './useAsyncThrottler' +export * from './useAsyncThrottledCallback' diff --git a/packages/preact-pacer/src/async-throttler/useAsyncThrottledCallback.ts b/packages/preact-pacer/src/async-throttler/useAsyncThrottledCallback.ts new file mode 100644 index 00000000..78732b90 --- /dev/null +++ b/packages/preact-pacer/src/async-throttler/useAsyncThrottledCallback.ts @@ -0,0 +1,52 @@ +import { useCallback } from 'preact/hooks' +import { useAsyncThrottler } from './useAsyncThrottler' +import type { AsyncThrottlerOptions } from '@tanstack/pacer/async-throttler' +import type { AnyAsyncFunction } from '@tanstack/pacer/types' + +/** + * A Preact hook that creates a throttled version of an async callback function. + * This hook is a convenient wrapper around the `useAsyncThrottler` hook, + * providing a stable, throttled async function reference for use in Preact components. + * + * The throttled async function will execute at most once within the specified wait time period, + * regardless of how many times it is called. If called multiple times during the wait period, + * only the first invocation will execute, and subsequent calls will be ignored until + * the wait period has elapsed. The returned function always returns a promise + * that resolves or rejects with the result of the original async function. + * + * This hook provides a simpler API compared to `useAsyncThrottler`, making it ideal for basic + * async throttling needs. However, it does not expose the underlying AsyncThrottler instance. + * + * For advanced usage requiring features like: + * - Manual cancellation + * - Access to execution/error state + * - Custom useCallback dependencies + * + * Consider using the `useAsyncThrottler` hook instead. + * + * + * @example + * ```tsx + * // Throttle an async API call + * const handleApiCall = useAsyncThrottledCallback(async (data) => { + * const result = await sendDataToServer(data); + * return result; + * }, { + * wait: 200 // Execute at most once every 200ms + * }); + * + * // Use in an event handler + * + * ``` + */ +export function useAsyncThrottledCallback( + fn: TFn, + options: AsyncThrottlerOptions, +): (...args: Parameters) => Promise> { + const asyncThrottledFn = useAsyncThrottler(fn, options).maybeExecute + return useCallback( + (...args: Parameters) => + asyncThrottledFn(...args) as Promise>, + [asyncThrottledFn], + ) +} diff --git a/packages/preact-pacer/src/async-throttler/useAsyncThrottler.ts b/packages/preact-pacer/src/async-throttler/useAsyncThrottler.ts new file mode 100644 index 00000000..cfe928ae --- /dev/null +++ b/packages/preact-pacer/src/async-throttler/useAsyncThrottler.ts @@ -0,0 +1,193 @@ +import { useEffect, useMemo, useState } from 'preact/hooks' +import { AsyncThrottler } from '@tanstack/pacer/async-throttler' +import { useStore } from '@tanstack/preact-store' +import { useDefaultPacerOptions } from '../provider/PacerProvider' +import type { Store } from '@tanstack/preact-store' +import type { AnyAsyncFunction } from '@tanstack/pacer/types' +import type { + AsyncThrottlerOptions, + AsyncThrottlerState, +} from '@tanstack/pacer/async-throttler' + +export interface ReactAsyncThrottler< + TFn extends AnyAsyncFunction, + TSelected = {}, +> extends Omit, 'store'> { + /** + * Reactive state that will be updated and re-rendered when the throttler state changes + * + * Use this instead of `throttler.store.state` + */ + readonly state: Readonly + /** + * @deprecated Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state. + * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally. + * Although, you can make the state reactive by using the `useStore` in your own usage. + */ + readonly store: Store>> +} + +/** + * A low-level Preact hook that creates an `AsyncThrottler` instance to limit how often an async function can execute. + * + * This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that + * you can integrate with any state management solution (useState, Redux, Zustand, Jotai, etc). + * + * Async throttling ensures an async function executes at most once within a specified time window, + * regardless of how many times it is called. This is useful for rate-limiting expensive API calls, + * database operations, or other async tasks. + * + * Unlike the non-async Throttler, this async version supports returning values from the throttled function, + * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call + * instead of setting the result on a state variable from within the throttled function. + * + * Error Handling: + * - If an `onError` handler is provided, it will be called with the error and throttler instance + * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown + * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed + * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown + * - The error state can be checked using the underlying AsyncThrottler instance + * + * ## State Management and Selector + * + * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you + * to specify which state changes will trigger a re-render, optimizing performance by preventing + * unnecessary re-renders when irrelevant state changes occur. + * + * **By default, there will be no reactive state subscriptions** and you must opt-in to state + * tracking by providing a selector function. This prevents unnecessary re-renders and gives you + * full control over when your component updates. Only when you provide a selector will the + * component re-render when the selected state values change. + * + * Available state properties: + * - `errorCount`: Number of function executions that have resulted in errors + * - `isExecuting`: Whether the throttled function is currently executing asynchronously + * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution + * - `lastArgs`: The arguments from the most recent call to maybeExecute + * - `lastExecutionTime`: Timestamp of the last function execution in milliseconds + * - `lastResult`: The result from the most recent successful function execution + * - `nextExecutionTime`: Timestamp when the next execution can occur in milliseconds + * - `settleCount`: Number of function executions that have completed (success or error) + * - `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing' | 'settled') + * - `successCount`: Number of function executions that have completed successfully + * + * @example + * ```tsx + * // Default behavior - no reactive state subscriptions + * const asyncThrottler = useAsyncThrottler( + * async (id: string) => { + * const data = await api.fetchData(id); + * return data; // Return value is preserved + * }, + * { wait: 1000 } + * ); + * + * // Opt-in to re-render when execution state changes (optimized for loading indicators) + * const asyncThrottler = useAsyncThrottler( + * async (id: string) => { + * const data = await api.fetchData(id); + * return data; + * }, + * { wait: 1000 }, + * (state) => ({ + * isExecuting: state.isExecuting, + * isPending: state.isPending, + * status: state.status + * }) + * ); + * + * // Opt-in to re-render when results are available (optimized for data display) + * const asyncThrottler = useAsyncThrottler( + * async (id: string) => { + * const data = await api.fetchData(id); + * return data; + * }, + * { wait: 1000 }, + * (state) => ({ + * lastResult: state.lastResult, + * successCount: state.successCount, + * settleCount: state.settleCount + * }) + * ); + * + * // Opt-in to re-render when error state changes (optimized for error handling) + * const asyncThrottler = useAsyncThrottler( + * async (id: string) => { + * const data = await api.fetchData(id); + * return data; + * }, + * { + * wait: 1000, + * onError: (error) => console.error('API call failed:', error) + * }, + * (state) => ({ + * errorCount: state.errorCount, + * status: state.status + * }) + * ); + * + * // Opt-in to re-render when timing information changes (optimized for timing displays) + * const asyncThrottler = useAsyncThrottler( + * async (id: string) => { + * const data = await api.fetchData(id); + * return data; + * }, + * { wait: 1000 }, + * (state) => ({ + * lastExecutionTime: state.lastExecutionTime, + * nextExecutionTime: state.nextExecutionTime + * }) + * ); + * + * // With state management and return value + * const [data, setData] = useState(null); + * const { maybeExecute, state } = useAsyncThrottler( + * async (query) => { + * const result = await searchAPI(query); + * setData(result); + * return result; // Return value can be used by the caller + * }, + * { + * wait: 2000, + * leading: true, // Execute immediately on first call + * trailing: false // Skip trailing edge updates + * } + * ); + * + * // Access the selected state (will be empty object {} unless selector provided) + * const { isExecuting, lastResult } = state; + * ``` + */ +export function useAsyncThrottler( + fn: TFn, + options: AsyncThrottlerOptions, + selector: (state: AsyncThrottlerState) => TSelected = () => + ({}) as TSelected, +): ReactAsyncThrottler { + const mergedOptions = { + ...useDefaultPacerOptions().asyncThrottler, + ...options, + } as AsyncThrottlerOptions + + const [asyncThrottler] = useState( + () => new AsyncThrottler(fn, mergedOptions), + ) + + asyncThrottler.fn = fn + asyncThrottler.setOptions(mergedOptions) + + const state = useStore(asyncThrottler.store, selector) + + useEffect(() => { + return () => asyncThrottler.cancel() + }, [asyncThrottler]) + + return useMemo( + () => + ({ + ...asyncThrottler, + state, + }) as ReactAsyncThrottler, // omit `store` in favor of `state` + [asyncThrottler, state], + ) +} diff --git a/packages/preact-pacer/src/batcher/index.ts b/packages/preact-pacer/src/batcher/index.ts new file mode 100644 index 00000000..f1c8ba98 --- /dev/null +++ b/packages/preact-pacer/src/batcher/index.ts @@ -0,0 +1,4 @@ +export * from '@tanstack/pacer/batcher' + +export * from './useBatcher' +export * from './useBatchedCallback' diff --git a/packages/preact-pacer/src/batcher/useBatchedCallback.ts b/packages/preact-pacer/src/batcher/useBatchedCallback.ts new file mode 100644 index 00000000..ff47721e --- /dev/null +++ b/packages/preact-pacer/src/batcher/useBatchedCallback.ts @@ -0,0 +1,50 @@ +import { useCallback } from 'preact/hooks' +import { useBatcher } from './useBatcher' +import type { BatcherOptions } from '@tanstack/pacer/batcher' +import type { AnyFunction } from '@tanstack/pacer/types' + +/** + * A Preact hook that creates a batched version of a callback function. + * This hook is essentially a wrapper around the basic `batch` function + * that is exported from `@tanstack/pacer`, + * but optimized for Preact with reactive options and a stable function reference. + * + * The batched function will collect individual calls into batches and execute them + * when batch conditions are met (max size reached, wait time elapsed, or custom logic). + * + * This hook provides a simpler API compared to `useBatcher`, making it ideal for basic + * batching needs. However, it does not expose the underlying Batcher instance. + * + * For advanced usage requiring features like: + * - Manual batch execution + * - Access to batch state and metrics + * - Custom useCallback dependencies + * + * Consider using the `useBatcher` hook instead. + * + * @example + * ```tsx + * // Batch analytics events + * const trackEvents = useBatchedCallback((events: AnalyticsEvent[]) => { + * sendAnalytics(events); + * }, { + * maxSize: 5, // Process when 5 events collected + * wait: 2000 // Or after 2 seconds + * }); + * + * // Use in event handlers + * + * ``` + */ +export function useBatchedCallback( + fn: (items: Array[0]>) => void, + options: BatcherOptions[0]>, +): (...args: Parameters) => void { + const batchedFn = useBatcher(fn, options).addItem + return useCallback( + (...args: Parameters) => batchedFn(args[0]), + [batchedFn], + ) +} diff --git a/packages/preact-pacer/src/batcher/useBatcher.ts b/packages/preact-pacer/src/batcher/useBatcher.ts new file mode 100644 index 00000000..0d72cd1d --- /dev/null +++ b/packages/preact-pacer/src/batcher/useBatcher.ts @@ -0,0 +1,150 @@ +import { useMemo, useState } from 'preact/hooks' +import { Batcher } from '@tanstack/pacer/batcher' +import { useStore } from '@tanstack/preact-store' +import { useDefaultPacerOptions } from '../provider/PacerProvider' +import type { Store } from '@tanstack/preact-store' +import type { BatcherOptions, BatcherState } from '@tanstack/pacer/batcher' + +export interface PreactBatcher extends Omit< + Batcher, + 'store' +> { + /** + * Reactive state that will be updated and re-rendered when the batcher state changes + * + * Use this instead of `batcher.store.state` + */ + readonly state: Readonly + /** + * @deprecated Use `batcher.state` instead of `batcher.store.state` if you want to read reactive state. + * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally. + * Although, you can make the state reactive by using the `useStore` in your own usage. + */ + readonly store: Store>> +} + +/** + * A Preact hook that creates and manages a Batcher instance. + * + * This is a lower-level hook that provides direct access to the Batcher's functionality without + * any built-in state management. This allows you to integrate it with any state management solution + * you prefer (useState, Redux, Zustand, etc.) by utilizing the onItemsChange callback. + * + * The Batcher collects items and processes them in batches based on configurable conditions: + * - Maximum batch size + * - Time-based batching (process after X milliseconds) + * - Custom batch processing logic via getShouldExecute + * + * ## State Management and Selector + * + * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you + * to specify which state changes will trigger a re-render, optimizing performance by preventing + * unnecessary re-renders when irrelevant state changes occur. + * + * **By default, there will be no reactive state subscriptions** and you must opt-in to state + * tracking by providing a selector function. This prevents unnecessary re-renders and gives you + * full control over when your component updates. Only when you provide a selector will the + * component re-render when the selected state values change. + * + * Available state properties: + * - `executionCount`: Number of batch executions that have been completed + * - `isEmpty`: Whether the batcher has no items to process + * - `isPending`: Whether the batcher is waiting for the timeout to trigger batch processing + * - `isRunning`: Whether the batcher is active and will process items automatically + * - `items`: Array of items currently queued for batch processing + * - `size`: Number of items currently in the batch queue + * - `status`: Current processing status ('idle' | 'pending') + * - `totalItemsProcessed`: Total number of items processed across all batches + * + * @example + * ```tsx + * // Default behavior - no reactive state subscriptions + * const batcher = useBatcher( + * (items) => console.log('Processing batch:', items), + * { maxSize: 5, wait: 2000 } + * ); + * + * // Opt-in to re-render when batch size changes (optimized for displaying queue size) + * const batcher = useBatcher( + * (items) => console.log('Processing batch:', items), + * { maxSize: 5, wait: 2000 }, + * (state) => ({ + * size: state.size, + * isEmpty: state.isEmpty + * }) + * ); + * + * // Opt-in to re-render when execution metrics change (optimized for stats display) + * const batcher = useBatcher( + * (items) => console.log('Processing batch:', items), + * { maxSize: 5, wait: 2000 }, + * (state) => ({ + * executionCount: state.executionCount, + * totalItemsProcessed: state.totalItemsProcessed + * }) + * ); + * + * // Opt-in to re-render when processing state changes (optimized for loading indicators) + * const batcher = useBatcher( + * (items) => console.log('Processing batch:', items), + * { maxSize: 5, wait: 2000 }, + * (state) => ({ + * isPending: state.isPending, + * isRunning: state.isRunning, + * status: state.status + * }) + * ); + * + * // Example with custom state management and batching + * const [items, setItems] = useState([]); + * + * const batcher = useBatcher( + * (items) => console.log('Processing batch:', items), + * { + * maxSize: 5, + * wait: 2000, + * onItemsChange: (batcher) => setItems(batcher.peekAllItems()), + * getShouldExecute: (items) => items.length >= 3 + * } + * ); + * + * // Add items to batch - they'll be processed when conditions are met + * batcher.addItem(1); + * batcher.addItem(2); + * batcher.addItem(3); // Triggers batch processing + * + * // Control the batcher + * batcher.stop(); // Pause batching + * batcher.start(); // Resume batching + * + * // Access the selected state (will be empty object {} unless selector provided) + * const { size, isPending } = batcher.state; + * ``` + */ +export function useBatcher( + fn: (items: Array) => void, + options: BatcherOptions = {}, + selector: (state: BatcherState) => TSelected = () => + ({}) as TSelected, +): PreactBatcher { + const mergedOptions = { + ...useDefaultPacerOptions().batcher, + ...options, + } as BatcherOptions + + const [batcher] = useState(() => new Batcher(fn, mergedOptions)) + + batcher.fn = fn + batcher.setOptions(mergedOptions) + + const state = useStore(batcher.store, selector) + + return useMemo( + () => + ({ + ...batcher, + state, + }) as PreactBatcher, // omit `store` in favor of `state` + [batcher, state], + ) +} diff --git a/packages/preact-pacer/src/debouncer/index.ts b/packages/preact-pacer/src/debouncer/index.ts new file mode 100644 index 00000000..2c872d75 --- /dev/null +++ b/packages/preact-pacer/src/debouncer/index.ts @@ -0,0 +1,7 @@ +// re-export everything from the core pacer package, BUT ONLY from the debouncer module +export * from '@tanstack/pacer/debouncer' + +export * from './useDebouncedCallback' +export * from './useDebouncedState' +export * from './useDebouncedValue' +export * from './useDebouncer' diff --git a/packages/preact-pacer/src/debouncer/useDebouncedCallback.ts b/packages/preact-pacer/src/debouncer/useDebouncedCallback.ts new file mode 100644 index 00000000..bd896747 --- /dev/null +++ b/packages/preact-pacer/src/debouncer/useDebouncedCallback.ts @@ -0,0 +1,51 @@ +import { useCallback } from 'preact/hooks' +import { useDebouncer } from './useDebouncer' +import type { DebouncerOptions } from '@tanstack/pacer/debouncer' +import type { AnyFunction } from '@tanstack/pacer/types' + +/** + * A Preact hook that creates a debounced version of a callback function. + * This hook is essentially a wrapper around the basic `debounce` function + * that is exported from `@tanstack/pacer`, + * but optimized for Preact with reactive options and a stable function reference. + * + * The debounced function will only execute after the specified wait time has elapsed + * since its last invocation. If called again before the wait time expires, the timer + * resets and starts waiting again. + * + * This hook provides a simpler API compared to `useDebouncer`, making it ideal for basic + * debouncing needs. However, it does not expose the underlying Debouncer instance. + * + * For advanced usage requiring features like: + * - Manual cancellation + * - Access to execution counts + * - Custom useCallback dependencies + * + * Consider using the `useDebouncer` hook instead. + * + * @example + * ```tsx + * // Debounce a search handler + * const handleSearch = useDebouncedCallback((query: string) => { + * fetchSearchResults(query); + * }, { + * wait: 500 // Wait 500ms between executions + * }); + * + * // Use in an input + * handleSearch(e.target.value)} + * /> + * ``` + */ +export function useDebouncedCallback( + fn: TFn, + options: DebouncerOptions, +): (...args: Parameters) => void { + const debouncedFn = useDebouncer(fn, options).maybeExecute + return useCallback( + (...args: Parameters) => debouncedFn(...args), + [debouncedFn], + ) +} diff --git a/packages/preact-pacer/src/debouncer/useDebouncedState.ts b/packages/preact-pacer/src/debouncer/useDebouncedState.ts new file mode 100644 index 00000000..b39b33cd --- /dev/null +++ b/packages/preact-pacer/src/debouncer/useDebouncedState.ts @@ -0,0 +1,109 @@ +import { useState } from 'preact/hooks' +import { useDebouncer } from './useDebouncer' +import type { Dispatch, StateUpdater } from 'preact/hooks' +import type { PreactDebouncer } from './useDebouncer' +import type { + DebouncerOptions, + DebouncerState, +} from '@tanstack/pacer/debouncer' + +/** + * A Preact hook that creates a debounced state value, combining Preact's useState with debouncing functionality. + * This hook provides both the current debounced value and methods to update it. + * + * The state value is only updated after the specified wait time has elapsed since the last update attempt. + * If another update is attempted before the wait time expires, the timer resets and starts waiting again. + * This is useful for handling frequent state updates that should be throttled, like search input values + * or window resize dimensions. + * + * The hook returns a tuple containing: + * - The current debounced value + * - A function to update the debounced value + * - The debouncer instance with additional control methods + * + * ## State Management and Selector + * + * The hook uses TanStack Store for reactive state management via the underlying debouncer instance. + * The `selector` parameter allows you to specify which debouncer state changes will trigger a re-render, + * optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur. + * + * **By default, there will be no reactive state subscriptions** and you must opt-in to state + * tracking by providing a selector function. This prevents unnecessary re-renders and gives you + * full control over when your component updates. Only when you provide a selector will the + * component re-render when the selected state values change. + * + * Available debouncer state properties: + * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge + * - `executionCount`: Number of function executions that have been completed + * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution + * - `lastArgs`: The arguments from the most recent call to maybeExecute + * - `status`: Current execution status ('disabled' | 'idle' | 'pending') + * + * @example + * ```tsx + * // Default behavior - no reactive state subscriptions + * const [searchTerm, setSearchTerm, debouncer] = useDebouncedState('', { + * wait: 500 // Wait 500ms after last keystroke + * }); + * + * // Opt-in to re-render when pending state changes (optimized for loading indicators) + * const [searchTerm, setSearchTerm, debouncer] = useDebouncedState( + * '', + * { wait: 500 }, + * (state) => ({ isPending: state.isPending }) + * ); + * + * // Opt-in to re-render when execution count changes (optimized for tracking executions) + * const [searchTerm, setSearchTerm, debouncer] = useDebouncedState( + * '', + * { wait: 500 }, + * (state) => ({ executionCount: state.executionCount }) + * ); + * + * // Opt-in to re-render when debouncing status changes (optimized for status display) + * const [searchTerm, setSearchTerm, debouncer] = useDebouncedState( + * '', + * { wait: 500 }, + * (state) => ({ + * status: state.status, + * canLeadingExecute: state.canLeadingExecute + * }) + * ); + * + * // Update value - will be debounced + * const handleChange = (e) => { + * setSearchTerm(e.target.value); + * }; + * + * // Access the selected debouncer state (will be empty object {} unless selector provided) + * const { isPending, executionCount } = debouncer.state; + * ``` + */ +export function useDebouncedState< + TValue, + TSelected = DebouncerState>>, +>( + value: TValue, + options: DebouncerOptions>>, + selector?: ( + state: DebouncerState>>, + ) => TSelected, +): [ + TValue, + Dispatch>, + PreactDebouncer>, TSelected>, +] { + const [debouncedValue, setDebouncedValue] = useState(value) + const debouncer = useDebouncer( + setDebouncedValue, + options, + selector as ( + state: DebouncerState>>, + ) => TSelected, + ) + return [ + debouncedValue, + debouncer.maybeExecute as Dispatch>, + debouncer, + ] +} diff --git a/packages/preact-pacer/src/debouncer/useDebouncedValue.ts b/packages/preact-pacer/src/debouncer/useDebouncedValue.ts new file mode 100644 index 00000000..7002fa72 --- /dev/null +++ b/packages/preact-pacer/src/debouncer/useDebouncedValue.ts @@ -0,0 +1,112 @@ +import { useEffect } from 'preact/hooks' +import { useDebouncedState } from './useDebouncedState' +import type { Dispatch, StateUpdater } from 'preact/hooks' +import type { PreactDebouncer } from './useDebouncer' +import type { + DebouncerOptions, + DebouncerState, +} from '@tanstack/pacer/debouncer' + +/** + * A Preact hook that creates a debounced value that updates only after a specified delay. + * Unlike useDebouncedState, this hook automatically tracks changes to the input value + * and updates the debounced value accordingly. + * + * The debounced value will only update after the specified wait time has elapsed since + * the last change to the input value. If the input value changes again before the wait + * time expires, the timer resets and starts waiting again. + * + * This is useful for deriving debounced values from props or state that change frequently, + * like search queries or form inputs, where you want to limit how often downstream effects + * or calculations occur. + * + * The hook returns the current debounced value and the underlying debouncer instance. + * The debouncer instance can be used to access additional functionality like cancellation + * and execution counts. + * + * ## State Management and Selector + * + * The hook uses TanStack Store for reactive state management via the underlying debouncer instance. + * The `selector` parameter allows you to specify which debouncer state changes will trigger a re-render, + * optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur. + * + * **By default, there will be no reactive state subscriptions** and you must opt-in to state + * tracking by providing a selector function. This prevents unnecessary re-renders and gives you + * full control over when your component updates. Only when you provide a selector will the + * component re-render when the selected state values change. + * + * Available debouncer state properties: + * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge + * - `executionCount`: Number of function executions that have been completed + * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution + * - `lastArgs`: The arguments from the most recent call to maybeExecute + * - `status`: Current execution status ('disabled' | 'idle' | 'pending') + * + * @example + * ```tsx + * // Default behavior - no reactive state subscriptions + * const [searchQuery, setSearchQuery] = useState(''); + * const [debouncedQuery, debouncer] = useDebouncedValue(searchQuery, { + * wait: 500 // Wait 500ms after last change + * }); + * + * // Opt-in to re-render when pending state changes (optimized for loading indicators) + * const [debouncedQuery, debouncer] = useDebouncedValue( + * searchQuery, + * { wait: 500 }, + * (state) => ({ isPending: state.isPending }) + * ); + * + * // Opt-in to re-render when execution count changes (optimized for tracking executions) + * const [debouncedQuery, debouncer] = useDebouncedValue( + * searchQuery, + * { wait: 500 }, + * (state) => ({ executionCount: state.executionCount }) + * ); + * + * // Opt-in to re-render when debouncing status changes (optimized for status display) + * const [debouncedQuery, debouncer] = useDebouncedValue( + * searchQuery, + * { wait: 500 }, + * (state) => ({ + * status: state.status, + * canLeadingExecute: state.canLeadingExecute + * }) + * ); + * + * // debouncedQuery will update 500ms after searchQuery stops changing + * useEffect(() => { + * fetchSearchResults(debouncedQuery); + * }, [debouncedQuery]); + * + * // Handle input changes + * const handleChange = (e) => { + * setSearchQuery(e.target.value); + * }; + * + * // Access the selected debouncer state (will be empty object {} unless selector provided) + * const { isPending, executionCount } = debouncer.state; + * ``` + */ +export function useDebouncedValue< + TValue, + TSelected = DebouncerState>>, +>( + value: TValue, + options: DebouncerOptions>>, + selector?: ( + state: DebouncerState>>, + ) => TSelected, +): [TValue, PreactDebouncer>, TSelected>] { + const [debouncedValue, setDebouncedValue, debouncer] = useDebouncedState( + value, + options, + selector, + ) + + useEffect(() => { + ;(setDebouncedValue as (value: TValue) => void)(value) + }, [value, setDebouncedValue]) + + return [debouncedValue, debouncer] +} diff --git a/packages/preact-pacer/src/debouncer/useDebouncer.ts b/packages/preact-pacer/src/debouncer/useDebouncer.ts new file mode 100644 index 00000000..2e822d6b --- /dev/null +++ b/packages/preact-pacer/src/debouncer/useDebouncer.ts @@ -0,0 +1,136 @@ +import { useEffect, useMemo, useState } from 'preact/hooks' +import { Debouncer } from '@tanstack/pacer/debouncer' +import { useStore } from '@tanstack/preact-store' +import { useDefaultPacerOptions } from '../provider/PacerProvider' +import type { Store } from '@tanstack/preact-store' +import type { + DebouncerOptions, + DebouncerState, +} from '@tanstack/pacer/debouncer' +import type { AnyFunction } from '@tanstack/pacer/types' + +export interface PreactDebouncer< + TFn extends AnyFunction, + TSelected = {}, +> extends Omit, 'store'> { + /** + * Reactive state that will be updated and re-rendered when the debouncer state changes + * + * Use this instead of `debouncer.store.state` + */ + readonly state: Readonly + /** + * @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state. + * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally. + * Although, you can make the state reactive by using the `useStore` in your own usage. + */ + readonly store: Store>> +} + +/** + * A Preact hook that creates and manages a Debouncer instance. + * + * This is a lower-level hook that provides direct access to the Debouncer's functionality without + * any built-in state management. This allows you to integrate it with any state management solution + * you prefer (useState, Redux, Zustand, etc.). + * + * This hook provides debouncing functionality to limit how often a function can be called, + * waiting for a specified delay before executing the latest call. This is useful for handling + * frequent events like window resizing, scroll events, or real-time search inputs. + * + * The debouncer will only execute the function after the specified wait time has elapsed + * since the last call. If the function is called again before the wait time expires, the + * timer resets and starts waiting again. + * + * ## State Management and Selector + * + * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you + * to specify which state changes will trigger a re-render, optimizing performance by preventing + * unnecessary re-renders when irrelevant state changes occur. + * + * **By default, there will be no reactive state subscriptions** and you must opt-in to state + * tracking by providing a selector function. This prevents unnecessary re-renders and gives you + * full control over when your component updates. Only when you provide a selector will the + * component re-render when the selected state values change. + * + * Available state properties: + * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge + * - `executionCount`: Number of function executions that have been completed + * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution + * - `lastArgs`: The arguments from the most recent call to maybeExecute + * - `status`: Current execution status ('disabled' | 'idle' | 'pending') + * + * @example + * ```tsx + * // Default behavior - no reactive state subscriptions + * const searchDebouncer = useDebouncer( + * (query: string) => fetchSearchResults(query), + * { wait: 500 } + * ); + * + * // Opt-in to re-render when isPending changes (optimized for loading states) + * const searchDebouncer = useDebouncer( + * (query: string) => fetchSearchResults(query), + * { wait: 500 }, + * (state) => ({ isPending: state.isPending }) + * ); + * + * // Opt-in to re-render when executionCount changes (optimized for tracking execution) + * const searchDebouncer = useDebouncer( + * (query: string) => fetchSearchResults(query), + * { wait: 500 }, + * (state) => ({ executionCount: state.executionCount }) + * ); + * + * // Multiple state properties - re-render when any of these change + * const searchDebouncer = useDebouncer( + * (query: string) => fetchSearchResults(query), + * { wait: 500 }, + * (state) => ({ + * isPending: state.isPending, + * executionCount: state.executionCount, + * status: state.status + * }) + * ); + * + * // In an event handler + * const handleChange = (e) => { + * searchDebouncer.maybeExecute(e.target.value); + * }; + * + * // Access the selected state (will be empty object {} unless selector provided) + * const { isPending } = searchDebouncer.state; + * ``` + */ +export function useDebouncer( + fn: TFn, + options: DebouncerOptions, + selector: (state: DebouncerState) => TSelected = () => ({}) as TSelected, +): PreactDebouncer { + const mergedOptions = { + ...useDefaultPacerOptions().debouncer, + ...options, + } as DebouncerOptions + + const [debouncer] = useState(() => new Debouncer(fn, mergedOptions)) + + debouncer.fn = fn + debouncer.setOptions(mergedOptions) + + useEffect(() => { + return () => { + debouncer.cancel() + } + }, [debouncer]) + + const state = useStore(debouncer.store, selector) + + return useMemo( + () => + ({ + ...debouncer, + state, + }) as PreactDebouncer, // omit `store` in favor of `state` + [debouncer, state], + ) +} diff --git a/packages/preact-pacer/src/index.ts b/packages/preact-pacer/src/index.ts new file mode 100644 index 00000000..7ab02da1 --- /dev/null +++ b/packages/preact-pacer/src/index.ts @@ -0,0 +1,56 @@ +// re-export everything from the core pacer package +export * from '@tanstack/pacer' + +// provider +export * from './provider/PacerProvider' + +/** + * Export every hook individually - DON'T export from barrel files + */ + +// async-batcher +export * from './async-batcher/useAsyncBatcher' +export * from './async-batcher/useAsyncBatchedCallback' + +// async-debouncer +export * from './async-debouncer/useAsyncDebouncer' +export * from './async-debouncer/useAsyncDebouncedCallback' + +// async-queuer +export * from './async-queuer/useAsyncQueuer' +export * from './async-queuer/useAsyncQueuedState' + +// async-rate-limiter +export * from './async-rate-limiter/useAsyncRateLimiter' +export * from './async-rate-limiter/useAsyncRateLimitedCallback' + +// async-throttler +export * from './async-throttler/useAsyncThrottler' +export * from './async-throttler/useAsyncThrottledCallback' + +// batcher +export * from './batcher/useBatcher' +export * from './batcher/useBatchedCallback' + +// debouncer +export * from './debouncer/useDebouncedCallback' +export * from './debouncer/useDebouncedState' +export * from './debouncer/useDebouncedValue' +export * from './debouncer/useDebouncer' + +// queuer +export * from './queuer/useQueuer' +export * from './queuer/useQueuedState' +export * from './queuer/useQueuedValue' + +// rate-limiter +export * from './rate-limiter/useRateLimitedCallback' +export * from './rate-limiter/useRateLimiter' +export * from './rate-limiter/useRateLimitedState' +export * from './rate-limiter/useRateLimitedValue' + +// throttler +export * from './throttler/useThrottledCallback' +export * from './throttler/useThrottledState' +export * from './throttler/useThrottledValue' +export * from './throttler/useThrottler' diff --git a/packages/preact-pacer/src/provider/PacerProvider.tsx b/packages/preact-pacer/src/provider/PacerProvider.tsx new file mode 100644 index 00000000..844c5b1b --- /dev/null +++ b/packages/preact-pacer/src/provider/PacerProvider.tsx @@ -0,0 +1,70 @@ +import { useContext, useMemo } from 'preact/hooks' +import { createContext } from 'preact' +import type { ComponentChildren } from 'preact' +import type { + AnyAsyncFunction, + AnyFunction, + AsyncBatcherOptions, + AsyncDebouncerOptions, + AsyncQueuerOptions, + AsyncRateLimiterOptions, + AsyncThrottlerOptions, + BatcherOptions, + DebouncerOptions, + QueuerOptions, + RateLimiterOptions, + ThrottlerOptions, +} from '@tanstack/pacer' + +export interface PacerProviderOptions { + asyncBatcher?: Partial> + asyncDebouncer?: Partial> + asyncQueuer?: Partial> + asyncRateLimiter?: Partial> + asyncThrottler?: Partial> + batcher?: Partial> + debouncer?: Partial> + queuer?: Partial> + rateLimiter?: Partial> + throttler?: Partial> +} + +interface PacerContextValue { + defaultOptions: PacerProviderOptions +} + +const PacerContext = createContext(null) + +export interface PacerProviderProps { + children: ComponentChildren + defaultOptions?: PacerProviderOptions +} + +const DEFAULT_OPTIONS: PacerProviderOptions = {} + +export function PacerProvider({ + children, + defaultOptions = DEFAULT_OPTIONS, +}: PacerProviderProps) { + const contextValue: PacerContextValue = useMemo( + () => ({ + defaultOptions, + }), + [defaultOptions], + ) + + return ( + + {children} + + ) +} + +export function usePacerContext() { + return useContext(PacerContext) +} + +export function useDefaultPacerOptions() { + const context = useContext(PacerContext) + return context?.defaultOptions ?? {} +} diff --git a/packages/preact-pacer/src/provider/index.ts b/packages/preact-pacer/src/provider/index.ts new file mode 100644 index 00000000..5f4fe385 --- /dev/null +++ b/packages/preact-pacer/src/provider/index.ts @@ -0,0 +1 @@ +export * from './PacerProvider' diff --git a/packages/preact-pacer/src/queuer/index.ts b/packages/preact-pacer/src/queuer/index.ts new file mode 100644 index 00000000..6809bb17 --- /dev/null +++ b/packages/preact-pacer/src/queuer/index.ts @@ -0,0 +1,5 @@ +export * from '@tanstack/pacer/queuer' + +export * from './useQueuer' +export * from './useQueuedState' +export * from './useQueuedValue' diff --git a/packages/preact-pacer/src/queuer/useQueuedState.ts b/packages/preact-pacer/src/queuer/useQueuedState.ts new file mode 100644 index 00000000..6714694f --- /dev/null +++ b/packages/preact-pacer/src/queuer/useQueuedState.ts @@ -0,0 +1,133 @@ +import { useQueuer } from './useQueuer' +import type { PreactQueuer } from './useQueuer' +import type { Queuer, QueuerOptions, QueuerState } from '@tanstack/pacer/queuer' + +/** + * A Preact hook that creates a queuer with managed state, combining Preact's useState with queuing functionality. + * This hook provides both the current queue state and queue control methods. + * + * The queue state is automatically updated whenever items are added, removed, or reordered in the queue. + * All queue operations are reflected in the state array returned by the hook. + * + * The queue can be started and stopped to automatically process items at a specified interval, + * making it useful as a scheduler. When started, it will process one item per tick, with an + * optional wait time between ticks. + * + * The hook returns a tuple containing: + * - The current queue state as an array + * - The queue instance with methods for queue manipulation + * + * ## State Management and Selector + * + * The hook uses TanStack Store for reactive state management via the underlying queuer instance. + * The `selector` parameter allows you to specify which queuer state changes will trigger a re-render, + * optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur. + * + * **By default, there will be no reactive state subscriptions** and you must opt-in to state + * tracking by providing a selector function. This prevents unnecessary re-renders and gives you + * full control over when your component updates. Only when you provide a selector will the + * component re-render when the selected state values change. + * + * Available queuer state properties: + * - `executionCount`: Number of items that have been processed by the queuer + * - `expirationCount`: Number of items that have been removed due to expiration + * - `isEmpty`: Whether the queuer has no items to process + * - `isFull`: Whether the queuer has reached its maximum capacity + * - `isIdle`: Whether the queuer is not currently processing any items + * - `isRunning`: Whether the queuer is active and will process items automatically + * - `items`: Array of items currently waiting to be processed + * - `itemTimestamps`: Timestamps when items were added for expiration tracking + * - `pendingTick`: Whether the queuer has a pending timeout for processing the next item + * - `rejectionCount`: Number of items that have been rejected from being added + * - `size`: Number of items currently in the queue + * - `status`: Current processing status ('idle' | 'running' | 'stopped') + * + * @example + * ```tsx + * // Default behavior - no reactive state subscriptions + * const [items, addItem, queue] = useQueuedState( + * (item) => console.log('Processing:', item), + * { + * initialItems: ['item1', 'item2'], + * started: true, + * wait: 1000, + * getPriority: (item) => item.priority + * } + * ); + * + * // Opt-in to re-render when queue contents change (optimized for displaying queue items) + * const [items, addItem, queue] = useQueuedState( + * (item) => console.log('Processing:', item), + * { started: true, wait: 1000 }, + * (state) => ({ + * items: state.items, + * size: state.size, + * isEmpty: state.isEmpty + * }) + * ); + * + * // Opt-in to re-render when processing state changes (optimized for loading indicators) + * const [items, addItem, queue] = useQueuedState( + * (item) => console.log('Processing:', item), + * { started: true, wait: 1000 }, + * (state) => ({ + * isRunning: state.isRunning, + * isIdle: state.isIdle, + * status: state.status, + * pendingTick: state.pendingTick + * }) + * ); + * + * // Opt-in to re-render when execution metrics change (optimized for stats display) + * const [items, addItem, queue] = useQueuedState( + * (item) => console.log('Processing:', item), + * { started: true, wait: 1000 }, + * (state) => ({ + * executionCount: state.executionCount, + * expirationCount: state.expirationCount, + * rejectionCount: state.rejectionCount + * }) + * ); + * + * // Add items to queue + * const handleAdd = (item) => { + * addItem(item); + * }; + * + * // Start automatic processing + * const startProcessing = () => { + * queue.start(); + * }; + * + * // Stop automatic processing + * const stopProcessing = () => { + * queue.stop(); + * }; + * + * // Manual processing still available + * const handleProcess = () => { + * const nextItem = queue.getNextItem(); + * if (nextItem) { + * processItem(nextItem); + * } + * }; + * + * // Access the selected queuer state (will be empty object {} unless selector provided) + * const { size, isRunning, executionCount } = queue.state; + * ``` + */ +export function useQueuedState< + TValue, + TSelected extends Pick, 'items'> = Pick< + QueuerState, + 'items' + >, +>( + fn: (item: TValue) => void, + options: QueuerOptions = {}, + selector?: (state: QueuerState) => TSelected, +): [Array, Queuer['addItem'], PreactQueuer] { + const queue = useQueuer(fn, options, selector) + + return [queue.state.items, queue.addItem, queue] +} diff --git a/packages/preact-pacer/src/queuer/useQueuedValue.ts b/packages/preact-pacer/src/queuer/useQueuedValue.ts new file mode 100644 index 00000000..83bafb3d --- /dev/null +++ b/packages/preact-pacer/src/queuer/useQueuedValue.ts @@ -0,0 +1,129 @@ +import { useEffect, useState } from 'preact/hooks' +import { useQueuedState } from './useQueuedState' +import type { PreactQueuer } from './useQueuer' +import type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer' + +/** + * A Preact hook that creates a queued value that processes state changes in order with an optional delay. + * This hook uses useQueuer internally to manage a queue of state changes and apply them sequentially. + * + * The queued value will process changes in the order they are received, with optional delays between + * processing each change. This is useful for handling state updates that need to be processed + * in a specific order, like animations or sequential UI updates. + * + * The hook returns a tuple containing: + * - The current queued value + * - The queuer instance with control methods + * + * ## State Management and Selector + * + * The hook uses TanStack Store for reactive state management via the underlying queuer instance. + * The `selector` parameter allows you to specify which queuer state changes will trigger a re-render, + * optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur. + * + * **By default, there will be no reactive state subscriptions** and you must opt-in to state + * tracking by providing a selector function. This prevents unnecessary re-renders and gives you + * full control over when your component updates. Only when you provide a selector will the + * component re-render when the selected state values change. + * + * Available queuer state properties: + * - `executionCount`: Number of items that have been processed by the queuer + * - `expirationCount`: Number of items that have been removed due to expiration + * - `isEmpty`: Whether the queuer has no items to process + * - `isFull`: Whether the queuer has reached its maximum capacity + * - `isIdle`: Whether the queuer is not currently processing any items + * - `isRunning`: Whether the queuer is active and will process items automatically + * - `items`: Array of items currently waiting to be processed + * - `itemTimestamps`: Timestamps when items were added for expiration tracking + * - `pendingTick`: Whether the queuer has a pending timeout for processing the next item + * - `rejectionCount`: Number of items that have been rejected from being added + * - `size`: Number of items currently in the queue + * - `status`: Current processing status ('idle' | 'running' | 'stopped') + * + * @example + * ```tsx + * // Default behavior - no reactive state subscriptions + * const [value, queuer] = useQueuedValue(initialValue, { + * wait: 500, // Wait 500ms between processing each change + * started: true // Start processing immediately + * }); + * + * // Opt-in to re-render when queue processing state changes (optimized for loading indicators) + * const [value, queuer] = useQueuedValue( + * initialValue, + * { wait: 500, started: true }, + * (state) => ({ + * isRunning: state.isRunning, + * isIdle: state.isIdle, + * status: state.status, + * pendingTick: state.pendingTick + * }) + * ); + * + * // Opt-in to re-render when queue contents change (optimized for displaying queue status) + * const [value, queuer] = useQueuedValue( + * initialValue, + * { wait: 500, started: true }, + * (state) => ({ + * size: state.size, + * isEmpty: state.isEmpty, + * isFull: state.isFull + * }) + * ); + * + * // Opt-in to re-render when execution metrics change (optimized for stats display) + * const [value, queuer] = useQueuedValue( + * initialValue, + * { wait: 500, started: true }, + * (state) => ({ + * executionCount: state.executionCount, + * expirationCount: state.expirationCount, + * rejectionCount: state.rejectionCount + * }) + * ); + * + * // Add changes to the queue + * const handleChange = (newValue) => { + * queuer.addItem(newValue); + * }; + * + * // Control the queue + * const pauseProcessing = () => { + * queuer.stop(); + * }; + * + * const resumeProcessing = () => { + * queuer.start(); + * }; + * + * // Access the selected queuer state (will be empty object {} unless selector provided) + * const { size, isRunning, executionCount } = queuer.state; + * ``` + */ +export function useQueuedValue< + TValue, + TSelected extends Pick, 'items'> = Pick< + QueuerState, + 'items' + >, +>( + initialValue: TValue, + options: QueuerOptions = {}, + selector?: (state: QueuerState) => TSelected, +): [TValue, PreactQueuer] { + const [value, setValue] = useState(initialValue) + + const [, addItem, queuer] = useQueuedState( + (item) => { + setValue(item) + }, + options, + selector, + ) + + useEffect(() => { + addItem(initialValue) + }, [initialValue, addItem]) + + return [value, queuer] +} diff --git a/packages/preact-pacer/src/queuer/useQueuer.ts b/packages/preact-pacer/src/queuer/useQueuer.ts new file mode 100644 index 00000000..b33ba55b --- /dev/null +++ b/packages/preact-pacer/src/queuer/useQueuer.ts @@ -0,0 +1,160 @@ +import { useMemo, useState } from 'preact/hooks' +import { Queuer } from '@tanstack/pacer/queuer' +import { useStore } from '@tanstack/preact-store' +import { useDefaultPacerOptions } from '../provider/PacerProvider' +import type { Store } from '@tanstack/preact-store' +import type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer' + +export interface PreactQueuer extends Omit< + Queuer, + 'store' +> { + /** + * Reactive state that will be updated and re-rendered when the queuer state changes + * + * Use this instead of `queuer.store.state` + */ + readonly state: Readonly + /** + * @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state. + * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally. + * Although, you can make the state reactive by using the `useStore` in your own usage. + */ + readonly store: Store>> +} + +/** + * A Preact hook that creates and manages a Queuer instance. + * + * This is a lower-level hook that provides direct access to the Queuer's functionality without + * any built-in state management. This allows you to integrate it with any state management solution + * you prefer (useState, Redux, Zustand, etc.) by utilizing the onItemsChange callback. + * + * For a hook with built-in state management, see useQueuedState. + * + * The Queuer extends the base Queue to add processing capabilities. Items are processed + * synchronously in order, with optional delays between processing each item. The queuer includes + * an internal tick mechanism that can be started and stopped, making it useful as a scheduler. + * When started, it will process one item per tick, with an optional wait time between ticks. + * + * By default uses FIFO (First In First Out) behavior, but can be configured for LIFO + * (Last In First Out) by specifying 'front' position when adding items. + * + * ## State Management and Selector + * + * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you + * to specify which state changes will trigger a re-render, optimizing performance by preventing + * unnecessary re-renders when irrelevant state changes occur. + * + * **By default, there will be no reactive state subscriptions** and you must opt-in to state + * tracking by providing a selector function. This prevents unnecessary re-renders and gives you + * full control over when your component updates. Only when you provide a selector will the + * component re-render when the selected state values change. + * + * Available state properties: + * - `executionCount`: Number of items that have been processed by the queuer + * - `expirationCount`: Number of items that have been removed due to expiration + * - `isEmpty`: Whether the queuer has no items to process + * - `isFull`: Whether the queuer has reached its maximum capacity + * - `isIdle`: Whether the queuer is not currently processing any items + * - `isRunning`: Whether the queuer is active and will process items automatically + * - `items`: Array of items currently waiting to be processed + * - `itemTimestamps`: Timestamps when items were added for expiration tracking + * - `pendingTick`: Whether the queuer has a pending timeout for processing the next item + * - `rejectionCount`: Number of items that have been rejected from being added + * - `size`: Number of items currently in the queue + * - `status`: Current processing status ('idle' | 'running' | 'stopped') + * + * @example + * ```tsx + * // Default behavior - no reactive state subscriptions + * const queue = useQueuer( + * (item) => console.log('Processing:', item), + * { started: true, wait: 1000 } + * ); + * + * // Opt-in to re-render when queue size changes (optimized for displaying queue length) + * const queue = useQueuer( + * (item) => console.log('Processing:', item), + * { started: true, wait: 1000 }, + * (state) => ({ + * size: state.size, + * isEmpty: state.isEmpty, + * isFull: state.isFull + * }) + * ); + * + * // Opt-in to re-render when processing state changes (optimized for loading indicators) + * const queue = useQueuer( + * (item) => console.log('Processing:', item), + * { started: true, wait: 1000 }, + * (state) => ({ + * isRunning: state.isRunning, + * isIdle: state.isIdle, + * status: state.status, + * pendingTick: state.pendingTick + * }) + * ); + * + * // Opt-in to re-render when execution metrics change (optimized for stats display) + * const queue = useQueuer( + * (item) => console.log('Processing:', item), + * { started: true, wait: 1000 }, + * (state) => ({ + * executionCount: state.executionCount, + * expirationCount: state.expirationCount, + * rejectionCount: state.rejectionCount + * }) + * ); + * + * // Example with custom state management and scheduling + * const [items, setItems] = useState([]); + * + * const queue = useQueuer( + * (item) => console.log('Processing:', item), + * { + * started: true, // Start processing immediately + * wait: 1000, // Process one item every second + * onItemsChange: (queue) => setItems(queue.peekAllItems()), + * getPriority: (item) => item.priority // Process higher priority items first + * } + * ); + * + * // Add items to process - they'll be handled automatically + * queue.addItem('task1'); + * queue.addItem('task2'); + * + * // Control the scheduler + * queue.stop(); // Pause processing + * queue.start(); // Resume processing + * + * // Access the selected state (will be empty object {} unless selector provided) + * const { size, isRunning, executionCount } = queue.state; + * ``` + */ +export function useQueuer( + fn: (item: TValue) => void, + options: QueuerOptions = {}, + selector: (state: QueuerState) => TSelected = () => ({}) as TSelected, +): PreactQueuer { + const mergedOptions = { + ...useDefaultPacerOptions().queuer, + ...options, + } as QueuerOptions + + const [queuer] = useState(() => new Queuer(fn, mergedOptions)) + + queuer.fn = fn + queuer.setOptions(mergedOptions) + + const state = useStore(queuer.store, selector) + + return useMemo( + () => + ({ + ...queuer, + state, + }) as PreactQueuer, // omit `store` in favor of `state` + [queuer, state], + ) +} diff --git a/packages/preact-pacer/src/rate-limiter/index.ts b/packages/preact-pacer/src/rate-limiter/index.ts new file mode 100644 index 00000000..a7ab0ab6 --- /dev/null +++ b/packages/preact-pacer/src/rate-limiter/index.ts @@ -0,0 +1,6 @@ +export * from '@tanstack/pacer/rate-limiter' + +export * from './useRateLimitedCallback' +export * from './useRateLimiter' +export * from './useRateLimitedState' +export * from './useRateLimitedValue' diff --git a/packages/preact-pacer/src/rate-limiter/useRateLimitedCallback.ts b/packages/preact-pacer/src/rate-limiter/useRateLimitedCallback.ts new file mode 100644 index 00000000..82bf7906 --- /dev/null +++ b/packages/preact-pacer/src/rate-limiter/useRateLimitedCallback.ts @@ -0,0 +1,68 @@ +import { useCallback } from 'preact/hooks' +import { useRateLimiter } from './useRateLimiter' +import type { AnyFunction } from '@tanstack/pacer/types' +import type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter' + +/** + * A Preact hook that creates a rate-limited version of a callback function. + * This hook is essentially a wrapper around the basic `rateLimiter` function + * that is exported from `@tanstack/pacer`, + * but optimized for Preact with reactive options and a stable function reference. + * + * Rate limiting is a simple "hard limit" approach - it allows all calls until the limit + * is reached, then blocks subsequent calls until the window resets. Unlike throttling + * or debouncing, it does not attempt to space out or intelligently collapse calls. + * This can lead to bursts of rapid executions followed by periods where all calls + * are blocked. + * + * The rate limiter supports two types of windows: + * - 'fixed': A strict window that resets after the window period. All executions within the window count + * towards the limit, and the window resets completely after the period. + * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more + * consistent rate of execution over time. + * + * For smoother execution patterns, consider: + * - useThrottledCallback: When you want consistent spacing between executions (e.g. UI updates) + * - useDebouncedCallback: When you want to collapse rapid calls into a single execution (e.g. search input) + * + * Rate limiting should primarily be used when you need to enforce strict limits, + * like API rate limits or other scenarios requiring hard caps on execution frequency. + * + * This hook provides a simpler API compared to `useRateLimiter`, making it ideal for basic + * rate limiting needs. However, it does not expose the underlying RateLimiter instance. + * + * For advanced usage requiring features like: + * - Manual cancellation + * - Access to execution counts + * - Custom useCallback dependencies + * + * Consider using the `useRateLimiter` hook instead. + * + * @example + * ```tsx + * // Rate limit API calls to maximum 5 calls per minute with a sliding window + * const makeApiCall = useRateLimitedCallback( + * (data: ApiData) => { + * return fetch('/api/endpoint', { method: 'POST', body: JSON.stringify(data) }); + * }, + * { + * limit: 5, + * window: 60000, // 1 minute + * windowType: 'sliding', + * onReject: () => { + * console.warn('API rate limit reached. Please wait before trying again.'); + * } + * } + * ); + * ``` + */ +export function useRateLimitedCallback( + fn: TFn, + options: RateLimiterOptions, +): (...args: Parameters) => boolean { + const rateLimitedFn = useRateLimiter(fn, options).maybeExecute + return useCallback( + (...args: Parameters) => rateLimitedFn(...args), + [rateLimitedFn], + ) +} diff --git a/packages/preact-pacer/src/rate-limiter/useRateLimitedState.ts b/packages/preact-pacer/src/rate-limiter/useRateLimitedState.ts new file mode 100644 index 00000000..bbfdb695 --- /dev/null +++ b/packages/preact-pacer/src/rate-limiter/useRateLimitedState.ts @@ -0,0 +1,124 @@ +import { useState } from 'preact/hooks' +import { useRateLimiter } from './useRateLimiter' +import type { Dispatch, StateUpdater } from 'preact/hooks' +import type { PreactRateLimiter } from './useRateLimiter' +import type { + RateLimiterOptions, + RateLimiterState, +} from '@tanstack/pacer/rate-limiter' + +/** + * A Preact hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window. + * This hook combines Preact's useState with rate limiting functionality to provide controlled state updates. + * + * Rate limiting is a simple "hard limit" approach - it allows all updates until the limit is reached, then blocks + * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out + * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates. + * + * The rate limiter supports two types of windows: + * - 'fixed': A strict window that resets after the window period. All updates within the window count + * towards the limit, and the window resets completely after the period. + * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more + * consistent rate of updates over time. + * + * For smoother update patterns, consider: + * - useThrottledState: When you want consistent spacing between updates (e.g. UI changes) + * - useDebouncedState: When you want to collapse rapid updates into a single update (e.g. search input) + * + * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits. + * + * The hook returns a tuple containing: + * - The rate-limited state value + * - A rate-limited setter function that respects the configured limits + * - The rateLimiter instance for additional control + * + * For more direct control over rate limiting without state management, + * consider using the lower-level useRateLimiter hook instead. + * + * ## State Management and Selector + * + * The hook uses TanStack Store for reactive state management via the underlying rate limiter instance. + * The `selector` parameter allows you to specify which rate limiter state changes will trigger a re-render, + * optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur. + * + * **By default, there will be no reactive state subscriptions** and you must opt-in to state + * tracking by providing a selector function. This prevents unnecessary re-renders and gives you + * full control over when your component updates. Only when you provide a selector will the + * component re-render when the selected state values change. + * + * Available rate limiter state properties: + * - `executionCount`: Number of function executions that have been completed + * - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations + * - `rejectionCount`: Number of function executions that have been rejected due to rate limiting + * + * @example + * ```tsx + * // Default behavior - no reactive state subscriptions + * const [value, setValue, rateLimiter] = useRateLimitedState(0, { + * limit: 5, + * window: 60000, + * windowType: 'sliding' + * }); + * + * // Opt-in to re-render when execution count changes (optimized for tracking successful updates) + * const [value, setValue, rateLimiter] = useRateLimitedState( + * 0, + * { limit: 5, window: 60000, windowType: 'sliding' }, + * (state) => ({ executionCount: state.executionCount }) + * ); + * + * // Opt-in to re-render when rejection count changes (optimized for tracking rate limit violations) + * const [value, setValue, rateLimiter] = useRateLimitedState( + * 0, + * { limit: 5, window: 60000, windowType: 'sliding' }, + * (state) => ({ rejectionCount: state.rejectionCount }) + * ); + * + * // Opt-in to re-render when execution times change (optimized for window calculations) + * const [value, setValue, rateLimiter] = useRateLimitedState( + * 0, + * { limit: 5, window: 60000, windowType: 'sliding' }, + * (state) => ({ executionTimes: state.executionTimes }) + * ); + * + * // With rejection callback and fixed window + * const [value, setValue] = useRateLimitedState(0, { + * limit: 3, + * window: 5000, + * windowType: 'fixed', + * onReject: (rateLimiter) => { + * alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`); + * } + * }); + * + * // Access rateLimiter methods if needed + * const handleSubmit = () => { + * const remaining = rateLimiter.getRemainingInWindow(); + * if (remaining > 0) { + * setValue(newValue); + * } else { + * showRateLimitWarning(); + * } + * }; + * + * // Access the selected rate limiter state (will be empty object {} unless selector provided) + * const { executionCount, rejectionCount } = rateLimiter.state; + * ``` + */ +export function useRateLimitedState( + value: TValue, + options: RateLimiterOptions>>, + selector?: (state: RateLimiterState) => TSelected, +): [ + TValue, + Dispatch>, + PreactRateLimiter>, TSelected>, +] { + const [rateLimitedValue, setRateLimitedValue] = useState(value) + const rateLimiter = useRateLimiter(setRateLimitedValue, options, selector) + return [ + rateLimitedValue, + rateLimiter.maybeExecute as Dispatch>, + rateLimiter, + ] +} diff --git a/packages/preact-pacer/src/rate-limiter/useRateLimitedValue.ts b/packages/preact-pacer/src/rate-limiter/useRateLimitedValue.ts new file mode 100644 index 00000000..b9ed85be --- /dev/null +++ b/packages/preact-pacer/src/rate-limiter/useRateLimitedValue.ts @@ -0,0 +1,110 @@ +import { useEffect } from 'preact/hooks' +import { useRateLimitedState } from './useRateLimitedState' +import type { Dispatch, StateUpdater } from 'preact/hooks' +import type { PreactRateLimiter } from './useRateLimiter' +import type { + RateLimiterOptions, + RateLimiterState, +} from '@tanstack/pacer/rate-limiter' + +/** + * A high-level Preact hook that creates a rate-limited version of a value that updates at most a certain number of times within a time window. + * This hook uses Preact's useState internally to manage the rate-limited state. + * + * Rate limiting is a simple "hard limit" approach - it allows all updates until the limit is reached, then blocks + * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out + * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates. + * + * The rate limiter supports two types of windows: + * - 'fixed': A strict window that resets after the window period. All updates within the window count + * towards the limit, and the window resets completely after the period. + * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more + * consistent rate of updates over time. + * + * For smoother update patterns, consider: + * - useThrottledValue: When you want consistent spacing between updates (e.g. UI changes) + * - useDebouncedValue: When you want to collapse rapid updates into a single update (e.g. search input) + * + * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits. + * + * The hook returns a tuple containing: + * - The rate-limited value that updates according to the configured rate limit + * - The rate limiter instance with control methods + * + * For more direct control over rate limiting behavior without Preact state management, + * consider using the lower-level useRateLimiter hook instead. + * + * ## State Management and Selector + * + * The hook uses TanStack Store for reactive state management via the underlying rate limiter instance. + * The `selector` parameter allows you to specify which rate limiter state changes will trigger a re-render, + * optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur. + * + * **By default, there will be no reactive state subscriptions** and you must opt-in to state + * tracking by providing a selector function. This prevents unnecessary re-renders and gives you + * full control over when your component updates. Only when you provide a selector will the + * component re-render when the selected state values change. + * + * Available rate limiter state properties: + * - `executionCount`: Number of function executions that have been completed + * - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations + * - `rejectionCount`: Number of function executions that have been rejected due to rate limiting + * + * @example + * ```tsx + * // Default behavior - no reactive state subscriptions + * const [rateLimitedValue, rateLimiter] = useRateLimitedValue(rawValue, { + * limit: 5, + * window: 60000, + * windowType: 'sliding' + * }); + * + * // Opt-in to re-render when execution count changes (optimized for tracking successful updates) + * const [rateLimitedValue, rateLimiter] = useRateLimitedValue( + * rawValue, + * { limit: 5, window: 60000, windowType: 'sliding' }, + * (state) => ({ executionCount: state.executionCount }) + * ); + * + * // Opt-in to re-render when rejection count changes (optimized for tracking rate limit violations) + * const [rateLimitedValue, rateLimiter] = useRateLimitedValue( + * rawValue, + * { limit: 5, window: 60000, windowType: 'sliding' }, + * (state) => ({ rejectionCount: state.rejectionCount }) + * ); + * + * // Opt-in to re-render when execution times change (optimized for window calculations) + * const [rateLimitedValue, rateLimiter] = useRateLimitedValue( + * rawValue, + * { limit: 5, window: 60000, windowType: 'sliding' }, + * (state) => ({ executionTimes: state.executionTimes }) + * ); + * + * // With rejection callback and fixed window + * const [rateLimitedValue, rateLimiter] = useRateLimitedValue(rawValue, { + * limit: 3, + * window: 5000, + * windowType: 'fixed', + * onReject: (rateLimiter) => { + * console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`); + * } + * }); + * + * // Access the selected rate limiter state (will be empty object {} unless selector provided) + * const { executionCount, rejectionCount } = rateLimiter.state; + * ``` + */ +export function useRateLimitedValue( + value: TValue, + options: RateLimiterOptions>>, + selector?: (state: RateLimiterState) => TSelected, +): [TValue, PreactRateLimiter>, TSelected>] { + const [rateLimitedValue, setRateLimitedValue, rateLimiter] = + useRateLimitedState(value, options, selector) + + useEffect(() => { + ;(setRateLimitedValue as (value: TValue) => void)(value) + }, [value, setRateLimitedValue]) + + return [rateLimitedValue, rateLimiter] +} diff --git a/packages/preact-pacer/src/rate-limiter/useRateLimiter.ts b/packages/preact-pacer/src/rate-limiter/useRateLimiter.ts new file mode 100644 index 00000000..07c37bbf --- /dev/null +++ b/packages/preact-pacer/src/rate-limiter/useRateLimiter.ts @@ -0,0 +1,169 @@ +import { useMemo, useState } from 'preact/hooks' +import { RateLimiter } from '@tanstack/pacer/rate-limiter' +import { useStore } from '@tanstack/preact-store' +import { useDefaultPacerOptions } from '../provider/PacerProvider' +import type { Store } from '@tanstack/preact-store' +import type { + RateLimiterOptions, + RateLimiterState, +} from '@tanstack/pacer/rate-limiter' +import type { AnyFunction } from '@tanstack/pacer/types' + +export interface PreactRateLimiter< + TFn extends AnyFunction, + TSelected = {}, +> extends Omit, 'store'> { + /** + * Reactive state that will be updated and re-rendered when the rate limiter state changes + * + * Use this instead of `rateLimiter.store.state` + */ + readonly state: Readonly + /** + * @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state. + * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally. + * Although, you can make the state reactive by using the `useStore` in your own usage. + */ + readonly store: Store> +} + +/** + * A low-level Preact hook that creates a `RateLimiter` instance to enforce rate limits on function execution. + * + * This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that + * you can integrate with any state management solution (useState, Redux, Zustand, Jotai, etc). + * + * Rate limiting is a simple "hard limit" approach that allows executions until a maximum count is reached within + * a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing, + * it does not attempt to space out or collapse executions intelligently. + * + * The rate limiter supports two types of windows: + * - 'fixed': A strict window that resets after the window period. All executions within the window count + * towards the limit, and the window resets completely after the period. + * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more + * consistent rate of execution over time. + * + * For smoother execution patterns: + * - Use throttling when you want consistent spacing between executions (e.g. UI updates) + * - Use debouncing when you want to collapse rapid-fire events (e.g. search input) + * - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits) + * + * ## State Management and Selector + * + * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you + * to specify which state changes will trigger a re-render, optimizing performance by preventing + * unnecessary re-renders when irrelevant state changes occur. + * + * **By default, there will be no reactive state subscriptions** and you must opt-in to state + * tracking by providing a selector function. This prevents unnecessary re-renders and gives you + * full control over when your component updates. Only when you provide a selector will the + * component re-render when the selected state values change. + * + * Available state properties: + * - `executionCount`: Number of function executions that have been completed + * - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations + * - `rejectionCount`: Number of function executions that have been rejected due to rate limiting + * + * The hook returns an object containing: + * - maybeExecute: The rate-limited function that respects the configured limits + * - getExecutionCount: Returns the number of successful executions + * - getRejectionCount: Returns the number of rejected executions due to rate limiting + * - getRemainingInWindow: Returns how many more executions are allowed in the current window + * - reset: Resets the execution counts and window timing + * + * @example + * ```tsx + * // Default behavior - no reactive state subscriptions + * const rateLimiter = useRateLimiter(apiCall, { + * limit: 5, + * window: 60000, + * windowType: 'sliding', + * }); + * + * // Opt-in to re-render when execution count changes (optimized for tracking successful executions) + * const rateLimiter = useRateLimiter( + * apiCall, + * { + * limit: 5, + * window: 60000, + * windowType: 'sliding', + * }, + * (state) => ({ executionCount: state.executionCount }) + * ); + * + * // Opt-in to re-render when rejection count changes (optimized for tracking rate limit violations) + * const rateLimiter = useRateLimiter( + * apiCall, + * { + * limit: 5, + * window: 60000, + * windowType: 'sliding', + * }, + * (state) => ({ rejectionCount: state.rejectionCount }) + * ); + * + * // Opt-in to re-render when execution times change (optimized for window calculations) + * const rateLimiter = useRateLimiter( + * apiCall, + * { + * limit: 5, + * window: 60000, + * windowType: 'sliding', + * }, + * (state) => ({ executionTimes: state.executionTimes }) + * ); + * + * // Multiple state properties - re-render when any of these change + * const rateLimiter = useRateLimiter( + * apiCall, + * { + * limit: 5, + * window: 60000, + * windowType: 'sliding', + * }, + * (state) => ({ + * executionCount: state.executionCount, + * rejectionCount: state.rejectionCount + * }) + * ); + * + * // Monitor rate limit status + * const handleClick = () => { + * const remaining = rateLimiter.getRemainingInWindow(); + * if (remaining > 0) { + * rateLimiter.maybeExecute(data); + * } else { + * showRateLimitWarning(); + * } + * }; + * + * // Access the selected state (will be empty object {} unless selector provided) + * const { executionCount, rejectionCount } = rateLimiter.state; + * ``` + */ +export function useRateLimiter( + fn: TFn, + options: RateLimiterOptions, + selector: (state: RateLimiterState) => TSelected = () => ({}) as TSelected, +): PreactRateLimiter { + const mergedOptions = { + ...useDefaultPacerOptions().rateLimiter, + ...options, + } as RateLimiterOptions + + const [rateLimiter] = useState(() => new RateLimiter(fn, mergedOptions)) + + rateLimiter.fn = fn + rateLimiter.setOptions(mergedOptions) + + const state = useStore(rateLimiter.store, selector) + + return useMemo( + () => + ({ + ...rateLimiter, + state, + }) as PreactRateLimiter, // omit `store` in favor of `state` + [rateLimiter, state], + ) +} diff --git a/packages/preact-pacer/src/throttler/index.ts b/packages/preact-pacer/src/throttler/index.ts new file mode 100644 index 00000000..aecd2eee --- /dev/null +++ b/packages/preact-pacer/src/throttler/index.ts @@ -0,0 +1,7 @@ +// re-export everything from the core pacer package, BUT ONLY from the throttler module +export * from '@tanstack/pacer/throttler' + +export * from './useThrottledCallback' +export * from './useThrottledState' +export * from './useThrottledValue' +export * from './useThrottler' diff --git a/packages/preact-pacer/src/throttler/useThrottledCallback.ts b/packages/preact-pacer/src/throttler/useThrottledCallback.ts new file mode 100644 index 00000000..863e327f --- /dev/null +++ b/packages/preact-pacer/src/throttler/useThrottledCallback.ts @@ -0,0 +1,52 @@ +import { useCallback } from 'preact/hooks' +import { useThrottler } from './useThrottler' +import type { ThrottlerOptions } from '@tanstack/pacer/throttler' +import type { AnyFunction } from '@tanstack/pacer/types' + +/** + * A Preact hook that creates a throttled version of a callback function. + * This hook is essentially a wrapper around the basic `throttle` function + * that is exported from `@tanstack/pacer`, + * but optimized for Preact with reactive options and a stable function reference. + * + * The throttled function will execute at most once within the specified wait time period, + * regardless of how many times it is called. If called multiple times during the wait period, + * only the first invocation will execute, and subsequent calls will be ignored until + * the wait period has elapsed. + * + * This hook provides a simpler API compared to `useThrottler`, making it ideal for basic + * throttling needs. However, it does not expose the underlying Throttler instance. + * + * For advanced usage requiring features like: + * - Manual cancellation + * - Access to execution counts + * - Custom useCallback dependencies + * + * Consider using the `useThrottler` hook instead. + * + * @example + * ```tsx + * // Throttle a window resize handler + * const handleResize = useThrottledCallback(() => { + * updateLayoutMeasurements(); + * }, { + * wait: 100 // Execute at most once every 100ms + * }); + * + * // Use in an event listener + * useEffect(() => { + * window.addEventListener('resize', handleResize); + * return () => window.removeEventListener('resize', handleResize); + * }, [handleResize]); + * ``` + */ +export function useThrottledCallback( + fn: TFn, + options: ThrottlerOptions, +): (...args: Parameters) => void { + const throttledFn = useThrottler(fn, options).maybeExecute + return useCallback( + (...args: Parameters) => throttledFn(...args), + [throttledFn], + ) +} diff --git a/packages/preact-pacer/src/throttler/useThrottledState.ts b/packages/preact-pacer/src/throttler/useThrottledState.ts new file mode 100644 index 00000000..27b69678 --- /dev/null +++ b/packages/preact-pacer/src/throttler/useThrottledState.ts @@ -0,0 +1,121 @@ +import { useState } from 'preact/hooks' +import { useThrottler } from './useThrottler' +import type { Dispatch, StateUpdater } from 'preact/hooks' +import type { PreactThrottler } from './useThrottler' +import type { + ThrottlerOptions, + ThrottlerState, +} from '@tanstack/pacer/throttler' + +/** + * A Preact hook that creates a throttled state value that updates at most once within a specified time window. + * This hook combines Preact's useState with throttling functionality to provide controlled state updates. + * + * Throttling ensures state updates occur at a controlled rate regardless of how frequently the setter is called. + * This is useful for rate-limiting expensive re-renders or operations that depend on rapidly changing state. + * + * The hook returns a tuple containing: + * - The throttled state value + * - A throttled setter function that respects the configured wait time + * - The throttler instance for additional control + * + * For more direct control over throttling without state management, + * consider using the lower-level useThrottler hook instead. + * + * ## State Management and Selector + * + * The hook uses TanStack Store for reactive state management via the underlying throttler instance. + * The `selector` parameter allows you to specify which throttler state changes will trigger a re-render, + * optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur. + * + * **By default, there will be no reactive state subscriptions** and you must opt-in to state + * tracking by providing a selector function. This prevents unnecessary re-renders and gives you + * full control over when your component updates. Only when you provide a selector will the + * component re-render when the selected state values change. + * + * Available throttler state properties: + * - `executionCount`: Number of function executions that have been completed + * - `lastArgs`: The arguments from the most recent call to maybeExecute + * - `lastExecutionTime`: Timestamp of the last function execution in milliseconds + * - `nextExecutionTime`: Timestamp when the next execution can occur in milliseconds + * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution + * - `status`: Current execution status ('disabled' | 'idle' | 'pending') + * + * @example + * ```tsx + * // Default behavior - no reactive state subscriptions + * const [value, setValue, throttler] = useThrottledState(0, { wait: 1000 }); + * + * // Opt-in to re-render when execution count changes (optimized for tracking executions) + * const [value, setValue, throttler] = useThrottledState( + * 0, + * { wait: 1000 }, + * (state) => ({ executionCount: state.executionCount }) + * ); + * + * // Opt-in to re-render when throttling state changes (optimized for loading indicators) + * const [value, setValue, throttler] = useThrottledState( + * 0, + * { wait: 1000 }, + * (state) => ({ + * isPending: state.isPending, + * status: state.status + * }) + * ); + * + * // Opt-in to re-render when timing information changes (optimized for timing displays) + * const [value, setValue, throttler] = useThrottledState( + * 0, + * { wait: 1000 }, + * (state) => ({ + * lastExecutionTime: state.lastExecutionTime, + * nextExecutionTime: state.nextExecutionTime + * }) + * ); + * + * // With custom leading/trailing behavior + * const [value, setValue] = useThrottledState(0, { + * wait: 1000, + * leading: true, // Update immediately on first change + * trailing: false // Skip trailing edge updates + * }); + * + * // Access throttler methods if needed + * const handleReset = () => { + * setValue(0); + * throttler.cancel(); // Cancel any pending updates + * }; + * + * // Access the selected throttler state (will be empty object {} unless selector provided) + * const { executionCount, isPending } = throttler.state; + * ``` + */ + +export function useThrottledState< + TValue, + TSelected = ThrottlerState>>, +>( + value: TValue, + options: ThrottlerOptions>>, + selector?: ( + state: ThrottlerState>>, + ) => TSelected, +): [ + TValue, + Dispatch>, + PreactThrottler>, TSelected>, +] { + const [throttledValue, setThrottledValue] = useState(value) + const throttler = useThrottler( + setThrottledValue, + options, + selector as ( + state: ThrottlerState>>, + ) => TSelected, + ) + return [ + throttledValue, + throttler.maybeExecute as Dispatch>, + throttler, + ] +} diff --git a/packages/preact-pacer/src/throttler/useThrottledValue.ts b/packages/preact-pacer/src/throttler/useThrottledValue.ts new file mode 100644 index 00000000..82a2f143 --- /dev/null +++ b/packages/preact-pacer/src/throttler/useThrottledValue.ts @@ -0,0 +1,107 @@ +import { useEffect } from 'preact/hooks' +import { useThrottledState } from './useThrottledState' +import type { Dispatch, StateUpdater } from 'preact/hooks' +import type { PreactThrottler } from './useThrottler' +import type { + ThrottlerOptions, + ThrottlerState, +} from '@tanstack/pacer/throttler' + +/** + * A high-level Preact hook that creates a throttled version of a value that updates at most once within a specified time window. + * This hook uses Preact's useState internally to manage the throttled state. + * + * Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes. + * This is useful for rate-limiting expensive re-renders or API calls that depend on rapidly changing values. + * + * The hook returns a tuple containing: + * - The throttled value that updates according to the leading/trailing edge behavior specified in the options + * - The throttler instance with control methods + * + * For more direct control over throttling behavior without Preact state management, + * consider using the lower-level useThrottler hook instead. + * + * ## State Management and Selector + * + * The hook uses TanStack Store for reactive state management via the underlying throttler instance. + * The `selector` parameter allows you to specify which throttler state changes will trigger a re-render, + * optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur. + * + * **By default, there will be no reactive state subscriptions** and you must opt-in to state + * tracking by providing a selector function. This prevents unnecessary re-renders and gives you + * full control over when your component updates. Only when you provide a selector will the + * component re-render when the selected state values change. + * + * Available throttler state properties: + * - `executionCount`: Number of function executions that have been completed + * - `lastArgs`: The arguments from the most recent call to maybeExecute + * - `lastExecutionTime`: Timestamp of the last function execution in milliseconds + * - `nextExecutionTime`: Timestamp when the next execution can occur in milliseconds + * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution + * - `status`: Current execution status ('disabled' | 'idle' | 'pending') + * + * @example + * ```tsx + * // Default behavior - no reactive state subscriptions + * const [throttledValue, throttler] = useThrottledValue(rawValue, { wait: 1000 }); + * + * // Opt-in to re-render when execution count changes (optimized for tracking executions) + * const [throttledValue, throttler] = useThrottledValue( + * rawValue, + * { wait: 1000 }, + * (state) => ({ executionCount: state.executionCount }) + * ); + * + * // Opt-in to re-render when throttling state changes (optimized for loading indicators) + * const [throttledValue, throttler] = useThrottledValue( + * rawValue, + * { wait: 1000 }, + * (state) => ({ + * isPending: state.isPending, + * status: state.status + * }) + * ); + * + * // Opt-in to re-render when timing information changes (optimized for timing displays) + * const [throttledValue, throttler] = useThrottledValue( + * rawValue, + * { wait: 1000 }, + * (state) => ({ + * lastExecutionTime: state.lastExecutionTime, + * nextExecutionTime: state.nextExecutionTime + * }) + * ); + * + * // With custom leading/trailing behavior + * const [throttledValue, throttler] = useThrottledValue(rawValue, { + * wait: 1000, + * leading: true, // Update immediately on first change + * trailing: false // Skip trailing edge updates + * }); + * + * // Access the selected throttler state (will be empty object {} unless selector provided) + * const { executionCount, isPending } = throttler.state; + * ``` + */ +export function useThrottledValue< + TValue, + TSelected = ThrottlerState>>, +>( + value: TValue, + options: ThrottlerOptions>>, + selector?: ( + state: ThrottlerState>>, + ) => TSelected, +): [TValue, PreactThrottler>, TSelected>] { + const [throttledValue, setThrottledValue, throttler] = useThrottledState( + value, + options, + selector, + ) + + useEffect(() => { + ;(setThrottledValue as (value: TValue) => void)(value) + }, [value, setThrottledValue]) + + return [throttledValue, throttler] +} diff --git a/packages/preact-pacer/src/throttler/useThrottler.ts b/packages/preact-pacer/src/throttler/useThrottler.ts new file mode 100644 index 00000000..7ebd7085 --- /dev/null +++ b/packages/preact-pacer/src/throttler/useThrottler.ts @@ -0,0 +1,141 @@ +import { useEffect, useMemo, useState } from 'preact/hooks' +import { Throttler } from '@tanstack/pacer/throttler' +import { useStore } from '@tanstack/preact-store' +import { useDefaultPacerOptions } from '../provider/PacerProvider' +import type { Store } from '@tanstack/preact-store' +import type { AnyFunction } from '@tanstack/pacer/types' +import type { + ThrottlerOptions, + ThrottlerState, +} from '@tanstack/pacer/throttler' + +export interface PreactThrottler< + TFn extends AnyFunction, + TSelected = {}, +> extends Omit, 'store'> { + /** + * Reactive state that will be updated and re-rendered when the throttler state changes + * + * Use this instead of `throttler.store.state` + */ + readonly state: Readonly + /** + * @deprecated Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state. + * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally. + * Although, you can make the state reactive by using the `useStore` in your own usage. + */ + readonly store: Store>> +} + +/** + * A low-level Preact hook that creates a `Throttler` instance that limits how often the provided function can execute. + * + * This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that + * you can integrate with any state management solution (useState, Redux, Zustand, Jotai, etc). For a simpler and higher-level hook that + * integrates directly with Preact's useState, see useThrottledState. + * + * Throttling ensures a function executes at most once within a specified time window, + * regardless of how many times it is called. This is useful for rate-limiting + * expensive operations or UI updates. + * + * ## State Management and Selector + * + * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you + * to specify which state changes will trigger a re-render, optimizing performance by preventing + * unnecessary re-renders when irrelevant state changes occur. + * + * **By default, there will be no reactive state subscriptions** and you must opt-in to state + * tracking by providing a selector function. This prevents unnecessary re-renders and gives you + * full control over when your component updates. Only when you provide a selector will the + * component re-render when the selected state values change. + * + * Available state properties: + * - `executionCount`: Number of function executions that have been completed + * - `lastArgs`: The arguments from the most recent call to maybeExecute + * - `lastExecutionTime`: Timestamp of the last function execution in milliseconds + * - `nextExecutionTime`: Timestamp when the next execution can occur in milliseconds + * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution + * - `status`: Current execution status ('disabled' | 'idle' | 'pending') + * + * @example + * ```tsx + * // Default behavior - no reactive state subscriptions + * const [value, setValue] = useState(0); + * const throttler = useThrottler(setValue, { wait: 1000 }); + * + * // Opt-in to re-render when execution count changes (optimized for tracking executions) + * const [value, setValue] = useState(0); + * const throttler = useThrottler( + * setValue, + * { wait: 1000 }, + * (state) => ({ executionCount: state.executionCount }) + * ); + * + * // Opt-in to re-render when throttling state changes (optimized for loading indicators) + * const [value, setValue] = useState(0); + * const throttler = useThrottler( + * setValue, + * { wait: 1000 }, + * (state) => ({ + * isPending: state.isPending, + * status: state.status + * }) + * ); + * + * // Opt-in to re-render when timing information changes (optimized for timing displays) + * const [value, setValue] = useState(0); + * const throttler = useThrottler( + * setValue, + * { wait: 1000 }, + * (state) => ({ + * lastExecutionTime: state.lastExecutionTime, + * nextExecutionTime: state.nextExecutionTime + * }) + * ); + * + * // With any state manager + * const throttler = useThrottler( + * (value) => stateManager.setState(value), + * { + * wait: 2000, + * leading: true, // Execute immediately on first call + * trailing: false // Skip trailing edge updates + * } + * ); + * + * // Access the selected state (will be empty object {} unless selector provided) + * const { executionCount, isPending } = throttler.state; + * ``` + */ +export function useThrottler( + fn: TFn, + options: ThrottlerOptions, + selector: (state: ThrottlerState) => TSelected = () => ({}) as TSelected, +): PreactThrottler { + const mergedOptions = { + ...useDefaultPacerOptions().throttler, + ...options, + } as ThrottlerOptions + + const [throttler] = useState(() => new Throttler(fn, mergedOptions)) + + throttler.fn = fn + throttler.setOptions(mergedOptions) + + const state = useStore(throttler.store, selector) + + useEffect(() => { + return () => { + throttler.cancel() + } + }, [throttler]) + + return useMemo( + () => + ({ + ...throttler, + state, + }) as PreactThrottler, // omit `store` in favor of `state` + [throttler, state], + ) +} diff --git a/packages/preact-pacer/src/types/index.ts b/packages/preact-pacer/src/types/index.ts new file mode 100644 index 00000000..bc0ca24c --- /dev/null +++ b/packages/preact-pacer/src/types/index.ts @@ -0,0 +1 @@ +export * from '@tanstack/pacer/types' diff --git a/packages/preact-pacer/src/utils/index.ts b/packages/preact-pacer/src/utils/index.ts new file mode 100644 index 00000000..c5c19a2a --- /dev/null +++ b/packages/preact-pacer/src/utils/index.ts @@ -0,0 +1 @@ +export * from '@tanstack/pacer/utils' diff --git a/packages/preact-pacer/tsconfig.docs.json b/packages/preact-pacer/tsconfig.docs.json new file mode 100644 index 00000000..20ccb038 --- /dev/null +++ b/packages/preact-pacer/tsconfig.docs.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "paths": { + "@tanstack/pacer": ["../pacer/src"] + } + }, + "include": ["src"] +} diff --git a/packages/preact-pacer/tsconfig.json b/packages/preact-pacer/tsconfig.json new file mode 100644 index 00000000..675e1903 --- /dev/null +++ b/packages/preact-pacer/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "jsx": "react-jsx", + "jsxImportSource": "preact" + }, + "include": ["src", "vite.config.ts", "tests"], + "exclude": ["eslint.config.js"] +} diff --git a/packages/preact-pacer/tsdown.config.ts b/packages/preact-pacer/tsdown.config.ts new file mode 100644 index 00000000..cb988897 --- /dev/null +++ b/packages/preact-pacer/tsdown.config.ts @@ -0,0 +1,37 @@ +import { defineConfig } from 'tsdown' +import preact from '@preact/preset-vite' + +export default defineConfig({ + // Disable Prefresh for library builds. The consuming app's Vite dev server + // will inject its own Prefresh runtime, and double-injection breaks with + // "Identifier 'prevRefreshReg' has already been declared". + plugins: [preact({ prefreshEnabled: false })], + entry: [ + './src/index.ts', + './src/async-batcher/index.ts', + './src/async-debouncer/index.ts', + './src/async-queuer/index.ts', + './src/async-rate-limiter/index.ts', + './src/async-retryer/index.ts', + './src/async-throttler/index.ts', + './src/batcher/index.ts', + './src/debouncer/index.ts', + './src/provider/index.ts', + './src/queuer/index.ts', + './src/rate-limiter/index.ts', + './src/throttler/index.ts', + './src/types/index.ts', + './src/utils/index.ts', + ], + format: ['esm', 'cjs'], + unbundle: true, + dts: true, + sourcemap: true, + clean: true, + minify: false, + fixedExtension: false, + exports: true, + publint: { + strict: true, + }, +}) diff --git a/packages/preact-pacer/vitest.config.ts b/packages/preact-pacer/vitest.config.ts new file mode 100644 index 00000000..743da049 --- /dev/null +++ b/packages/preact-pacer/vitest.config.ts @@ -0,0 +1,15 @@ +import { defineConfig } from 'vitest/config' +import preact from '@preact/preset-vite' +import packageJson from './package.json' with { type: 'json' } + +export default defineConfig({ + plugins: [preact()], + test: { + name: packageJson.name, + dir: './tests', + watch: false, + environment: 'happy-dom', + // setupFiles: ['./tests/test-setup.ts'], + globals: true, + }, +}) diff --git a/packages/react-pacer-devtools/README.md b/packages/react-pacer-devtools/README.md index 42347dcc..5a42510f 100644 --- a/packages/react-pacer-devtools/README.md +++ b/packages/react-pacer-devtools/README.md @@ -89,9 +89,9 @@ A lightweight timing and scheduling library for debouncing, throttling, rate lim > You may know **TanSack Pacer** by our adapter names, too! > > - [**React Pacer**](https://tanstack.com/pacer/latest/docs/framework/react/react-pacer) +> - [**Preact Pacer**](https://tanstack.com/pacer/latest/docs/framework/preact/preact-pacer) > - [**Solid Pacer**](https://tanstack.com/pacer/latest/docs/framework/solid/solid-pacer) > - Angular Pacer - needs a contributor! -> - Preact Pacer - Coming soon! (After React Pacer is more fleshed out) > - Svelte Pacer - needs a contributor! > - Vue Pacer - needs a contributor! diff --git a/packages/react-pacer-devtools/package.json b/packages/react-pacer-devtools/package.json index 07c84727..179a1506 100644 --- a/packages/react-pacer-devtools/package.json +++ b/packages/react-pacer-devtools/package.json @@ -59,7 +59,7 @@ "@tanstack/pacer-devtools": "workspace:*" }, "devDependencies": { - "@eslint-react/eslint-plugin": "^2.3.12", + "@eslint-react/eslint-plugin": "^2.3.13", "@vitejs/plugin-react": "^5.1.2", "eslint-plugin-react-compiler": "19.1.0-rc.2", "eslint-plugin-react-hooks": "^7.0.1" diff --git a/packages/react-pacer/README.md b/packages/react-pacer/README.md index 42347dcc..5a42510f 100644 --- a/packages/react-pacer/README.md +++ b/packages/react-pacer/README.md @@ -89,9 +89,9 @@ A lightweight timing and scheduling library for debouncing, throttling, rate lim > You may know **TanSack Pacer** by our adapter names, too! > > - [**React Pacer**](https://tanstack.com/pacer/latest/docs/framework/react/react-pacer) +> - [**Preact Pacer**](https://tanstack.com/pacer/latest/docs/framework/preact/preact-pacer) > - [**Solid Pacer**](https://tanstack.com/pacer/latest/docs/framework/solid/solid-pacer) > - Angular Pacer - needs a contributor! -> - Preact Pacer - Coming soon! (After React Pacer is more fleshed out) > - Svelte Pacer - needs a contributor! > - Vue Pacer - needs a contributor! diff --git a/packages/react-pacer/package.json b/packages/react-pacer/package.json index a8d34229..1f970135 100644 --- a/packages/react-pacer/package.json +++ b/packages/react-pacer/package.json @@ -110,12 +110,12 @@ "@tanstack/react-store": "^0.8.0" }, "devDependencies": { - "@eslint-react/eslint-plugin": "^2.3.12", + "@eslint-react/eslint-plugin": "^2.3.13", "@types/react": "^19.2.7", "@vitejs/plugin-react": "^5.1.2", "eslint-plugin-react-compiler": "19.1.0-rc.2", "eslint-plugin-react-hooks": "^7.0.1", - "react": "^19.2.1" + "react": "^19.2.3" }, "peerDependencies": { "react": ">=16.8", diff --git a/packages/solid-pacer-devtools/README.md b/packages/solid-pacer-devtools/README.md index 42347dcc..5a42510f 100644 --- a/packages/solid-pacer-devtools/README.md +++ b/packages/solid-pacer-devtools/README.md @@ -89,9 +89,9 @@ A lightweight timing and scheduling library for debouncing, throttling, rate lim > You may know **TanSack Pacer** by our adapter names, too! > > - [**React Pacer**](https://tanstack.com/pacer/latest/docs/framework/react/react-pacer) +> - [**Preact Pacer**](https://tanstack.com/pacer/latest/docs/framework/preact/preact-pacer) > - [**Solid Pacer**](https://tanstack.com/pacer/latest/docs/framework/solid/solid-pacer) > - Angular Pacer - needs a contributor! -> - Preact Pacer - Coming soon! (After React Pacer is more fleshed out) > - Svelte Pacer - needs a contributor! > - Vue Pacer - needs a contributor! diff --git a/packages/solid-pacer/README.md b/packages/solid-pacer/README.md index 42347dcc..5a42510f 100644 --- a/packages/solid-pacer/README.md +++ b/packages/solid-pacer/README.md @@ -89,9 +89,9 @@ A lightweight timing and scheduling library for debouncing, throttling, rate lim > You may know **TanSack Pacer** by our adapter names, too! > > - [**React Pacer**](https://tanstack.com/pacer/latest/docs/framework/react/react-pacer) +> - [**Preact Pacer**](https://tanstack.com/pacer/latest/docs/framework/preact/preact-pacer) > - [**Solid Pacer**](https://tanstack.com/pacer/latest/docs/framework/solid/solid-pacer) > - Angular Pacer - needs a contributor! -> - Preact Pacer - Coming soon! (After React Pacer is more fleshed out) > - Svelte Pacer - needs a contributor! > - Vue Pacer - needs a contributor! diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 192fa745..ab69f01d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10,7 +10,7 @@ importers: devDependencies: '@changesets/cli': specifier: ^2.29.8 - version: 2.29.8(@types/node@24.10.1) + version: 2.29.8(@types/node@25.0.0) '@faker-js/faker': specifier: ^10.1.0 version: 10.1.0 @@ -22,7 +22,7 @@ importers: version: 1.2.0 '@tanstack/eslint-config': specifier: 0.3.4 - version: 0.3.4(@typescript-eslint/utils@8.48.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3))(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + version: 0.3.4(@typescript-eslint/utils@8.49.0(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3))(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) '@tanstack/typedoc-config': specifier: 0.3.3 version: 0.3.3(typescript@5.9.3) @@ -30,8 +30,8 @@ importers: specifier: ^6.9.1 version: 6.9.1 '@types/node': - specifier: ^24.10.1 - version: 24.10.1 + specifier: ^25.0.0 + version: 25.0.0 eslint: specifier: ^9.39.1 version: 9.39.1(jiti@2.6.1) @@ -42,14 +42,14 @@ importers: specifier: ^20.0.11 version: 20.0.11 knip: - specifier: ^5.72.0 - version: 5.72.0(@types/node@24.10.1)(typescript@5.9.3) + specifier: ^5.73.3 + version: 5.73.3(@types/node@25.0.0)(typescript@5.9.3) markdown-link-extractor: specifier: ^4.0.3 version: 4.0.3 nx: - specifier: ^22.2.0 - version: 22.2.0 + specifier: ^22.2.1 + version: 22.2.1 premove: specifier: ^4.0.0 version: 4.0.0 @@ -60,8 +60,8 @@ importers: specifier: ^3.4.0 version: 3.4.0(prettier@3.7.4)(svelte@5.45.5) publint: - specifier: ^0.3.15 - version: 0.3.15 + specifier: ^0.3.16 + version: 0.3.16 sherif: specifier: ^1.9.0 version: 1.9.0 @@ -73,13 +73,665 @@ importers: version: 0.2.15 tsdown: specifier: ^0.17.2 - version: 0.17.2(@arethetypeswrong/core@0.18.2)(oxc-resolver@11.15.0)(publint@0.3.15)(typescript@5.9.3) + version: 0.17.2(@arethetypeswrong/core@0.18.2)(oxc-resolver@11.15.0)(publint@0.3.16)(typescript@5.9.3) typescript: specifier: 5.9.3 version: 5.9.3 vitest: specifier: ^4.0.15 - version: 4.0.15(@types/node@24.10.1)(happy-dom@20.0.11)(jiti@2.6.1)(yaml@2.8.2) + version: 4.0.15(@types/node@25.0.0)(happy-dom@20.0.11)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/asyncBatch: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/asyncDebounce: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/asyncRateLimit: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/asyncRetry: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/asyncThrottle: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/batch: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/debounce: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/queue: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/rateLimit: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/throttle: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useAsyncBatchedCallback: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useAsyncBatcher: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useAsyncDebouncedCallback: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useAsyncDebouncer: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useAsyncQueuedState: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useAsyncQueuer: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useAsyncRateLimiter: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useAsyncRateLimiterWithPersister: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useAsyncThrottledCallback: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useAsyncThrottler: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useBatchedCallback: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useBatcher: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useDebouncedCallback: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useDebouncedState: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useDebouncedValue: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useDebouncer: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useQueuedState: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useQueuedValue: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useQueuer: + dependencies: + '@tanstack/preact-devtools': + specifier: ^0.9.2 + version: 0.9.2(csstype@3.2.3)(preact@10.28.0)(solid-js@1.9.10) + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + '@tanstack/preact-pacer-devtools': + specifier: workspace:* + version: link:../../../packages/preact-pacer-devtools + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useQueuerWithPersister: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useRateLimitedCallback: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useRateLimitedState: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useRateLimitedValue: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useRateLimiter: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useRateLimiterWithPersister: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useThrottledCallback: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useThrottledState: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useThrottledValue: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/useThrottler: + dependencies: + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + examples/preact/util-comparison: + dependencies: + '@tanstack/preact-devtools': + specifier: ^0.9.2 + version: 0.9.2(csstype@3.2.3)(preact@10.28.0)(solid-js@1.9.10) + '@tanstack/preact-pacer': + specifier: ^0.17.3 + version: link:../../../packages/preact-pacer + '@tanstack/preact-pacer-devtools': + specifier: workspace:* + version: link:../../../packages/preact-pacer-devtools + preact: + specifier: ^10.28.0 + version: 10.28.0 + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + vite: + specifier: ^7.2.7 + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/asyncBatch: dependencies: @@ -87,11 +739,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -101,10 +753,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/asyncDebounce: dependencies: @@ -112,11 +764,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -126,10 +778,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/asyncRateLimit: dependencies: @@ -137,11 +789,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -151,10 +803,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/asyncRetry: dependencies: @@ -162,11 +814,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -176,10 +828,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/asyncThrottle: dependencies: @@ -187,11 +839,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -201,10 +853,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/batch: dependencies: @@ -212,11 +864,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -226,10 +878,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/debounce: dependencies: @@ -237,11 +889,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -251,10 +903,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/queue: dependencies: @@ -262,15 +914,15 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@tanstack/react-devtools': specifier: 0.8.4 - version: 0.8.4(@types/react-dom@19.2.3(@types/react@19.2.7))(@types/react@19.2.7)(csstype@3.2.3)(react-dom@19.2.1(react@19.2.1))(react@19.2.1)(solid-js@1.9.10) + version: 0.8.4(@types/react-dom@19.2.3(@types/react@19.2.7))(@types/react@19.2.7)(csstype@3.2.3)(react-dom@19.2.3(react@19.2.3))(react@19.2.3)(solid-js@1.9.10) '@tanstack/react-pacer-devtools': specifier: 0.4.1 version: link:../../../packages/react-pacer-devtools @@ -282,10 +934,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/rateLimit: dependencies: @@ -293,11 +945,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -307,10 +959,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/react-query-debounced-prefetch: dependencies: @@ -319,16 +971,16 @@ importers: version: link:../../../packages/react-pacer '@tanstack/react-query': specifier: ^5.90.12 - version: 5.90.12(react@19.2.1) + version: 5.90.12(react@19.2.3) '@tanstack/react-query-devtools': specifier: ^5.91.1 - version: 5.91.1(@tanstack/react-query@5.90.12(react@19.2.1))(react@19.2.1) + version: 5.91.1(@tanstack/react-query@5.90.12(react@19.2.3))(react@19.2.3) react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -338,10 +990,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/react-query-queued-prefetch: dependencies: @@ -350,16 +1002,16 @@ importers: version: link:../../../packages/react-pacer '@tanstack/react-query': specifier: ^5.90.12 - version: 5.90.12(react@19.2.1) + version: 5.90.12(react@19.2.3) '@tanstack/react-query-devtools': specifier: ^5.91.1 - version: 5.91.1(@tanstack/react-query@5.90.12(react@19.2.1))(react@19.2.1) + version: 5.91.1(@tanstack/react-query@5.90.12(react@19.2.3))(react@19.2.3) react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -369,10 +1021,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/react-query-throttled-prefetch: dependencies: @@ -381,16 +1033,16 @@ importers: version: link:../../../packages/react-pacer '@tanstack/react-query': specifier: ^5.90.12 - version: 5.90.12(react@19.2.1) + version: 5.90.12(react@19.2.3) '@tanstack/react-query-devtools': specifier: ^5.91.1 - version: 5.91.1(@tanstack/react-query@5.90.12(react@19.2.1))(react@19.2.1) + version: 5.91.1(@tanstack/react-query@5.90.12(react@19.2.3))(react@19.2.3) react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -400,10 +1052,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/throttle: dependencies: @@ -411,11 +1063,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -425,10 +1077,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useAsyncBatchedCallback: dependencies: @@ -436,11 +1088,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -450,10 +1102,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useAsyncBatcher: dependencies: @@ -461,11 +1113,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -475,10 +1127,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useAsyncDebouncedCallback: dependencies: @@ -486,11 +1138,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -500,10 +1152,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useAsyncDebouncer: dependencies: @@ -511,11 +1163,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -525,10 +1177,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useAsyncQueuedState: dependencies: @@ -536,11 +1188,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -550,10 +1202,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useAsyncQueuer: dependencies: @@ -561,11 +1213,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -575,10 +1227,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useAsyncRateLimiter: dependencies: @@ -587,13 +1239,13 @@ importers: version: link:../../../packages/react-pacer '@tanstack/react-persister': specifier: ^0.1.1 - version: 0.1.1(react-dom@19.2.1(react@19.2.1))(react@19.2.1) + version: 0.1.1(react-dom@19.2.3(react@19.2.3))(react@19.2.3) react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -603,10 +1255,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useAsyncRateLimiterWithPersister: dependencies: @@ -615,13 +1267,13 @@ importers: version: link:../../../packages/react-pacer '@tanstack/react-persister': specifier: ^0.1.1 - version: 0.1.1(react-dom@19.2.1(react@19.2.1))(react@19.2.1) + version: 0.1.1(react-dom@19.2.3(react@19.2.3))(react@19.2.3) react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -631,10 +1283,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useAsyncThrottledCallback: dependencies: @@ -642,11 +1294,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -656,10 +1308,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useAsyncThrottler: dependencies: @@ -667,11 +1319,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -681,10 +1333,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useBatchedCallback: dependencies: @@ -692,11 +1344,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -706,10 +1358,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useBatcher: dependencies: @@ -717,11 +1369,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -731,10 +1383,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useDebouncedCallback: dependencies: @@ -742,11 +1394,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -756,10 +1408,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useDebouncedState: dependencies: @@ -767,11 +1419,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -781,10 +1433,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useDebouncedValue: dependencies: @@ -792,11 +1444,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -806,10 +1458,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useDebouncer: dependencies: @@ -817,11 +1469,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -831,10 +1483,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useQueuedState: dependencies: @@ -842,11 +1494,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -856,10 +1508,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useQueuedValue: dependencies: @@ -867,11 +1519,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -881,10 +1533,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useQueuer: dependencies: @@ -893,17 +1545,17 @@ importers: version: link:../../../packages/react-pacer '@tanstack/react-persister': specifier: ^0.1.1 - version: 0.1.1(react-dom@19.2.1(react@19.2.1))(react@19.2.1) + version: 0.1.1(react-dom@19.2.3(react@19.2.3))(react@19.2.3) react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@tanstack/react-devtools': specifier: 0.8.4 - version: 0.8.4(@types/react-dom@19.2.3(@types/react@19.2.7))(@types/react@19.2.7)(csstype@3.2.3)(react-dom@19.2.1(react@19.2.1))(react@19.2.1)(solid-js@1.9.10) + version: 0.8.4(@types/react-dom@19.2.3(@types/react@19.2.7))(@types/react@19.2.7)(csstype@3.2.3)(react-dom@19.2.3(react@19.2.3))(react@19.2.3)(solid-js@1.9.10) '@tanstack/react-pacer-devtools': specifier: 0.4.1 version: link:../../../packages/react-pacer-devtools @@ -915,10 +1567,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useQueuerWithPersister: dependencies: @@ -927,13 +1579,13 @@ importers: version: link:../../../packages/react-pacer '@tanstack/react-persister': specifier: ^0.1.1 - version: 0.1.1(react-dom@19.2.1(react@19.2.1))(react@19.2.1) + version: 0.1.1(react-dom@19.2.3(react@19.2.3))(react@19.2.3) react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -943,10 +1595,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useRateLimitedCallback: dependencies: @@ -954,11 +1606,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -968,10 +1620,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useRateLimitedState: dependencies: @@ -979,11 +1631,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -993,10 +1645,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useRateLimitedValue: dependencies: @@ -1004,11 +1656,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -1018,10 +1670,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useRateLimiter: dependencies: @@ -1030,13 +1682,13 @@ importers: version: link:../../../packages/react-pacer '@tanstack/react-persister': specifier: ^0.1.1 - version: 0.1.1(react-dom@19.2.1(react@19.2.1))(react@19.2.1) + version: 0.1.1(react-dom@19.2.3(react@19.2.3))(react@19.2.3) react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -1046,10 +1698,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useRateLimiterWithPersister: dependencies: @@ -1058,13 +1710,13 @@ importers: version: link:../../../packages/react-pacer '@tanstack/react-persister': specifier: ^0.1.1 - version: 0.1.1(react-dom@19.2.1(react@19.2.1))(react@19.2.1) + version: 0.1.1(react-dom@19.2.3(react@19.2.3))(react@19.2.3) react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -1074,10 +1726,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useThrottledCallback: dependencies: @@ -1085,11 +1737,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -1099,10 +1751,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useThrottledState: dependencies: @@ -1110,11 +1762,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -1124,10 +1776,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useThrottledValue: dependencies: @@ -1135,11 +1787,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -1149,10 +1801,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/useThrottler: dependencies: @@ -1160,11 +1812,11 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@types/react': specifier: ^19.2.7 @@ -1174,10 +1826,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/react/util-comparison: dependencies: @@ -1185,15 +1837,15 @@ importers: specifier: ^0.17.4 version: link:../../../packages/react-pacer react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 react-dom: - specifier: ^19.2.1 - version: 19.2.1(react@19.2.1) + specifier: ^19.2.3 + version: 19.2.3(react@19.2.3) devDependencies: '@tanstack/react-devtools': specifier: 0.8.4 - version: 0.8.4(@types/react-dom@19.2.3(@types/react@19.2.7))(@types/react@19.2.7)(csstype@3.2.3)(react-dom@19.2.1(react@19.2.1))(react@19.2.1)(solid-js@1.9.10) + version: 0.8.4(@types/react-dom@19.2.3(@types/react@19.2.7))(@types/react@19.2.7)(csstype@3.2.3)(react-dom@19.2.3(react@19.2.3))(react@19.2.3)(solid-js@1.9.10) '@tanstack/react-pacer-devtools': specifier: 0.4.1 version: link:../../../packages/react-pacer-devtools @@ -1205,10 +1857,10 @@ importers: version: 19.2.3(@types/react@19.2.7) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/solid/asyncBatch: dependencies: @@ -1221,10 +1873,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/asyncDebounce: dependencies: @@ -1237,10 +1889,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/asyncRateLimit: dependencies: @@ -1253,10 +1905,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/asyncThrottle: dependencies: @@ -1269,10 +1921,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/batch: dependencies: @@ -1285,10 +1937,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/createAsyncBatcher: dependencies: @@ -1301,10 +1953,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/createAsyncDebouncer: dependencies: @@ -1317,10 +1969,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/createAsyncQueuer: dependencies: @@ -1333,10 +1985,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/createAsyncRateLimiter: dependencies: @@ -1349,10 +2001,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/createAsyncThrottler: dependencies: @@ -1365,10 +2017,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/createBatcher: dependencies: @@ -1381,10 +2033,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/createDebouncedSignal: dependencies: @@ -1397,10 +2049,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/createDebouncedValue: dependencies: @@ -1413,10 +2065,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/createDebouncer: dependencies: @@ -1429,10 +2081,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/createQueuedSignal: dependencies: @@ -1451,10 +2103,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/createQueuer: dependencies: @@ -1473,10 +2125,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/createRateLimitedSignal: dependencies: @@ -1489,10 +2141,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/createRateLimitedValue: dependencies: @@ -1505,10 +2157,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/createRateLimiter: dependencies: @@ -1521,10 +2173,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/createThrottledSignal: dependencies: @@ -1537,10 +2189,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/createThrottledValue: dependencies: @@ -1553,10 +2205,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/createThrottler: dependencies: @@ -1569,10 +2221,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/debounce: dependencies: @@ -1585,10 +2237,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/queue: dependencies: @@ -1607,10 +2259,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/rateLimit: dependencies: @@ -1623,10 +2275,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/solid/throttle: dependencies: @@ -1639,10 +2291,10 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) examples/vanilla/LiteBatcher: dependencies: @@ -1652,7 +2304,7 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/vanilla/LiteDebouncer: dependencies: @@ -1662,7 +2314,7 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/vanilla/LiteQueuer: dependencies: @@ -1672,7 +2324,7 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/vanilla/LiteRateLimiter: dependencies: @@ -1682,7 +2334,7 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/vanilla/LiteThrottler: dependencies: @@ -1692,7 +2344,7 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/vanilla/liteBatch: dependencies: @@ -1702,7 +2354,7 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/vanilla/liteDebounce: dependencies: @@ -1712,7 +2364,7 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/vanilla/liteQueue: dependencies: @@ -1722,7 +2374,7 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/vanilla/liteRateLimit: dependencies: @@ -1732,7 +2384,7 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) examples/vanilla/liteThrottle: dependencies: @@ -1742,7 +2394,7 @@ importers: devDependencies: vite: specifier: ^7.2.7 - version: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + version: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) packages/pacer: dependencies: @@ -1760,7 +2412,7 @@ importers: version: 0.4.4(csstype@3.2.3)(solid-js@1.9.10) '@tanstack/devtools-utils': specifier: ^0.1.0 - version: 0.1.0(@types/react@19.2.7)(csstype@3.2.3)(react@19.2.1)(solid-js@1.9.10) + version: 0.1.0(@types/react@19.2.7)(csstype@3.2.3)(preact@10.28.0)(react@19.2.3)(solid-js@1.9.10) '@tanstack/pacer': specifier: '>=0.16.4' version: link:../pacer @@ -1782,7 +2434,7 @@ importers: devDependencies: vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) packages/pacer-lite: devDependencies: @@ -1790,6 +2442,44 @@ importers: specifier: workspace:* version: link:../pacer + packages/preact-pacer: + dependencies: + '@tanstack/pacer': + specifier: workspace:* + version: link:../pacer + '@tanstack/preact-store': + specifier: ^0.10.1 + version: 0.10.1(preact@10.28.0) + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + eslint-plugin-react-hooks: + specifier: ^7.0.1 + version: 7.0.1(eslint@9.39.1(jiti@2.6.1)) + preact: + specifier: ^10.28.0 + version: 10.28.0 + + packages/preact-pacer-devtools: + dependencies: + '@tanstack/devtools-utils': + specifier: ^0.1.0 + version: 0.1.0(@types/react@19.2.7)(csstype@3.2.3)(preact@10.28.0)(react@19.2.3)(solid-js@1.9.10) + '@tanstack/pacer-devtools': + specifier: workspace:* + version: link:../pacer-devtools + devDependencies: + '@preact/preset-vite': + specifier: ^2.10.2 + version: 2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + '@testing-library/preact': + specifier: ^3.2.4 + version: 3.2.4(preact@10.28.0) + preact: + specifier: ^10.28.0 + version: 10.28.0 + packages/react-pacer: dependencies: '@tanstack/pacer': @@ -1797,20 +2487,20 @@ importers: version: link:../pacer '@tanstack/react-store': specifier: ^0.8.0 - version: 0.8.0(react-dom@19.2.1(react@19.2.1))(react@19.2.1) + version: 0.8.0(react-dom@19.2.1(react@19.2.3))(react@19.2.3) react-dom: specifier: '>=16.8' - version: 19.2.1(react@19.2.1) + version: 19.2.1(react@19.2.3) devDependencies: '@eslint-react/eslint-plugin': - specifier: ^2.3.12 - version: 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + specifier: ^2.3.13 + version: 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) '@types/react': specifier: ^19.2.7 version: 19.2.7 '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) eslint-plugin-react-compiler: specifier: 19.1.0-rc.2 version: 19.1.0-rc.2(eslint@9.39.1(jiti@2.6.1)) @@ -1818,14 +2508,14 @@ importers: specifier: ^7.0.1 version: 7.0.1(eslint@9.39.1(jiti@2.6.1)) react: - specifier: ^19.2.1 - version: 19.2.1 + specifier: ^19.2.3 + version: 19.2.3 packages/react-pacer-devtools: dependencies: '@tanstack/devtools-utils': specifier: ^0.1.0 - version: 0.1.0(@types/react@19.2.7)(csstype@3.2.3)(react@19.2.1)(solid-js@1.9.10) + version: 0.1.0(@types/react@19.2.7)(preact@10.28.0)(react@19.2.1)(solid-js@1.9.10) '@tanstack/pacer-devtools': specifier: workspace:* version: link:../pacer-devtools @@ -1843,11 +2533,11 @@ importers: version: 19.2.1(react@19.2.1) devDependencies: '@eslint-react/eslint-plugin': - specifier: ^2.3.12 - version: 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + specifier: ^2.3.13 + version: 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) '@vitejs/plugin-react': specifier: ^5.1.2 - version: 5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) eslint-plugin-react-compiler: specifier: 19.1.0-rc.2 version: 19.1.0-rc.2(eslint@9.39.1(jiti@2.6.1)) @@ -1869,13 +2559,13 @@ importers: version: 1.9.10 vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) packages/solid-pacer-devtools: dependencies: '@tanstack/devtools-utils': specifier: ^0.1.0 - version: 0.1.0(@types/react@19.2.7)(csstype@3.2.3)(react@19.2.1)(solid-js@1.9.10) + version: 0.1.0(@types/react@19.2.7)(csstype@3.2.3)(preact@10.28.0)(react@19.2.3)(solid-js@1.9.10) '@tanstack/pacer-devtools': specifier: workspace:* version: link:../pacer-devtools @@ -1885,7 +2575,7 @@ importers: devDependencies: vite-plugin-solid: specifier: ^2.11.10 - version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + version: 2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) packages: @@ -2003,6 +2693,12 @@ packages: peerDependencies: '@babel/core': ^7.0.0-0 + '@babel/plugin-transform-react-jsx-development@7.27.1': + resolution: {integrity: sha512-ykDdF5yI4f1WrAolLqeF3hmYU12j9ntLQl/AOG1HAS21jxyg1Q0/J/tpREuYLfatGdGmXp/3yS0ZA76kOlVq9Q==} + engines: {node: '>=6.9.0'} + peerDependencies: + '@babel/core': ^7.0.0-0 + '@babel/plugin-transform-react-jsx-self@7.27.1': resolution: {integrity: sha512-6UzkCs+ejGdZ5mFFC/OCUrv028ab2fp1znZmCZjAOBKiBK2jXD1O+BPSfX8X2qjJ75fZBMSnQn3Rq2mrBJK2mw==} engines: {node: '>=6.9.0'} @@ -2015,6 +2711,12 @@ packages: peerDependencies: '@babel/core': ^7.0.0-0 + '@babel/plugin-transform-react-jsx@7.27.1': + resolution: {integrity: sha512-2KH4LWGSrJIkVf5tSiBFYuXDAoWRq2MMwgivCf+93dd0GQi8RXLjKA/0EvRnVV5G0hrHczsquXuD01L8s6dmBw==} + engines: {node: '>=6.9.0'} + peerDependencies: + '@babel/core': ^7.0.0-0 + '@babel/runtime@7.28.4': resolution: {integrity: sha512-Q/N6JNWvIvPnLDvjlE1OUBLPQHH6l3CltCEsHIujp45zQUSSh8K+gHnaEX45yAT1nyngnINhvWtzN+Nb9D8RAQ==} engines: {node: '>=6.9.0'} @@ -2423,40 +3125,40 @@ packages: resolution: {integrity: sha512-EriSTlt5OC9/7SXkRSCAhfSxxoSUgBm33OH+IkwbdpgoqsSsUg7y3uh+IICI/Qg4BBWr3U2i39RpmycbxMq4ew==} engines: {node: ^12.0.0 || ^14.0.0 || >=16.0.0} - '@eslint-react/ast@2.3.12': - resolution: {integrity: sha512-2wlRvqS4dxleGlL4Gp3Bh5PNb47wnAEa99CsGppzWCFXSPvm3d/bM5nJPvOwQOF53+PGa6xq1ZqwGh70zL7+zw==} + '@eslint-react/ast@2.3.13': + resolution: {integrity: sha512-OP2rOhHYLx2nfd9uA9uACKZJN9z9rX9uuAMx4PjT75JNOdYr1GgqWQZcYCepyJ+gmVNCyiXcLXuyhavqxCSM8Q==} engines: {node: '>=20.19.0'} peerDependencies: eslint: ^8.57.0 || ^9.0.0 typescript: '>=4.8.4 <6.0.0' - '@eslint-react/core@2.3.12': - resolution: {integrity: sha512-Q3w6f0WfVyIJriJa+tYHS4rmVQ3nwnubCH7o/VYlBCR3qczpvpvkCi2XK4clU/7vpVwHbbaXGICAbJu7tNZqoQ==} + '@eslint-react/core@2.3.13': + resolution: {integrity: sha512-4bWBE+1kApuxJKIrLJH2FuFtCbM4fXfDs6Ou8MNamGoX6hdynlntssvaMZTd/lk/L8dt01H/3btr7xBX4+4BNA==} engines: {node: '>=20.19.0'} peerDependencies: eslint: ^8.57.0 || ^9.0.0 typescript: '>=4.8.4 <6.0.0' - '@eslint-react/eff@2.3.12': - resolution: {integrity: sha512-QjFENG1VGVrD67YFc0yiLm9zef2kTeXZGux4hlMjGLnxTHnn0tPx4T/xGzh5C1WRmolcNeIzjVWMqSngFrTphQ==} + '@eslint-react/eff@2.3.13': + resolution: {integrity: sha512-byXsssozwh3VaiqcOonAKQgLXgpMVNSxBWFjdfbNhW7+NttorSt950qtiw+P7A9JoRab1OuGYk4MDY5UVBno8Q==} engines: {node: '>=20.19.0'} - '@eslint-react/eslint-plugin@2.3.12': - resolution: {integrity: sha512-/nrnrKINpsUEWIDfy7/YT4oGMvtyMUAJy6gm1nk3YLBrW9v6SVofcOnw2k6xwmB9Zl7RExlL58amlkdRpenkzA==} + '@eslint-react/eslint-plugin@2.3.13': + resolution: {integrity: sha512-gq0Z0wADAXvJS8Y/Wk3isK7WIEcfrQGGGdWvorAv0T7MxPd3d32TVwdc1Gx3hVLka3fYq1BBlQ5Fr8e1VgNuIg==} engines: {node: '>=20.19.0'} peerDependencies: eslint: ^8.57.0 || ^9.0.0 typescript: '>=4.8.4 <6.0.0' - '@eslint-react/shared@2.3.12': - resolution: {integrity: sha512-mIgxjEwKOknJabbQs/bxvkEhKitJnET0QDc0a89pFx36DBLJIEvdcGMCDEXFgtgjDV/WwMxIava/+coE6T3Dyw==} + '@eslint-react/shared@2.3.13': + resolution: {integrity: sha512-ESE7dVeOXtem3K6BD6k2wJaFt35kPtTT9SWCL99LFk7pym4OEGoMxPcyB2R7PMWiVudwl63BmiOgQOdaFYPONg==} engines: {node: '>=20.19.0'} peerDependencies: eslint: ^8.57.0 || ^9.0.0 typescript: '>=4.8.4 <6.0.0' - '@eslint-react/var@2.3.12': - resolution: {integrity: sha512-jjgeRcop74NTzWzCF8rBN1H5avdSDLEOALJjwmYWOdxoSUNGO7OIeM/pZvHZ7G36kHDuD619P2JauCVM2/c+7A==} + '@eslint-react/var@2.3.13': + resolution: {integrity: sha512-BozBfUZkzzobD6x/M8XERAnZQ3UvZPsD49zTGFKKU9M/bgsM78HwzxAPLkiu88W55v3sO/Kqf8fQTXT4VEeZ/g==} engines: {node: '>=20.19.0'} peerDependencies: eslint: ^8.57.0 || ^9.0.0 @@ -2588,53 +3290,53 @@ packages: resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} engines: {node: '>= 8'} - '@nx/nx-darwin-arm64@22.2.0': - resolution: {integrity: sha512-X50NmpoPdMgM37HfYFAySzzLpmR+OiLX0cxnmrAKID6hs1hVtTiPF5zvZ01W+9hU/G0kPfeEChHArUUIUC+jAg==} + '@nx/nx-darwin-arm64@22.2.1': + resolution: {integrity: sha512-GcISvKjB0GiD8lpM3kNkpYplaXzfGWJA0ApOrqRvhKU9HB/pwKtnN+nMdkIWKs74Dlizm2WnDNVfS7eXEmpCvg==} cpu: [arm64] os: [darwin] - '@nx/nx-darwin-x64@22.2.0': - resolution: {integrity: sha512-w85LW+hXKmKAlI4o9DmusMLV+wK+w7eKS/it5ObaU3Cel1faZRJBzXT08d7DZNI7frGivVSc6ISC1JZ+BYodnA==} + '@nx/nx-darwin-x64@22.2.1': + resolution: {integrity: sha512-Zikb50atIxdSm+zcrppuQ95STqXi1I2NWMzAxhnM3bw9Ty4mh4gIaXD9g0yp5O3AQYposkRl6+n1HXUwQHMMaA==} cpu: [x64] os: [darwin] - '@nx/nx-freebsd-x64@22.2.0': - resolution: {integrity: sha512-dtgdg6f0BLXdYd4BBGyPZ9yU7XYbPPrq0xxRjqXW7pWKXAL6palaouWPo1xsHfcopMhJYFpDJpuihZZMpPHgAw==} + '@nx/nx-freebsd-x64@22.2.1': + resolution: {integrity: sha512-zKiCxZ57o4NEx2wLIDuevCNy6X0gOU7vb74Qi6uNQ2lrZRXDlPTALdi4WKj2s3HaI2vTF2mkrxUKh6Ho/+PSqg==} cpu: [x64] os: [freebsd] - '@nx/nx-linux-arm-gnueabihf@22.2.0': - resolution: {integrity: sha512-5Y7qNEf8NYKlWK5F9V6Ib1eqDfJnUP+ZsQdPjp4rM4lwfpy+MIoLpPh0V3hkr+1jzMISR9ZV6Uh/M4I/frNORg==} + '@nx/nx-linux-arm-gnueabihf@22.2.1': + resolution: {integrity: sha512-6Mq4XQLL2fpo1upP98xXs9Bt1UTi0Et3Jxo3KZMlmIDgFl8LLYM/p0kCdWmCPNn9EPhM769Fe3O21BNlRHYqvQ==} cpu: [arm] os: [linux] - '@nx/nx-linux-arm64-gnu@22.2.0': - resolution: {integrity: sha512-vmu+nzv2Kjr6h/9mJix4kYM97WaMwfTEm0osaSHzYyA/DyKtrCuCLxRalXJvH4GuS8ZhDVdGKq2g0c2SE3sxMA==} + '@nx/nx-linux-arm64-gnu@22.2.1': + resolution: {integrity: sha512-HyGantAqciBEqu+fI4f58j7aEI9UCb7/AQHpKqgDdajgfA5RP0HgI0EGrSWnns8qPwZKMWCgeq5wp+lB/ukB9w==} cpu: [arm64] os: [linux] - '@nx/nx-linux-arm64-musl@22.2.0': - resolution: {integrity: sha512-kX47bMhmHWXOUQWYP3VlwnhEb9zqFq9KfI1qVSLjkgLbozKACE8f12DXLXw7cyc+iXl0fU+RjpELSAxAKY2gVA==} + '@nx/nx-linux-arm64-musl@22.2.1': + resolution: {integrity: sha512-fCTDiQxPSzTmRUAWODV4ZHSFA0BQ3wM+uGxpNtqTAvj2FL9O4LsVFH1c+mB6oVSjSfwMV/9+TztY40zsE35Btw==} cpu: [arm64] os: [linux] - '@nx/nx-linux-x64-gnu@22.2.0': - resolution: {integrity: sha512-cUsb+puiSYLFlbZwzX9FiNV5xYlm/9vEFcFWXOci2zCcJODr3/dPFTkgjwwJXWyNkkSCe+nptTjT6TTUlguTzw==} + '@nx/nx-linux-x64-gnu@22.2.1': + resolution: {integrity: sha512-bOmNt2zNUv9M7iS3FHg5RZRrkQc4yFsbf0wGwVkQpcsmFKPkXR6RdLfZg08Qr1lUsgVX+5nnqT8d5xXnoao/hg==} cpu: [x64] os: [linux] - '@nx/nx-linux-x64-musl@22.2.0': - resolution: {integrity: sha512-4HBAnRo1mKZEGoe8KczyLPigytMNjB9B5IMGJKGqkfaFUtcQjc0+weT1IxKGL9NYMKUU9L3RRf0IUd9vrjcRpQ==} + '@nx/nx-linux-x64-musl@22.2.1': + resolution: {integrity: sha512-dO08lbMhuBwvjzTADGEH8w+GSzobirpMt33hV/+Yuj35/SfsO2gwNCu72A2Fekh23MXODsO8gzAS0+0aqtvxXQ==} cpu: [x64] os: [linux] - '@nx/nx-win32-arm64-msvc@22.2.0': - resolution: {integrity: sha512-6UwsKD9uL3Iwj/D0RSrq2ByHAASnNg8ao4SxikJBXh1+lDPiY/7QxNZP8hzQHOJBh+bL11I/48QzA+j5pMevCw==} + '@nx/nx-win32-arm64-msvc@22.2.1': + resolution: {integrity: sha512-4cN4SoLgf004EFE7tlP6ibS/SDr986Urne3SgJhEnbrZv+GypEP+yJOnYejZArDnUDLAyeNe1Ha1aMy00p8AHg==} cpu: [arm64] os: [win32] - '@nx/nx-win32-x64-msvc@22.2.0': - resolution: {integrity: sha512-YXrpMtnVkw0PmoP++6ixPtmx2/Iu+SXoT3p2Hj7PgzYnSe6VQzI/mCN/X7QeOjq8VpC6/KIty+Rg9I9lsb9Hdw==} + '@nx/nx-win32-x64-msvc@22.2.1': + resolution: {integrity: sha512-N90PIFViLWurPOQq0dydtP060+GWuhiJwh840g6Gmzh/hOiv5545mx9tdKK+ZuCh01jKPbYU+tyDUkaGFrqtYA==} cpu: [x64] os: [win32] @@ -2741,6 +3443,29 @@ packages: cpu: [x64] os: [win32] + '@preact/preset-vite@2.10.2': + resolution: {integrity: sha512-K9wHlJOtkE+cGqlyQ5v9kL3Ge0Ql4LlIZjkUTL+1zf3nNdF88F9UZN6VTV8jdzBX9Fl7WSzeNMSDG7qECPmSmg==} + peerDependencies: + '@babel/core': 7.x + vite: 2.x || 3.x || 4.x || 5.x || 6.x || 7.x + + '@prefresh/babel-plugin@0.5.2': + resolution: {integrity: sha512-AOl4HG6dAxWkJ5ndPHBgBa49oo/9bOiJuRDKHLSTyH+Fd9x00shTXpdiTj1W41l6oQIwUOAgJeHMn4QwIDpHkA==} + + '@prefresh/core@1.5.9': + resolution: {integrity: sha512-IKBKCPaz34OFVC+adiQ2qaTF5qdztO2/4ZPf4KsRTgjKosWqxVXmEbxCiUydYZRY8GVie+DQlKzQr9gt6HQ+EQ==} + peerDependencies: + preact: ^10.0.0 || ^11.0.0-0 + + '@prefresh/utils@1.2.1': + resolution: {integrity: sha512-vq/sIuN5nYfYzvyayXI4C2QkprfNaHUQ9ZX+3xLD8nL3rWyzpxOm1+K7RtMbhd+66QcaISViK7amjnheQ/4WZw==} + + '@prefresh/vite@2.4.11': + resolution: {integrity: sha512-/XjURQqdRiCG3NpMmWqE9kJwrg9IchIOWHzulCfqg2sRe/8oQ1g5De7xrk9lbqPIQLn7ntBkKdqWXIj4E9YXyg==} + peerDependencies: + preact: ^10.4.0 || ^11.0.0-0 + vite: '>=2.0.0' + '@publint/pack@0.1.2': resolution: {integrity: sha512-S+9ANAvUmjutrshV4jZjaiG8XQyuJIZ8a4utWmN/vW1sgQ9IfBnPndwkmQYw53QmouOIytT874u65HEmu6H5jw==} engines: {node: '>=18'} @@ -2828,6 +3553,10 @@ packages: '@rolldown/pluginutils@1.0.0-beta.53': resolution: {integrity: sha512-vENRlFU4YbrwVqNDZ7fLvy+JR1CRkyr01jhSiDpE1u6py3OMzQfztQU2jxykW3ALNxO4kSlqIDeYyD0Y9RcQeQ==} + '@rollup/pluginutils@4.2.1': + resolution: {integrity: sha512-iKnFXr7NkdZAIHiIWE+BX5ULi/ucVFYWD6TbAV+rZctiRTY2PL6tsIKhoIOaoskiWAkgu+VsbXgUVDNLHf+InQ==} + engines: {node: '>= 8.0.0'} + '@rollup/rollup-android-arm-eabi@4.53.3': resolution: {integrity: sha512-mRSi+4cBjrRLoaal2PnqH82Wqyb+d3HsPUN/W+WslCXsZsyHa9ZeQQX/pQsZaVIWDkPcpV6jJ+3KLbTbgnwv8w==} cpu: [arm] @@ -3076,6 +3805,17 @@ packages: resolution: {integrity: sha512-XUewm2+D0K84ZSuWm1oMHfqw/flmO7IzCc+316php/XChgbMe30DStp1cF2Uc4IV0cI0G4hDq2RX3+NTxTIvWg==} engines: {node: '>=18'} + '@tanstack/preact-devtools@0.9.2': + resolution: {integrity: sha512-nhrjd5wVOxs04Wz3uiY4p1GNZ3PDMFEeeCe+OqpLWGW0QyJCqzokyqAjKNpPTDLDZ0mVEToXANqysIuKl2qOuA==} + engines: {node: '>=18'} + peerDependencies: + preact: '>=10.0.0' + + '@tanstack/preact-store@0.10.1': + resolution: {integrity: sha512-LLwm4vd38kz/db8Af8J0KQd4h6vapS8QW2r0iE6jJ3x33GQeXGsi/CGTUe5QBhEP1RnXgUaAlFNnmusfXloreQ==} + peerDependencies: + preact: ^10.0.0 + '@tanstack/query-core@5.90.12': resolution: {integrity: sha512-T1/8t5DhV/SisWjDnaiU2drl6ySvsHj1bHBCWNXd+/T+Hh1cf6JodyEYMd5sgwm+b/mETT4EV3H+zCVczCU5hg==} @@ -3133,16 +3873,29 @@ packages: resolution: {integrity: sha512-wVT2YfKDSpd+4f7fk6UaPIP3a2J7LSovlyVuFF1PH2yQb7gjqehod5zdFiwFyEXgvI9XGuFvvs1OehkKNYcr6A==} engines: {node: '>=18'} + '@testing-library/dom@8.20.1': + resolution: {integrity: sha512-/DiOQ5xBxgdYRC8LNk7U+RWat0S3qRLeIw3ZIkMQ9kkVlRmwD/Eg8k8CqIpD6GW7u20JIUOfMKbxtiLutpjQ4g==} + engines: {node: '>=12'} + '@testing-library/jest-dom@6.9.1': resolution: {integrity: sha512-zIcONa+hVtVSSep9UT3jZ5rizo2BsxgyDYU7WFD5eICBE7no3881HGeb/QkGfsJs6JTkY1aQhT7rIPC7e+0nnA==} engines: {node: '>=14', npm: '>=6', yarn: '>=1'} + '@testing-library/preact@3.2.4': + resolution: {integrity: sha512-F+kJ243LP6VmEK1M809unzTE/ijg+bsMNuiRN0JEDIJBELKKDNhdgC/WrUSZ7klwJvtlO3wQZ9ix+jhObG07Fg==} + engines: {node: '>= 12'} + peerDependencies: + preact: '>=10 || ^10.0.0-alpha.0 || ^10.0.0-beta.0' + '@tybys/wasm-util@0.10.1': resolution: {integrity: sha512-9tTaPJLSiejZKx+Bmog4uSubteqTvFrVrURwkmHixBo0G4seD0zUxp98E1DzUBJxLQ3NPwXrGKDiVjwx/DpPsg==} '@tybys/wasm-util@0.9.0': resolution: {integrity: sha512-6+7nlbMVX/PVDCwaIQ8nTOPveOcFLSt8GcXdx8hD0bt39uWxYT88uXzqTd4fTvqta7oeUJqudepapKNt2DYJFw==} + '@types/aria-query@5.0.4': + resolution: {integrity: sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw==} + '@types/babel__core@7.20.5': resolution: {integrity: sha512-qoQprZvz5wQFJwMDqeseRXWv3rqMvhgpbXFfVyWhbx9X47POIA6i/+dXefEmZKoAgOaTdaIgNSMqMIU61yRyzA==} @@ -3176,8 +3929,8 @@ packages: '@types/node@20.19.25': resolution: {integrity: sha512-ZsJzA5thDQMSQO788d7IocwwQbI8B5OPzmqNvpf3NY/+MHDAS759Wo0gd2WQeXYt5AAAQjzcrTVC6SKCuYgoCQ==} - '@types/node@24.10.1': - resolution: {integrity: sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ==} + '@types/node@25.0.0': + resolution: {integrity: sha512-rl78HwuZlaDIUSeUKkmogkhebA+8K1Hy7tddZuJ3D0xV8pZSfsYGTsliGUol1JPzu9EKnTxPC4L1fiWouStRew==} '@types/react-dom@19.2.3': resolution: {integrity: sha512-jp2L/eY6fn+KgVVQAOqYItbF0VY/YApe5Mz2F0aykSO8gx31bYCZyvSeYxCHKvzHG5eZjc+zyaS5BrBWya2+kQ==} @@ -3214,16 +3967,32 @@ packages: peerDependencies: typescript: '>=4.8.4 <6.0.0' + '@typescript-eslint/project-service@8.49.0': + resolution: {integrity: sha512-/wJN0/DKkmRUMXjZUXYZpD1NEQzQAAn9QWfGwo+Ai8gnzqH7tvqS7oNVdTjKqOcPyVIdZdyCMoqN66Ia789e7g==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + peerDependencies: + typescript: '>=4.8.4 <6.0.0' + '@typescript-eslint/scope-manager@8.48.1': resolution: {integrity: sha512-rj4vWQsytQbLxC5Bf4XwZ0/CKd362DkWMUkviT7DCS057SK64D5lH74sSGzhI6PDD2HCEq02xAP9cX68dYyg1w==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + '@typescript-eslint/scope-manager@8.49.0': + resolution: {integrity: sha512-npgS3zi+/30KSOkXNs0LQXtsg9ekZ8OISAOLGWA/ZOEn0ZH74Ginfl7foziV8DT+D98WfQ5Kopwqb/PZOaIJGg==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + '@typescript-eslint/tsconfig-utils@8.48.1': resolution: {integrity: sha512-k0Jhs4CpEffIBm6wPaCXBAD7jxBtrHjrSgtfCjUvPp9AZ78lXKdTR8fxyZO5y4vWNlOvYXRtngSZNSn+H53Jkw==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} peerDependencies: typescript: '>=4.8.4 <6.0.0' + '@typescript-eslint/tsconfig-utils@8.49.0': + resolution: {integrity: sha512-8prixNi1/6nawsRYxet4YOhnbW+W9FK/bQPxsGB1D3ZrDzbJ5FXw5XmzxZv82X3B+ZccuSxo/X8q9nQ+mFecWA==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + peerDependencies: + typescript: '>=4.8.4 <6.0.0' + '@typescript-eslint/type-utils@8.48.1': resolution: {integrity: sha512-1jEop81a3LrJQLTf/1VfPQdhIY4PlGDBc/i67EVWObrtvcziysbLN3oReexHOM6N3jyXgCrkBsZpqwH0hiDOQg==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -3231,16 +4000,33 @@ packages: eslint: ^8.57.0 || ^9.0.0 typescript: '>=4.8.4 <6.0.0' + '@typescript-eslint/type-utils@8.49.0': + resolution: {integrity: sha512-KTExJfQ+svY8I10P4HdxKzWsvtVnsuCifU5MvXrRwoP2KOlNZ9ADNEWWsQTJgMxLzS5VLQKDjkCT/YzgsnqmZg==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + peerDependencies: + eslint: ^8.57.0 || ^9.0.0 + typescript: '>=4.8.4 <6.0.0' + '@typescript-eslint/types@8.48.1': resolution: {integrity: sha512-+fZ3LZNeiELGmimrujsDCT4CRIbq5oXdHe7chLiW8qzqyPMnn1puNstCrMNVAqwcl2FdIxkuJ4tOs/RFDBVc/Q==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + '@typescript-eslint/types@8.49.0': + resolution: {integrity: sha512-e9k/fneezorUo6WShlQpMxXh8/8wfyc+biu6tnAqA81oWrEic0k21RHzP9uqqpyBBeBKu4T+Bsjy9/b8u7obXQ==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + '@typescript-eslint/typescript-estree@8.48.1': resolution: {integrity: sha512-/9wQ4PqaefTK6POVTjJaYS0bynCgzh6ClJHGSBj06XEHjkfylzB+A3qvyaXnErEZSaxhIo4YdyBgq6j4RysxDg==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} peerDependencies: typescript: '>=4.8.4 <6.0.0' + '@typescript-eslint/typescript-estree@8.49.0': + resolution: {integrity: sha512-jrLdRuAbPfPIdYNppHJ/D0wN+wwNfJ32YTAm10eJVsFmrVpXQnDWBn8niCSMlWjvml8jsce5E/O+86IQtTbJWA==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + peerDependencies: + typescript: '>=4.8.4 <6.0.0' + '@typescript-eslint/utils@8.48.1': resolution: {integrity: sha512-fAnhLrDjiVfey5wwFRwrweyRlCmdz5ZxXz2G/4cLn0YDLjTapmN4gcCsTBR1N2rWnZSDeWpYtgLDsJt+FpmcwA==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -3248,10 +4034,21 @@ packages: eslint: ^8.57.0 || ^9.0.0 typescript: '>=4.8.4 <6.0.0' + '@typescript-eslint/utils@8.49.0': + resolution: {integrity: sha512-N3W7rJw7Rw+z1tRsHZbK395TWSYvufBXumYtEGzypgMUthlg0/hmCImeA8hgO2d2G4pd7ftpxxul2J8OdtdaFA==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + peerDependencies: + eslint: ^8.57.0 || ^9.0.0 + typescript: '>=4.8.4 <6.0.0' + '@typescript-eslint/visitor-keys@8.48.1': resolution: {integrity: sha512-BmxxndzEWhE4TIEEMBs8lP3MBWN3jFPs/p6gPm/wkv02o41hI6cq9AuSmGAaTTHPtA1FTi2jBre4A9rm5ZmX+Q==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + '@typescript-eslint/visitor-keys@8.49.0': + resolution: {integrity: sha512-LlKaciDe3GmZFphXIc79THF/YYBugZ7FS1pO581E/edlVVNbZKDy93evqmrfQ9/Y4uN0vVhX4iuchq26mK/iiA==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + '@unrs/resolver-binding-android-arm-eabi@1.11.1': resolution: {integrity: sha512-ppLRUgHVaGRWUx0R0Ut06Mjo9gBaBkg3v/8AxusGLhsIotbBLuRk51rAzqLC8gq6NyyAojEXglNjzf6R948DNw==} cpu: [arm] @@ -3432,10 +4229,17 @@ packages: argparse@2.0.1: resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==} + aria-query@5.1.3: + resolution: {integrity: sha512-R5iJ5lkuHybztUfuOAznmboyjWq8O6sqNqtK7CLOqdydi54VNbORp49mb14KbWgG1QD3JFO9hJdZ+y4KutfdOQ==} + aria-query@5.3.2: resolution: {integrity: sha512-COROpnaoap1E2F000S62r6A60uHZnmlvomhfyT2DlTcrY1OrBKn2UhH7qn5wTC9zMvD0AY7csdPSNwKP+7WiQw==} engines: {node: '>= 0.4'} + array-buffer-byte-length@1.0.2: + resolution: {integrity: sha512-LHE+8BuR7RYGDKvnrmcuSq3tDcKv9OFEXQt/HpbZhY7V6h0zlUXutnAD82GiFx9rdieCMjkvtcsPqBwgUl1Iiw==} + engines: {node: '>= 0.4'} + array-union@2.1.0: resolution: {integrity: sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==} engines: {node: '>=8'} @@ -3451,6 +4255,10 @@ packages: asynckit@0.4.0: resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} + available-typed-arrays@1.0.7: + resolution: {integrity: sha512-wvUjBtSGN7+7SjNpq/9M2Tg350UZD3q62IFZLbRAR1bSMlCo1ZaeW+BJ+D090e4hIIZLBcTDWe4Mh4jvUDajzQ==} + engines: {node: '>= 0.4'} + axios@1.13.2: resolution: {integrity: sha512-VPk9ebNqPcy5lRGuSlKx752IlDatOjT9paPlm8A7yOuW2Fbvp4X3JznJtT4f0GzGLLiWE9W8onz51SqLYwzGaA==} @@ -3463,6 +4271,11 @@ packages: peerDependencies: '@babel/core': ^7.20.12 + babel-plugin-transform-hook-names@1.0.2: + resolution: {integrity: sha512-5gafyjyyBTTdX/tQQ0hRgu4AhNHG/hqWi0ZZmg2xvs2FgRkJXzDNKBZCyoYqgFkovfDrgM8OoKg8karoUvWeCw==} + peerDependencies: + '@babel/core': ^7.12.10 + babel-preset-solid@1.9.10: resolution: {integrity: sha512-HCelrgua/Y+kqO8RyL04JBWS/cVdrtUv/h45GntgQY+cJl4eBcKkCDV3TdMjtKx1nXwRaR9QXslM/Npm1dxdZQ==} peerDependencies: @@ -3478,8 +4291,8 @@ packages: base64-js@1.5.1: resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} - baseline-browser-mapping@2.9.0: - resolution: {integrity: sha512-Mh++g+2LPfzZToywfE1BUzvZbfOY52Nil0rn9H1CPC5DJ7fX+Vir7nToBeoiSbB1zTNeGYbELEvJESujgGrzXw==} + baseline-browser-mapping@2.9.3: + resolution: {integrity: sha512-8QdH6czo+G7uBsNo0GiUfouPN1lRzKdJTGnKXwe12gkFbnnOUaUKGN55dMkfy+mnxmvjwl9zcI4VncczcVXDhA==} hasBin: true better-path-resolve@1.0.0: @@ -3528,6 +4341,14 @@ packages: resolution: {integrity: sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==} engines: {node: '>= 0.4'} + call-bind@1.0.8: + resolution: {integrity: sha512-oKlSFMcMwpUg2ednkhQ454wfWiU/ul3CkJe/PEHcTKuiX6RpbehUiFMXu13HalGZxfUwCQzZG747YXBn1im9ww==} + engines: {node: '>= 0.4'} + + call-bound@1.0.4: + resolution: {integrity: sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==} + engines: {node: '>= 0.4'} + callsites@3.1.0: resolution: {integrity: sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==} engines: {node: '>=6'} @@ -3636,16 +4457,28 @@ packages: supports-color: optional: true + deep-equal@2.2.3: + resolution: {integrity: sha512-ZIwpnevOurS8bpT4192sqAowWM76JDKSHYzMLty3BZGSswgq6pBaH3DhCSW5xVAZICZyKdOBPjwww5wfgT/6PA==} + engines: {node: '>= 0.4'} + deep-is@0.1.4: resolution: {integrity: sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==} defaults@1.0.4: resolution: {integrity: sha512-eFuaLoy/Rxalv2kr+lqMlUnrDWV+3j4pljOIJgLIhI058IQfWJ7vXhyEIHu+HtC738klGALYxOKDO0bQP3tg8A==} + define-data-property@1.1.4: + resolution: {integrity: sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==} + engines: {node: '>= 0.4'} + define-lazy-prop@2.0.0: resolution: {integrity: sha512-Ds09qNh8yw3khSjiJjiUInaGX9xlqZDY7JVryGxdxV7NPeuqQfplOpQ66yJFZut3jLa5zOwkXw1g9EI2uKh4Og==} engines: {node: '>=8'} + define-properties@1.2.1: + resolution: {integrity: sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==} + engines: {node: '>= 0.4'} + delayed-stream@1.0.0: resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==} engines: {node: '>=0.4.0'} @@ -3661,6 +4494,9 @@ packages: resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==} engines: {node: '>=8'} + dom-accessibility-api@0.5.16: + resolution: {integrity: sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==} + dom-accessibility-api@0.6.3: resolution: {integrity: sha512-7ZgogeTnjuHbo+ct10G9Ffp0mif17idi0IyWNVA/wcwcm7NPOD/WEHVP3n7n3MhXqxoIYm8d6MuZohYWIZ4T3w==} @@ -3702,8 +4538,8 @@ packages: resolution: {integrity: sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==} engines: {node: '>= 0.4'} - electron-to-chromium@1.5.264: - resolution: {integrity: sha512-1tEf0nLgltC3iy9wtlYDlQDc5Rg9lEKVjEmIHJ21rI9OcqkvD45K1oyNIRA4rR1z3LgJ7KeGzEBojVcV6m4qjA==} + electron-to-chromium@1.5.266: + resolution: {integrity: sha512-kgWEglXvkEfMH7rxP5OSZZwnaDWT7J9EoZCujhnpLbfi0bbNtRkgdX2E3gt0Uer11c61qCYktB3hwkAS325sJg==} emoji-regex@8.0.0: resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} @@ -3746,6 +4582,9 @@ packages: resolution: {integrity: sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==} engines: {node: '>= 0.4'} + es-get-iterator@1.1.3: + resolution: {integrity: sha512-sPZmqHBe6JIiTfN5q2pEi//TwxmAFHwj/XEuYjTuse78i8KxaqMTTzxPoFKuzRpDpTJ+0NAbpfenkmH2rePtuw==} + es-module-lexer@1.7.0: resolution: {integrity: sha512-jEQoCwk8hyb2AZziIOLhDqpm5+2ww5uIE6lkO/6jcOCusfk6LhMHpXXfBLXTZ7Ydyt0j4VoUQv6uGNYbdW+kBA==} @@ -3825,15 +4664,15 @@ packages: peerDependencies: eslint: '>=7' - eslint-plugin-react-dom@2.3.12: - resolution: {integrity: sha512-GBiIANlm5267Ys+xM5AH74F5kzK43N1c6pm2oy+/P+tiZUpebIgEAilFGSAoAHqyyK1ul+kYsYr5Z8k2hP6aOw==} + eslint-plugin-react-dom@2.3.13: + resolution: {integrity: sha512-O9jglTOnnuyfJcSxjeVc8lqIp5kuS9/0MLLCHlOTH8ZjIifHHxUr6GZ2fd4la9y0FsoEYXEO7DBIMjWx2vCwjg==} engines: {node: '>=20.19.0'} peerDependencies: eslint: ^8.57.0 || ^9.0.0 typescript: '>=4.8.4 <6.0.0' - eslint-plugin-react-hooks-extra@2.3.12: - resolution: {integrity: sha512-6Dg8MMcDIGMTEguB5qanN1iERVEQIXmr7wC3hSR7pexmSASGLqer2MrM8VRa66aq28r5XmhTcNjKqh/R3Hetnw==} + eslint-plugin-react-hooks-extra@2.3.13: + resolution: {integrity: sha512-NSnY8yvtrvu2FAALLuvc2xesIAkMqGyJgilpy8wEi1w/Nw6v0IwBEffoNKLq9OHW4v3nikud3aBTqWfWKOx67Q==} engines: {node: '>=20.0.0'} peerDependencies: eslint: ^8.57.0 || ^9.0.0 @@ -3845,22 +4684,22 @@ packages: peerDependencies: eslint: ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0 || ^9.0.0 - eslint-plugin-react-naming-convention@2.3.12: - resolution: {integrity: sha512-2kTupCIdJaeuf8p2QuWckjGzyA+QiIuH6+kO8dZbuMw5dNdP3oJDtDZWLgMXk+WT8mdegu5a2Q9i2QjwxMKKbw==} + eslint-plugin-react-naming-convention@2.3.13: + resolution: {integrity: sha512-2iler1ldFpB/PaNpN8WAVk6dKYKwKcoGm1j0JAAjdCrsfOTJ007ol2xTAyoHKAbMOvkZSi7qq90q+Q//RuhWwA==} engines: {node: '>=20.19.0'} peerDependencies: eslint: ^8.57.0 || ^9.0.0 typescript: '>=4.8.4 <6.0.0' - eslint-plugin-react-web-api@2.3.12: - resolution: {integrity: sha512-9CWujvWbuwsBSrz2Ts4+NR996VKbDMbYv6ziHmmZLucHt3hZELF8eu5YHz99SLQeFzQynOMnZdR63ICr/dF+JA==} + eslint-plugin-react-web-api@2.3.13: + resolution: {integrity: sha512-+UypRPHP9GFMulIENpsC/J+TygWywiyz2mb4qyUP6y/IwdcSilk1MyF9WquNYKB/4/FN4Rl1oRm6WMbfkbpMnQ==} engines: {node: '>=20.19.0'} peerDependencies: eslint: ^8.57.0 || ^9.0.0 typescript: '>=4.8.4 <6.0.0' - eslint-plugin-react-x@2.3.12: - resolution: {integrity: sha512-G9ThX5LZQun3243JN/UchMbGPra9ZL1D7Wi4dwaIgqh26nRK8W6LBqRTJC+jlrmOanosg+flcxpUyFS/N+Ch7A==} + eslint-plugin-react-x@2.3.13: + resolution: {integrity: sha512-+m+V/5VLMxgx0VsFUUyflMNLQG0WFYspsfv0XJFqx7me3A2b3P20QatNDHQCYswz0PRbRFqinTPukPRhZh68ag==} engines: {node: '>=20.19.0'} peerDependencies: eslint: ^8.57.0 || ^9.0.0 @@ -3924,6 +4763,9 @@ packages: resolution: {integrity: sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==} engines: {node: '>=4.0'} + estree-walker@2.0.2: + resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==} + estree-walker@3.0.3: resolution: {integrity: sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==} @@ -4009,6 +4851,10 @@ packages: debug: optional: true + for-each@0.3.5: + resolution: {integrity: sha512-dKx12eRCVIzqCxFGplyFKJMPvLEWgmNtUrpTiJIR5u97zEhRG8ySrtboPHZXx7daLxQVrl643cTzbab2tkQjxg==} + engines: {node: '>= 0.4'} + form-data@4.0.5: resolution: {integrity: sha512-8RipRLol37bNs2bhoV67fiTEvdTrbMUYcFTiy3+wuuOnUog2QBHCZWXDRijWQfAkhBj2Uf5UnVaiWwA5vdd82w==} engines: {node: '>= 6'} @@ -4040,6 +4886,9 @@ packages: function-bind@1.1.2: resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==} + functions-have-names@1.2.3: + resolution: {integrity: sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==} + gensync@1.0.0-beta.2: resolution: {integrity: sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==} engines: {node: '>=6.9.0'} @@ -4105,10 +4954,17 @@ packages: resolution: {integrity: sha512-QsCdAUHAmiDeKeaNojb1OHOPF7NjcWPBR7obdu3NwH2a/oyQaLg5d0aaCy/9My6CdPChYF07dvz5chaXBGaD4g==} engines: {node: '>=20.0.0'} + has-bigints@1.1.0: + resolution: {integrity: sha512-R3pbpkcIqv2Pm3dUwgjclDRVmWpTJW2DcMzcIhEXEx1oh/CEMObMm3KLmRJOdvhM7o4uQBnwr8pzRK2sJWIqfg==} + engines: {node: '>= 0.4'} + has-flag@4.0.0: resolution: {integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==} engines: {node: '>=8'} + has-property-descriptors@1.0.2: + resolution: {integrity: sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==} + has-symbols@1.1.0: resolution: {integrity: sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==} engines: {node: '>= 0.4'} @@ -4121,6 +4977,10 @@ packages: resolution: {integrity: sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==} engines: {node: '>= 0.4'} + he@1.2.0: + resolution: {integrity: sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==} + hasBin: true + hermes-estree@0.25.1: resolution: {integrity: sha512-0wUoCcLp+5Ev5pDW2OriHC2MJCbwLwuRx+gAqMTOkGKJJiBCLjtrvy4PWUGn6MIVefecRpzoOZ/UV6iGdOr+Cw==} @@ -4181,6 +5041,34 @@ packages: inherits@2.0.4: resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} + internal-slot@1.1.0: + resolution: {integrity: sha512-4gd7VpWNQNB4UKKCFFVcp1AVv+FMOgs9NKzjHKusc8jTMhd5eL1NqQqOpE0KzMds804/yHlglp3uxgluOqAPLw==} + engines: {node: '>= 0.4'} + + is-arguments@1.2.0: + resolution: {integrity: sha512-7bVbi0huj/wrIAOzb8U1aszg9kdi3KN/CyU19CTI7tAoZYEZoL9yCDXpbXN+uPsuWnP02cyug1gleqq+TU+YCA==} + engines: {node: '>= 0.4'} + + is-array-buffer@3.0.5: + resolution: {integrity: sha512-DDfANUiiG2wC1qawP66qlTugJeL5HyzMpfr8lLK+jMQirGzNod0B12cFB/9q838Ru27sBwfw78/rdoU7RERz6A==} + engines: {node: '>= 0.4'} + + is-bigint@1.1.0: + resolution: {integrity: sha512-n4ZT37wG78iz03xPRKJrHTdZbe3IicyucEtdRsV5yglwc3GyUfbAfpSeD0FJ41NbUNSt5wbhqfp1fS+BgnvDFQ==} + engines: {node: '>= 0.4'} + + is-boolean-object@1.2.2: + resolution: {integrity: sha512-wa56o2/ElJMYqjCjGkXri7it5FbebW5usLw/nPmCMs5DeZ7eziSYZhSmPRn0txqeW4LnAmQQU7FgqLpsEFKM4A==} + engines: {node: '>= 0.4'} + + is-callable@1.2.7: + resolution: {integrity: sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==} + engines: {node: '>= 0.4'} + + is-date-object@1.1.0: + resolution: {integrity: sha512-PwwhEakHVKTdRNVOw+/Gyh0+MzlCl4R6qKvkhuvLtPMggI1WAHt9sOwZxQLSGpUaDnrdyDsomoRgNnCfKNSXXg==} + engines: {node: '>= 0.4'} + is-docker@2.2.1: resolution: {integrity: sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==} engines: {node: '>=8'} @@ -4208,6 +5096,14 @@ packages: resolution: {integrity: sha512-2HvIEKRoqS62guEC+qBjpvRubdX910WCMuJTZ+I9yvqKU2/12eSL549HMwtabb4oupdj2sMP50k+XJfB/8JE6w==} engines: {node: '>=8'} + is-map@2.0.3: + resolution: {integrity: sha512-1Qed0/Hr2m+YqxnM09CjA2d/i6YZNfF6R2oRAOj36eUdS6qIV/huPJNSEpKbupewFs+ZsJlxsjjPbc0/afW6Lw==} + engines: {node: '>= 0.4'} + + is-number-object@1.1.1: + resolution: {integrity: sha512-lZhclumE1G6VYD8VHe35wFaIif+CTy5SJIi5+3y4psDgWu4wPDoBhF8NxUOinEc7pHgiTsT6MaBb92rKhhD+Xw==} + engines: {node: '>= 0.4'} + is-number@7.0.0: resolution: {integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==} engines: {node: '>=0.12.0'} @@ -4215,14 +5111,42 @@ packages: is-reference@3.0.3: resolution: {integrity: sha512-ixkJoqQvAP88E6wLydLGGqCJsrFUnqoH6HnaczB8XmDH1oaWU+xxdptvikTgaEhtZ53Ky6YXiBuUI2WXLMCwjw==} + is-regex@1.2.1: + resolution: {integrity: sha512-MjYsKHO5O7mCsmRGxWcLWheFqN9DJ/2TmngvjKXihe6efViPqc274+Fx/4fYj/r03+ESvBdTXK0V6tA3rgez1g==} + engines: {node: '>= 0.4'} + + is-set@2.0.3: + resolution: {integrity: sha512-iPAjerrse27/ygGLxw+EBR9agv9Y6uLeYVJMu+QNCoouJ1/1ri0mGrcWpfCqFZuzzx3WjtwxG098X+n4OuRkPg==} + engines: {node: '>= 0.4'} + + is-shared-array-buffer@1.0.4: + resolution: {integrity: sha512-ISWac8drv4ZGfwKl5slpHG9OwPNty4jOWPRIhBpxOoD+hqITiwuipOQ2bNthAzwA3B4fIjO4Nln74N0S9byq8A==} + engines: {node: '>= 0.4'} + + is-string@1.1.1: + resolution: {integrity: sha512-BtEeSsoaQjlSPBemMQIrY1MY0uM6vnS1g5fmufYOtnxLGUZM2178PKbhsk7Ffv58IX+ZtcvoGwccYsh0PglkAA==} + engines: {node: '>= 0.4'} + is-subdir@1.2.0: resolution: {integrity: sha512-2AT6j+gXe/1ueqbW6fLZJiIw3F8iXGJtt0yDrZaBhAZEG1raiTxKWU+IPqMCzQAXOUCKdA4UDMgacKH25XG2Cw==} engines: {node: '>=4'} + is-symbol@1.1.1: + resolution: {integrity: sha512-9gGx6GTtCQM73BgmHQXfDmLtfjjTUDSyoxTCbp5WtoixAhfgsDirWIcVQ/IHpvI5Vgd5i/J5F7B9cN/WlVbC/w==} + engines: {node: '>= 0.4'} + is-unicode-supported@0.1.0: resolution: {integrity: sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==} engines: {node: '>=10'} + is-weakmap@2.0.2: + resolution: {integrity: sha512-K5pXYOm9wqY1RgjpL3YTkF39tni1XajUIkawTLUo9EZEVUFga5gSQJF8nNS7ZwJQ02y+1YCNYcMh+HIf1ZqE+w==} + engines: {node: '>= 0.4'} + + is-weakset@2.0.4: + resolution: {integrity: sha512-mfcwb6IzQyOKTs84CQMrOwW4gQcaTOAWJ0zzJCl2WSPDrWk/OzDaImWFH3djXhb24g4eudZfLRozAvPGw4d9hQ==} + engines: {node: '>= 0.4'} + is-what@4.1.16: resolution: {integrity: sha512-ZhMwEosbFJkA0YhFnNDgTM4ZxDRsS6HqTo7qsZM08fehyRYIYa0yHu5R6mgo1n/8MgaPBXiPimPD77baVFYg+A==} engines: {node: '>=12.13'} @@ -4235,6 +5159,9 @@ packages: resolution: {integrity: sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==} engines: {node: '>=8'} + isarray@2.0.5: + resolution: {integrity: sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==} + isexe@2.0.0: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} @@ -4285,14 +5212,17 @@ packages: keyv@4.5.4: resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==} - knip@5.72.0: - resolution: {integrity: sha512-rlyoXI8FcggNtM/QXd/GW0sbsYvNuA/zPXt7bsuVi6kVQogY2PDCr81bPpzNnl0CP8AkFm2Z2plVeL5QQSis2w==} + knip@5.73.3: + resolution: {integrity: sha512-676xuqNQidE9yZeUUX7lJeZ0d1N7QBTbmO1J0p+SyuXlbpdE4pd8Ql3WVMvrvaaaG2z/+3ExeFNm0Q9mVIjuKw==} engines: {node: '>=18.18.0'} hasBin: true peerDependencies: '@types/node': '>=18' typescript: '>=5.0.4 <7' + kolorist@1.8.0: + resolution: {integrity: sha512-Y+60/zizpJ3HRH8DCss+q95yr6145JXZo46OTpFvDZWLfRCE4qChOyk1b26nMaNpfHHgxagk9dXT5OP0Tfe+dQ==} + levn@0.4.1: resolution: {integrity: sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==} engines: {node: '>= 0.8.0'} @@ -4339,6 +5269,10 @@ packages: lunr@2.3.9: resolution: {integrity: sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow==} + lz-string@1.5.0: + resolution: {integrity: sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==} + hasBin: true + magic-string@0.30.21: resolution: {integrity: sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==} @@ -4444,6 +5378,9 @@ packages: encoding: optional: true + node-html-parser@6.1.13: + resolution: {integrity: sha512-qIsTMOY4C/dAa5Q5vsobRpOOvPfC4pB61UVW2uSwZNUp0QU/jCekTal1vMmbO0DgdHeLUJpv/ARmDqErVxA3Sg==} + node-machine-id@1.1.12: resolution: {integrity: sha512-QNABxbrPa3qEIfrE6GOJ7BYIuignnJw7iQ2YPbc3Nla1HzRJjXzZOiikfF8m7eAMfichLt3M4VgLOetqgDmgGQ==} @@ -4457,8 +5394,8 @@ packages: nth-check@2.1.1: resolution: {integrity: sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==} - nx@22.2.0: - resolution: {integrity: sha512-EOPtpGLA11jM8AJ7g8cLuhCHam0SANDsp1t1aalcx5fXIy/Av24XaHUKm1rk3lJHGLoGgfae0THg5OQ3JKJQ8g==} + nx@22.2.1: + resolution: {integrity: sha512-f/tDP9QKcJ0IjG3liHxZkJORPIPwcYiL0A7JsFMRYKVBjGiuvZ+qkAijjsVGdJBF7S7jJ7dy3oNCIZKevVru8w==} hasBin: true peerDependencies: '@swc-node/register': ^1.8.0 @@ -4469,6 +5406,22 @@ packages: '@swc/core': optional: true + object-inspect@1.13.4: + resolution: {integrity: sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==} + engines: {node: '>= 0.4'} + + object-is@1.1.6: + resolution: {integrity: sha512-F8cZ+KfGlSGi09lJT7/Nd6KJZ9ygtvYC0/UYYLI9nmQKLMnydpB9yvbv9K1uSkEu7FU9vYPmVwLg328tX+ot3Q==} + engines: {node: '>= 0.4'} + + object-keys@1.1.1: + resolution: {integrity: sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==} + engines: {node: '>= 0.4'} + + object.assign@4.1.7: + resolution: {integrity: sha512-nK28WOo+QIjBkDduTINE4JkF/UJJKyf2EJxvJKfblDpyg0Q+pkOHNTL0Qwy6NP6FhE/EnzV73BxxqcJaXY9anw==} + engines: {node: '>= 0.4'} + obug@2.1.1: resolution: {integrity: sha512-uTqF9MuPraAQ+IsnPf366RG4cP9RtUi7MLO1N3KEc+wb0a6yKpeL0lmk2IB1jY5KHPAlTc6T/JRdC/YqxHNwkQ==} @@ -4574,10 +5527,17 @@ packages: resolution: {integrity: sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==} engines: {node: '>=6'} + possible-typed-array-names@1.1.0: + resolution: {integrity: sha512-/+5VFTchJDoVj3bhoqi6UeymcD00DAwb1nJwamzPvHEszJ4FpF6SNNbUbOS8yI56qHzdV8eK0qEfOSiodkTdxg==} + engines: {node: '>= 0.4'} + postcss@8.5.6: resolution: {integrity: sha512-3Ybi1tAuwAP9s0r1UQ2J4n5Y0G05bJkpUIO0/bI9MhwmD70S5aTWbXGBwxHrelT+XM1k6dM0pk+SwNkpTRN7Pg==} engines: {node: ^10 || ^12 || >=14} + preact@10.28.0: + resolution: {integrity: sha512-rytDAoiXr3+t6OIP3WGlDd0ouCUG1iCWzkcY3++Nreuoi17y6T5i/zRhe6uYfoVcxq6YU+sBtJouuRDsq8vvqA==} + prelude-ls@1.2.1: resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==} engines: {node: '>= 0.8.0'} @@ -4603,6 +5563,10 @@ packages: engines: {node: '>=14'} hasBin: true + pretty-format@27.5.1: + resolution: {integrity: sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==} + engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} + pretty-format@30.2.0: resolution: {integrity: sha512-9uBdv/B4EefsuAL+pWqueZyZS2Ba+LxfFeQ9DN14HU4bN8bhaxKdkpjpB6fs9+pSjIBu+FXQHImEg8j/Lw0+vA==} engines: {node: ^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0} @@ -4610,8 +5574,8 @@ packages: proxy-from-env@1.1.0: resolution: {integrity: sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==} - publint@0.3.15: - resolution: {integrity: sha512-xPbRAPW+vqdiaKy5sVVY0uFAu3LaviaPO3pZ9FaRx59l9+U/RKR1OEbLhkug87cwiVKxPXyB4txsv5cad67u+A==} + publint@0.3.16: + resolution: {integrity: sha512-MFqyfRLAExPVZdTQFwkAQELzA8idyXzROVOytg6nEJ/GEypXBUmMGrVaID8cTuzRS1U5L8yTOdOJtMXgFUJAeA==} engines: {node: '>=18'} hasBin: true @@ -4637,6 +5601,14 @@ packages: peerDependencies: react: ^19.2.1 + react-dom@19.2.3: + resolution: {integrity: sha512-yELu4WmLPw5Mr/lmeEpox5rw3RETacE++JgHqQzd2dg+YbJuat3jH4ingc+WPZhxaoFzdv9y33G+F7Nl5O0GBg==} + peerDependencies: + react: ^19.2.3 + + react-is@17.0.2: + resolution: {integrity: sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==} + react-is@18.3.1: resolution: {integrity: sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==} @@ -4648,6 +5620,10 @@ packages: resolution: {integrity: sha512-DGrYcCWK7tvYMnWh79yrPHt+vdx9tY+1gPZa7nJQtO/p8bLTDaHp4dzwEhQB7pZ4Xe3ok4XKuEPrVuc+wlpkmw==} engines: {node: '>=0.10.0'} + react@19.2.3: + resolution: {integrity: sha512-Ku/hhYbVjOQnXDZFv2+RibmLFGwFdeeKHFcOTlrt7xplBnya5OGn/hIRDsqDiSUcfORsDC7MPxwork8jBwsIWA==} + engines: {node: '>=0.10.0'} + read-yaml-file@1.1.0: resolution: {integrity: sha512-VIMnQi/Z4HT2Fxuwg5KrY174U1VdUIASQVWXXyqtNRtxSr9IYkn1rsI6Tb6HsrHCmB7gVpNwX6JxPTHcH6IoTA==} engines: {node: '>=6'} @@ -4660,6 +5636,10 @@ packages: resolution: {integrity: sha512-6tDA8g98We0zd0GvVeMT9arEOnTw9qM03L9cJXaCjrip1OO764RDBLBfrB4cwzNGDj5OA5ioymC9GkizgWJDUg==} engines: {node: '>=8'} + regexp.prototype.flags@1.5.4: + resolution: {integrity: sha512-dYqgNSZbDwkaJ2ceRd9ojCGjBq+mOm9LmtXnAnEGyHhN/5R7iDW2TRw3h+o/jCFxus3P2LfWIIiwowAjANm7IA==} + engines: {node: '>= 0.4'} + require-directory@2.1.1: resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==} engines: {node: '>=0.10.0'} @@ -4726,6 +5706,10 @@ packages: safe-buffer@5.2.1: resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==} + safe-regex-test@1.1.0: + resolution: {integrity: sha512-x/+Cz4YrimQxQccJf5mKEbIa1NzeCRNI5Ecl/ekmlYaampdNLPalVyIcCZNNH3MvmqBugV5TMYZXv0ljslUlaw==} + engines: {node: '>= 0.4'} + safer-buffer@2.1.2: resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} @@ -4751,6 +5735,14 @@ packages: resolution: {integrity: sha512-RbcPH1n5cfwKrru7v7+zrZvjLurgHhGyso3HTyGtRivGWgYjbOmGuivCQaORNELjNONoK35nj28EoWul9sb1zQ==} engines: {node: '>=10'} + set-function-length@1.2.2: + resolution: {integrity: sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==} + engines: {node: '>= 0.4'} + + set-function-name@2.0.2: + resolution: {integrity: sha512-7PGFlmtwsEADb0WYyvCMa1t+yke6daIG4Wirafur5kcf+MhUnPms1UeR0CKQdTZD81yESwMHbtn+TR+dMviakQ==} + engines: {node: '>= 0.4'} + shebang-command@2.0.0: resolution: {integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==} engines: {node: '>=8'} @@ -4803,6 +5795,22 @@ packages: resolution: {integrity: sha512-5n7zqPAjL+RzR7n09NPKpWBXmDCtuRpQzIL+ycj8pe6MayV7cDuFmceoyPQJ0c95oFj6feY7SZvhX/+S0i1ukg==} hasBin: true + side-channel-list@1.0.0: + resolution: {integrity: sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==} + engines: {node: '>= 0.4'} + + side-channel-map@1.0.1: + resolution: {integrity: sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==} + engines: {node: '>= 0.4'} + + side-channel-weakmap@1.0.2: + resolution: {integrity: sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==} + engines: {node: '>= 0.4'} + + side-channel@1.1.0: + resolution: {integrity: sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==} + engines: {node: '>= 0.4'} + siginfo@2.0.0: resolution: {integrity: sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==} @@ -4813,6 +5821,9 @@ packages: resolution: {integrity: sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==} engines: {node: '>=14'} + simple-code-frame@1.3.0: + resolution: {integrity: sha512-MB4pQmETUBlNs62BBeRjIFGeuy/x6gGKh7+eRUemn1rCFhqo7K+4slPqsyizCbcbYLnaYqaoZ2FWsZ/jN06D8w==} + size-limit@12.0.0: resolution: {integrity: sha512-JBG8dioIs0m2kHOhs9jD6E/tZKD08vmbf2bfqj/rJyNWqJxk/ZcakixjhYtsqdbi+AKVbfPkt3g2RRZiKaizYA==} engines: {node: ^20.0.0 || ^22.0.0 || >=24.0.0} @@ -4843,6 +5854,10 @@ packages: resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} engines: {node: '>=0.10.0'} + source-map@0.7.6: + resolution: {integrity: sha512-i5uvt8C3ikiWeNZSVZNWcfZPItFQOsYTUAOkcUPGd8DqDy1uOUikjt5dG+uRlwyvR108Fb9DOd4GvXfT0N2/uQ==} + engines: {node: '>= 12'} + spawndamnit@3.0.1: resolution: {integrity: sha512-MmnduQUuHCoFckZoWnXsTg7JaiLBJrKFj9UI2MbRPGaJeVpsLcVBu6P/IGZovziM/YBsellCmsprgNA+w0CzVg==} @@ -4853,12 +5868,20 @@ packages: resolution: {integrity: sha512-o3yWv49B/o4QZk5ZcsALc6t0+eCelPc44zZsLtCQnZPDwFpDYSWcDnrv2TtMmMbQ7uKo3J0HTURCqckw23czNQ==} engines: {node: '>=12.0.0'} + stack-trace@1.0.0-pre2: + resolution: {integrity: sha512-2ztBJRek8IVofG9DBJqdy2N5kulaacX30Nz7xmkYF6ale9WBVmIy6mFBchvGX7Vx/MyjBhx+Rcxqrj+dbOnQ6A==} + engines: {node: '>=16'} + stackback@0.0.2: resolution: {integrity: sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==} std-env@3.10.0: resolution: {integrity: sha512-5GS12FdOZNliM5mAOxFRg7Ir0pWz8MdpYm6AY6VPkGpbA7ZzmbzNcBJQ0GPvvyWgcY7QAhCgf9Uy89I03faLkg==} + stop-iteration-iterator@1.1.0: + resolution: {integrity: sha512-eLoXW/DHyl62zxY4SCaIgnRhuMr6ri4juEYARS8E6sCEqzKpOiE521Ucofdx+KnDZl5xmvGYaaKCk5FEOxJCoQ==} + engines: {node: '>= 0.4'} + string-ts@2.3.1: resolution: {integrity: sha512-xSJq+BS52SaFFAVxuStmx6n5aYZU571uYUnUrPXkPFCfdHyZMMlbP2v2Wx5sNBnAVzq/2+0+mcBLBa3Xa5ubYw==} @@ -5088,6 +6111,11 @@ packages: '@testing-library/jest-dom': optional: true + vite-prerender-plugin@0.5.12: + resolution: {integrity: sha512-EiwhbMn+flg14EysbLTmZSzq8NGTxhytgK3bf4aGRF1evWLGwZiHiUJ1KZDvbxgKbMf2pG6fJWGEa3UZXOnR1g==} + peerDependencies: + vite: 5.x || 6.x || 7.x + vite@7.2.7: resolution: {integrity: sha512-ITcnkFeR3+fI8P1wMgItjGrR10170d8auB4EpMLPqmx6uxElH3a/hHGQabSHKdqd4FXWO1nFIp9rRn7JQ34ACQ==} engines: {node: ^20.19.0 || >=22.12.0} @@ -5201,6 +6229,18 @@ packages: whatwg-url@5.0.0: resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==} + which-boxed-primitive@1.1.1: + resolution: {integrity: sha512-TbX3mj8n0odCBFVlY8AxkqcHASw3L60jIuF8jFP78az3C2YhmGvqbHBpAjTRH2/xqYunrJ9g1jSyjCjpoWzIAA==} + engines: {node: '>= 0.4'} + + which-collection@1.0.2: + resolution: {integrity: sha512-K4jVyjnBdgvc86Y6BkaLZEN933SwYOuBFkdmBu9ZfkcAbdVbpITnDmjvZ/aQjRXQrv5EPkTnD1s39GiiqbngCw==} + engines: {node: '>= 0.4'} + + which-typed-array@1.1.19: + resolution: {integrity: sha512-rEvr90Bck4WZt9HHFC4DJMsjvu7x+r6bImz0/BrbWb7A2djJ8hnZMrWnHo9F8ssv0OMErasDhftrfROTyqSDrw==} + engines: {node: '>= 0.4'} + which@2.0.2: resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==} engines: {node: '>= 8'} @@ -5438,6 +6478,13 @@ snapshots: '@babel/core': 7.28.5 '@babel/helper-plugin-utils': 7.27.1 + '@babel/plugin-transform-react-jsx-development@7.27.1(@babel/core@7.28.5)': + dependencies: + '@babel/core': 7.28.5 + '@babel/plugin-transform-react-jsx': 7.27.1(@babel/core@7.28.5) + transitivePeerDependencies: + - supports-color + '@babel/plugin-transform-react-jsx-self@7.27.1(@babel/core@7.28.5)': dependencies: '@babel/core': 7.28.5 @@ -5448,6 +6495,17 @@ snapshots: '@babel/core': 7.28.5 '@babel/helper-plugin-utils': 7.27.1 + '@babel/plugin-transform-react-jsx@7.27.1(@babel/core@7.28.5)': + dependencies: + '@babel/core': 7.28.5 + '@babel/helper-annotate-as-pure': 7.27.3 + '@babel/helper-module-imports': 7.27.1 + '@babel/helper-plugin-utils': 7.27.1 + '@babel/plugin-syntax-jsx': 7.27.1(@babel/core@7.28.5) + '@babel/types': 7.28.5 + transitivePeerDependencies: + - supports-color + '@babel/runtime@7.28.4': {} '@babel/template@7.27.2': @@ -5505,7 +6563,7 @@ snapshots: dependencies: '@changesets/types': 6.1.0 - '@changesets/cli@2.29.8(@types/node@24.10.1)': + '@changesets/cli@2.29.8(@types/node@25.0.0)': dependencies: '@changesets/apply-release-plan': 7.0.14 '@changesets/assemble-release-plan': 6.0.9 @@ -5521,7 +6579,7 @@ snapshots: '@changesets/should-skip-package': 0.1.2 '@changesets/types': 6.1.0 '@changesets/write': 0.4.0 - '@inquirer/external-editor': 1.0.3(@types/node@24.10.1) + '@inquirer/external-editor': 1.0.3(@types/node@25.0.0) '@manypkg/get-packages': 1.1.3 ansi-colors: 4.1.3 ci-info: 3.9.0 @@ -5803,27 +6861,27 @@ snapshots: '@eslint-community/regexpp@4.12.2': {} - '@eslint-react/ast@2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3)': + '@eslint-react/ast@2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3)': dependencies: - '@eslint-react/eff': 2.3.12 - '@typescript-eslint/types': 8.48.1 - '@typescript-eslint/typescript-estree': 8.48.1(typescript@5.9.3) - '@typescript-eslint/utils': 8.48.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/eff': 2.3.13 + '@typescript-eslint/types': 8.49.0 + '@typescript-eslint/typescript-estree': 8.49.0(typescript@5.9.3) + '@typescript-eslint/utils': 8.49.0(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) eslint: 9.39.1(jiti@2.6.1) string-ts: 2.3.1 typescript: 5.9.3 transitivePeerDependencies: - supports-color - '@eslint-react/core@2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3)': + '@eslint-react/core@2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3)': dependencies: - '@eslint-react/ast': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@eslint-react/eff': 2.3.12 - '@eslint-react/shared': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@eslint-react/var': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@typescript-eslint/scope-manager': 8.48.1 - '@typescript-eslint/types': 8.48.1 - '@typescript-eslint/utils': 8.48.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/ast': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/eff': 2.3.13 + '@eslint-react/shared': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/var': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@typescript-eslint/scope-manager': 8.49.0 + '@typescript-eslint/types': 8.49.0 + '@typescript-eslint/utils': 8.49.0(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) birecord: 0.1.1 eslint: 9.39.1(jiti@2.6.1) ts-pattern: 5.9.0 @@ -5831,31 +6889,31 @@ snapshots: transitivePeerDependencies: - supports-color - '@eslint-react/eff@2.3.12': {} + '@eslint-react/eff@2.3.13': {} - '@eslint-react/eslint-plugin@2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3)': + '@eslint-react/eslint-plugin@2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3)': dependencies: - '@eslint-react/eff': 2.3.12 - '@eslint-react/shared': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@typescript-eslint/scope-manager': 8.48.1 - '@typescript-eslint/type-utils': 8.48.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@typescript-eslint/types': 8.48.1 - '@typescript-eslint/utils': 8.48.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/eff': 2.3.13 + '@eslint-react/shared': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@typescript-eslint/scope-manager': 8.49.0 + '@typescript-eslint/type-utils': 8.49.0(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@typescript-eslint/types': 8.49.0 + '@typescript-eslint/utils': 8.49.0(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) eslint: 9.39.1(jiti@2.6.1) - eslint-plugin-react-dom: 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - eslint-plugin-react-hooks-extra: 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - eslint-plugin-react-naming-convention: 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - eslint-plugin-react-web-api: 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - eslint-plugin-react-x: 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + eslint-plugin-react-dom: 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + eslint-plugin-react-hooks-extra: 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + eslint-plugin-react-naming-convention: 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + eslint-plugin-react-web-api: 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + eslint-plugin-react-x: 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) ts-api-utils: 2.1.0(typescript@5.9.3) typescript: 5.9.3 transitivePeerDependencies: - supports-color - '@eslint-react/shared@2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3)': + '@eslint-react/shared@2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3)': dependencies: - '@eslint-react/eff': 2.3.12 - '@typescript-eslint/utils': 8.48.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/eff': 2.3.13 + '@typescript-eslint/utils': 8.49.0(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) eslint: 9.39.1(jiti@2.6.1) ts-pattern: 5.9.0 typescript: 5.9.3 @@ -5863,13 +6921,13 @@ snapshots: transitivePeerDependencies: - supports-color - '@eslint-react/var@2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3)': + '@eslint-react/var@2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3)': dependencies: - '@eslint-react/ast': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@eslint-react/eff': 2.3.12 - '@typescript-eslint/scope-manager': 8.48.1 - '@typescript-eslint/types': 8.48.1 - '@typescript-eslint/utils': 8.48.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/ast': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/eff': 2.3.13 + '@typescript-eslint/scope-manager': 8.49.0 + '@typescript-eslint/types': 8.49.0 + '@typescript-eslint/utils': 8.49.0(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) eslint: 9.39.1(jiti@2.6.1) ts-pattern: 5.9.0 typescript: 5.9.3 @@ -5936,12 +6994,12 @@ snapshots: '@humanwhocodes/retry@0.4.3': {} - '@inquirer/external-editor@1.0.3(@types/node@24.10.1)': + '@inquirer/external-editor@1.0.3(@types/node@25.0.0)': dependencies: chardet: 2.1.1 iconv-lite: 0.7.0 optionalDependencies: - '@types/node': 24.10.1 + '@types/node': 25.0.0 '@isaacs/balanced-match@4.0.1': {} @@ -6029,34 +7087,34 @@ snapshots: '@nodelib/fs.scandir': 2.1.5 fastq: 1.19.1 - '@nx/nx-darwin-arm64@22.2.0': + '@nx/nx-darwin-arm64@22.2.1': optional: true - '@nx/nx-darwin-x64@22.2.0': + '@nx/nx-darwin-x64@22.2.1': optional: true - '@nx/nx-freebsd-x64@22.2.0': + '@nx/nx-freebsd-x64@22.2.1': optional: true - '@nx/nx-linux-arm-gnueabihf@22.2.0': + '@nx/nx-linux-arm-gnueabihf@22.2.1': optional: true - '@nx/nx-linux-arm64-gnu@22.2.0': + '@nx/nx-linux-arm64-gnu@22.2.1': optional: true - '@nx/nx-linux-arm64-musl@22.2.0': + '@nx/nx-linux-arm64-musl@22.2.1': optional: true - '@nx/nx-linux-x64-gnu@22.2.0': + '@nx/nx-linux-x64-gnu@22.2.1': optional: true - '@nx/nx-linux-x64-musl@22.2.0': + '@nx/nx-linux-x64-musl@22.2.1': optional: true - '@nx/nx-win32-arm64-msvc@22.2.0': + '@nx/nx-win32-arm64-msvc@22.2.1': optional: true - '@nx/nx-win32-x64-msvc@22.2.0': + '@nx/nx-win32-x64-msvc@22.2.1': optional: true '@oxc-project/types@0.101.0': {} @@ -6123,6 +7181,42 @@ snapshots: '@oxc-resolver/binding-win32-x64-msvc@11.15.0': optional: true + '@preact/preset-vite@2.10.2(@babel/core@7.28.5)(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2))': + dependencies: + '@babel/core': 7.28.5 + '@babel/plugin-transform-react-jsx': 7.27.1(@babel/core@7.28.5) + '@babel/plugin-transform-react-jsx-development': 7.27.1(@babel/core@7.28.5) + '@prefresh/vite': 2.4.11(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + '@rollup/pluginutils': 4.2.1 + babel-plugin-transform-hook-names: 1.0.2(@babel/core@7.28.5) + debug: 4.4.3 + picocolors: 1.1.1 + vite: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + vite-prerender-plugin: 0.5.12(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) + transitivePeerDependencies: + - preact + - supports-color + + '@prefresh/babel-plugin@0.5.2': {} + + '@prefresh/core@1.5.9(preact@10.28.0)': + dependencies: + preact: 10.28.0 + + '@prefresh/utils@1.2.1': {} + + '@prefresh/vite@2.4.11(preact@10.28.0)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2))': + dependencies: + '@babel/core': 7.28.5 + '@prefresh/babel-plugin': 0.5.2 + '@prefresh/core': 1.5.9(preact@10.28.0) + '@prefresh/utils': 1.2.1 + '@rollup/pluginutils': 4.2.1 + preact: 10.28.0 + vite: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + transitivePeerDependencies: + - supports-color + '@publint/pack@0.1.2': {} '@quansync/fs@1.0.0': @@ -6172,6 +7266,11 @@ snapshots: '@rolldown/pluginutils@1.0.0-beta.53': {} + '@rollup/pluginutils@4.2.1': + dependencies: + estree-walker: 2.0.2 + picomatch: 2.3.1 + '@rollup/rollup-android-arm-eabi@4.53.3': optional: true @@ -6346,19 +7445,31 @@ snapshots: '@tanstack/devtools-event-client@0.4.0': {} - '@tanstack/devtools-ui@0.4.4(csstype@3.2.3)(solid-js@1.9.10)': + '@tanstack/devtools-ui@0.4.4(csstype@3.2.3)(solid-js@1.9.10)': + dependencies: + clsx: 2.1.1 + goober: 2.1.18(csstype@3.2.3) + solid-js: 1.9.10 + transitivePeerDependencies: + - csstype + + '@tanstack/devtools-utils@0.1.0(@types/react@19.2.7)(csstype@3.2.3)(preact@10.28.0)(react@19.2.3)(solid-js@1.9.10)': dependencies: - clsx: 2.1.1 - goober: 2.1.18(csstype@3.2.3) + '@tanstack/devtools-ui': 0.4.4(csstype@3.2.3)(solid-js@1.9.10) + optionalDependencies: + '@types/react': 19.2.7 + preact: 10.28.0 + react: 19.2.3 solid-js: 1.9.10 transitivePeerDependencies: - csstype - '@tanstack/devtools-utils@0.1.0(@types/react@19.2.7)(csstype@3.2.3)(react@19.2.1)(solid-js@1.9.10)': + '@tanstack/devtools-utils@0.1.0(@types/react@19.2.7)(preact@10.28.0)(react@19.2.1)(solid-js@1.9.10)': dependencies: '@tanstack/devtools-ui': 0.4.4(csstype@3.2.3)(solid-js@1.9.10) optionalDependencies: '@types/react': 19.2.7 + preact: 10.28.0 react: 19.2.1 solid-js: 1.9.10 transitivePeerDependencies: @@ -6380,12 +7491,12 @@ snapshots: - csstype - utf-8-validate - '@tanstack/eslint-config@0.3.4(@typescript-eslint/utils@8.48.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3))(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3)': + '@tanstack/eslint-config@0.3.4(@typescript-eslint/utils@8.49.0(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3))(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3)': dependencies: '@eslint/js': 9.39.1 '@stylistic/eslint-plugin': 5.6.1(eslint@9.39.1(jiti@2.6.1)) eslint: 9.39.1(jiti@2.6.1) - eslint-plugin-import-x: 4.16.1(@typescript-eslint/utils@8.48.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3))(eslint@9.39.1(jiti@2.6.1)) + eslint-plugin-import-x: 4.16.1(@typescript-eslint/utils@8.49.0(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3))(eslint@9.39.1(jiti@2.6.1)) eslint-plugin-n: 17.23.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) globals: 16.5.0 typescript-eslint: 8.48.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) @@ -6398,46 +7509,61 @@ snapshots: '@tanstack/persister@0.1.1': {} + '@tanstack/preact-devtools@0.9.2(csstype@3.2.3)(preact@10.28.0)(solid-js@1.9.10)': + dependencies: + '@tanstack/devtools': 0.9.1(csstype@3.2.3)(solid-js@1.9.10) + preact: 10.28.0 + transitivePeerDependencies: + - bufferutil + - csstype + - solid-js + - utf-8-validate + + '@tanstack/preact-store@0.10.1(preact@10.28.0)': + dependencies: + '@tanstack/store': 0.8.0 + preact: 10.28.0 + '@tanstack/query-core@5.90.12': {} '@tanstack/query-devtools@5.91.1': {} - '@tanstack/react-devtools@0.8.4(@types/react-dom@19.2.3(@types/react@19.2.7))(@types/react@19.2.7)(csstype@3.2.3)(react-dom@19.2.1(react@19.2.1))(react@19.2.1)(solid-js@1.9.10)': + '@tanstack/react-devtools@0.8.4(@types/react-dom@19.2.3(@types/react@19.2.7))(@types/react@19.2.7)(csstype@3.2.3)(react-dom@19.2.3(react@19.2.3))(react@19.2.3)(solid-js@1.9.10)': dependencies: '@tanstack/devtools': 0.9.1(csstype@3.2.3)(solid-js@1.9.10) '@types/react': 19.2.7 '@types/react-dom': 19.2.3(@types/react@19.2.7) - react: 19.2.1 - react-dom: 19.2.1(react@19.2.1) + react: 19.2.3 + react-dom: 19.2.3(react@19.2.3) transitivePeerDependencies: - bufferutil - csstype - solid-js - utf-8-validate - '@tanstack/react-persister@0.1.1(react-dom@19.2.1(react@19.2.1))(react@19.2.1)': + '@tanstack/react-persister@0.1.1(react-dom@19.2.3(react@19.2.3))(react@19.2.3)': dependencies: '@tanstack/persister': 0.1.1 - react: 19.2.1 - react-dom: 19.2.1(react@19.2.1) + react: 19.2.3 + react-dom: 19.2.3(react@19.2.3) - '@tanstack/react-query-devtools@5.91.1(@tanstack/react-query@5.90.12(react@19.2.1))(react@19.2.1)': + '@tanstack/react-query-devtools@5.91.1(@tanstack/react-query@5.90.12(react@19.2.3))(react@19.2.3)': dependencies: '@tanstack/query-devtools': 5.91.1 - '@tanstack/react-query': 5.90.12(react@19.2.1) - react: 19.2.1 + '@tanstack/react-query': 5.90.12(react@19.2.3) + react: 19.2.3 - '@tanstack/react-query@5.90.12(react@19.2.1)': + '@tanstack/react-query@5.90.12(react@19.2.3)': dependencies: '@tanstack/query-core': 5.90.12 - react: 19.2.1 + react: 19.2.3 - '@tanstack/react-store@0.8.0(react-dom@19.2.1(react@19.2.1))(react@19.2.1)': + '@tanstack/react-store@0.8.0(react-dom@19.2.1(react@19.2.3))(react@19.2.3)': dependencies: '@tanstack/store': 0.8.0 - react: 19.2.1 - react-dom: 19.2.1(react@19.2.1) - use-sync-external-store: 1.6.0(react@19.2.1) + react: 19.2.3 + react-dom: 19.2.1(react@19.2.3) + use-sync-external-store: 1.6.0(react@19.2.3) '@tanstack/solid-devtools@0.7.17(csstype@3.2.3)(solid-js@1.9.10)': dependencies: @@ -6463,6 +7589,17 @@ snapshots: transitivePeerDependencies: - typescript + '@testing-library/dom@8.20.1': + dependencies: + '@babel/code-frame': 7.27.1 + '@babel/runtime': 7.28.4 + '@types/aria-query': 5.0.4 + aria-query: 5.1.3 + chalk: 4.1.2 + dom-accessibility-api: 0.5.16 + lz-string: 1.5.0 + pretty-format: 27.5.1 + '@testing-library/jest-dom@6.9.1': dependencies: '@adobe/css-tools': 4.4.4 @@ -6472,6 +7609,11 @@ snapshots: picocolors: 1.1.1 redent: 3.0.0 + '@testing-library/preact@3.2.4(preact@10.28.0)': + dependencies: + '@testing-library/dom': 8.20.1 + preact: 10.28.0 + '@tybys/wasm-util@0.10.1': dependencies: tslib: 2.8.1 @@ -6481,6 +7623,8 @@ snapshots: dependencies: tslib: 2.8.1 + '@types/aria-query@5.0.4': {} + '@types/babel__core@7.20.5': dependencies: '@babel/parser': 7.28.5 @@ -6523,7 +7667,7 @@ snapshots: dependencies: undici-types: 6.21.0 - '@types/node@24.10.1': + '@types/node@25.0.0': dependencies: undici-types: 7.16.0 @@ -6577,15 +7721,33 @@ snapshots: transitivePeerDependencies: - supports-color + '@typescript-eslint/project-service@8.49.0(typescript@5.9.3)': + dependencies: + '@typescript-eslint/tsconfig-utils': 8.49.0(typescript@5.9.3) + '@typescript-eslint/types': 8.49.0 + debug: 4.4.3 + typescript: 5.9.3 + transitivePeerDependencies: + - supports-color + '@typescript-eslint/scope-manager@8.48.1': dependencies: '@typescript-eslint/types': 8.48.1 '@typescript-eslint/visitor-keys': 8.48.1 + '@typescript-eslint/scope-manager@8.49.0': + dependencies: + '@typescript-eslint/types': 8.49.0 + '@typescript-eslint/visitor-keys': 8.49.0 + '@typescript-eslint/tsconfig-utils@8.48.1(typescript@5.9.3)': dependencies: typescript: 5.9.3 + '@typescript-eslint/tsconfig-utils@8.49.0(typescript@5.9.3)': + dependencies: + typescript: 5.9.3 + '@typescript-eslint/type-utils@8.48.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3)': dependencies: '@typescript-eslint/types': 8.48.1 @@ -6598,8 +7760,22 @@ snapshots: transitivePeerDependencies: - supports-color + '@typescript-eslint/type-utils@8.49.0(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3)': + dependencies: + '@typescript-eslint/types': 8.49.0 + '@typescript-eslint/typescript-estree': 8.49.0(typescript@5.9.3) + '@typescript-eslint/utils': 8.49.0(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + debug: 4.4.3 + eslint: 9.39.1(jiti@2.6.1) + ts-api-utils: 2.1.0(typescript@5.9.3) + typescript: 5.9.3 + transitivePeerDependencies: + - supports-color + '@typescript-eslint/types@8.48.1': {} + '@typescript-eslint/types@8.49.0': {} + '@typescript-eslint/typescript-estree@8.48.1(typescript@5.9.3)': dependencies: '@typescript-eslint/project-service': 8.48.1(typescript@5.9.3) @@ -6615,6 +7791,21 @@ snapshots: transitivePeerDependencies: - supports-color + '@typescript-eslint/typescript-estree@8.49.0(typescript@5.9.3)': + dependencies: + '@typescript-eslint/project-service': 8.49.0(typescript@5.9.3) + '@typescript-eslint/tsconfig-utils': 8.49.0(typescript@5.9.3) + '@typescript-eslint/types': 8.49.0 + '@typescript-eslint/visitor-keys': 8.49.0 + debug: 4.4.3 + minimatch: 9.0.5 + semver: 7.7.3 + tinyglobby: 0.2.15 + ts-api-utils: 2.1.0(typescript@5.9.3) + typescript: 5.9.3 + transitivePeerDependencies: + - supports-color + '@typescript-eslint/utils@8.48.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3)': dependencies: '@eslint-community/eslint-utils': 4.9.0(eslint@9.39.1(jiti@2.6.1)) @@ -6626,11 +7817,27 @@ snapshots: transitivePeerDependencies: - supports-color + '@typescript-eslint/utils@8.49.0(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3)': + dependencies: + '@eslint-community/eslint-utils': 4.9.0(eslint@9.39.1(jiti@2.6.1)) + '@typescript-eslint/scope-manager': 8.49.0 + '@typescript-eslint/types': 8.49.0 + '@typescript-eslint/typescript-estree': 8.49.0(typescript@5.9.3) + eslint: 9.39.1(jiti@2.6.1) + typescript: 5.9.3 + transitivePeerDependencies: + - supports-color + '@typescript-eslint/visitor-keys@8.48.1': dependencies: '@typescript-eslint/types': 8.48.1 eslint-visitor-keys: 4.2.1 + '@typescript-eslint/visitor-keys@8.49.0': + dependencies: + '@typescript-eslint/types': 8.49.0 + eslint-visitor-keys: 4.2.1 + '@unrs/resolver-binding-android-arm-eabi@1.11.1': optional: true @@ -6690,7 +7897,7 @@ snapshots: '@unrs/resolver-binding-win32-x64-msvc@1.11.1': optional: true - '@vitejs/plugin-react@5.1.2(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2))': + '@vitejs/plugin-react@5.1.2(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2))': dependencies: '@babel/core': 7.28.5 '@babel/plugin-transform-react-jsx-self': 7.27.1(@babel/core@7.28.5) @@ -6698,7 +7905,7 @@ snapshots: '@rolldown/pluginutils': 1.0.0-beta.53 '@types/babel__core': 7.20.5 react-refresh: 0.18.0 - vite: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + vite: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) transitivePeerDependencies: - supports-color @@ -6711,13 +7918,13 @@ snapshots: chai: 6.2.1 tinyrainbow: 3.0.3 - '@vitest/mocker@4.0.15(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2))': + '@vitest/mocker@4.0.15(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2))': dependencies: '@vitest/spy': 4.0.15 estree-walker: 3.0.3 magic-string: 0.30.21 optionalDependencies: - vite: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + vite: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) '@vitest/pretty-format@4.0.15': dependencies: @@ -6783,8 +7990,17 @@ snapshots: argparse@2.0.1: {} + aria-query@5.1.3: + dependencies: + deep-equal: 2.2.3 + aria-query@5.3.2: {} + array-buffer-byte-length@1.0.2: + dependencies: + call-bound: 1.0.4 + is-array-buffer: 3.0.5 + array-union@2.1.0: {} assertion-error@2.0.1: {} @@ -6796,6 +8012,10 @@ snapshots: asynckit@0.4.0: {} + available-typed-arrays@1.0.7: + dependencies: + possible-typed-array-names: 1.1.0 + axios@1.13.2: dependencies: follow-redirects: 1.15.11 @@ -6815,6 +8035,10 @@ snapshots: html-entities: 2.3.3 parse5: 7.3.0 + babel-plugin-transform-hook-names@1.0.2(@babel/core@7.28.5): + dependencies: + '@babel/core': 7.28.5 + babel-preset-solid@1.9.10(@babel/core@7.28.5)(solid-js@1.9.10): dependencies: '@babel/core': 7.28.5 @@ -6826,7 +8050,7 @@ snapshots: base64-js@1.5.1: {} - baseline-browser-mapping@2.9.0: {} + baseline-browser-mapping@2.9.3: {} better-path-resolve@1.0.0: dependencies: @@ -6859,9 +8083,9 @@ snapshots: browserslist@4.28.1: dependencies: - baseline-browser-mapping: 2.9.0 + baseline-browser-mapping: 2.9.3 caniuse-lite: 1.0.30001759 - electron-to-chromium: 1.5.264 + electron-to-chromium: 1.5.266 node-releases: 2.0.27 update-browserslist-db: 1.2.2(browserslist@4.28.1) @@ -6879,6 +8103,18 @@ snapshots: es-errors: 1.3.0 function-bind: 1.1.2 + call-bind@1.0.8: + dependencies: + call-bind-apply-helpers: 1.0.2 + es-define-property: 1.0.1 + get-intrinsic: 1.3.0 + set-function-length: 1.2.2 + + call-bound@1.0.4: + dependencies: + call-bind-apply-helpers: 1.0.2 + get-intrinsic: 1.3.0 + callsites@3.1.0: {} caniuse-lite@1.0.30001759: {} @@ -6982,14 +8218,47 @@ snapshots: dependencies: ms: 2.1.3 + deep-equal@2.2.3: + dependencies: + array-buffer-byte-length: 1.0.2 + call-bind: 1.0.8 + es-get-iterator: 1.1.3 + get-intrinsic: 1.3.0 + is-arguments: 1.2.0 + is-array-buffer: 3.0.5 + is-date-object: 1.1.0 + is-regex: 1.2.1 + is-shared-array-buffer: 1.0.4 + isarray: 2.0.5 + object-is: 1.1.6 + object-keys: 1.1.1 + object.assign: 4.1.7 + regexp.prototype.flags: 1.5.4 + side-channel: 1.1.0 + which-boxed-primitive: 1.1.1 + which-collection: 1.0.2 + which-typed-array: 1.1.19 + deep-is@0.1.4: {} defaults@1.0.4: dependencies: clone: 1.0.4 + define-data-property@1.1.4: + dependencies: + es-define-property: 1.0.1 + es-errors: 1.3.0 + gopd: 1.2.0 + define-lazy-prop@2.0.0: {} + define-properties@1.2.1: + dependencies: + define-data-property: 1.1.4 + has-property-descriptors: 1.0.2 + object-keys: 1.1.1 + delayed-stream@1.0.0: {} detect-indent@6.1.0: {} @@ -7000,6 +8269,8 @@ snapshots: dependencies: path-type: 4.0.0 + dom-accessibility-api@0.5.16: {} + dom-accessibility-api@0.6.3: {} dom-serializer@2.0.0: @@ -7038,7 +8309,7 @@ snapshots: es-errors: 1.3.0 gopd: 1.2.0 - electron-to-chromium@1.5.264: {} + electron-to-chromium@1.5.266: {} emoji-regex@8.0.0: {} @@ -7075,6 +8346,18 @@ snapshots: es-errors@1.3.0: {} + es-get-iterator@1.1.3: + dependencies: + call-bind: 1.0.8 + get-intrinsic: 1.3.0 + has-symbols: 1.1.0 + is-arguments: 1.2.0 + is-map: 2.0.3 + is-set: 2.0.3 + is-string: 1.1.1 + isarray: 2.0.5 + stop-iteration-iterator: 1.1.0 + es-module-lexer@1.7.0: {} es-object-atoms@1.1.1: @@ -7171,7 +8454,7 @@ snapshots: eslint: 9.39.1(jiti@2.6.1) eslint-compat-utils: 0.5.1(eslint@9.39.1(jiti@2.6.1)) - eslint-plugin-import-x@4.16.1(@typescript-eslint/utils@8.48.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3))(eslint@9.39.1(jiti@2.6.1)): + eslint-plugin-import-x@4.16.1(@typescript-eslint/utils@8.49.0(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3))(eslint@9.39.1(jiti@2.6.1)): dependencies: '@typescript-eslint/types': 8.48.1 comment-parser: 1.4.1 @@ -7184,7 +8467,7 @@ snapshots: stable-hash-x: 0.2.0 unrs-resolver: 1.11.1 optionalDependencies: - '@typescript-eslint/utils': 8.48.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@typescript-eslint/utils': 8.49.0(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) transitivePeerDependencies: - supports-color @@ -7215,16 +8498,16 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-plugin-react-dom@2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3): + eslint-plugin-react-dom@2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3): dependencies: - '@eslint-react/ast': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@eslint-react/core': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@eslint-react/eff': 2.3.12 - '@eslint-react/shared': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@eslint-react/var': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@typescript-eslint/scope-manager': 8.48.1 - '@typescript-eslint/types': 8.48.1 - '@typescript-eslint/utils': 8.48.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/ast': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/core': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/eff': 2.3.13 + '@eslint-react/shared': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/var': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@typescript-eslint/scope-manager': 8.49.0 + '@typescript-eslint/types': 8.49.0 + '@typescript-eslint/utils': 8.49.0(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) compare-versions: 6.1.1 eslint: 9.39.1(jiti@2.6.1) string-ts: 2.3.1 @@ -7233,17 +8516,17 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-plugin-react-hooks-extra@2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3): - dependencies: - '@eslint-react/ast': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@eslint-react/core': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@eslint-react/eff': 2.3.12 - '@eslint-react/shared': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@eslint-react/var': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@typescript-eslint/scope-manager': 8.48.1 - '@typescript-eslint/type-utils': 8.48.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@typescript-eslint/types': 8.48.1 - '@typescript-eslint/utils': 8.48.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + eslint-plugin-react-hooks-extra@2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3): + dependencies: + '@eslint-react/ast': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/core': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/eff': 2.3.13 + '@eslint-react/shared': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/var': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@typescript-eslint/scope-manager': 8.49.0 + '@typescript-eslint/type-utils': 8.49.0(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@typescript-eslint/types': 8.49.0 + '@typescript-eslint/utils': 8.49.0(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) eslint: 9.39.1(jiti@2.6.1) string-ts: 2.3.1 ts-pattern: 5.9.0 @@ -7262,17 +8545,17 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-plugin-react-naming-convention@2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3): - dependencies: - '@eslint-react/ast': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@eslint-react/core': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@eslint-react/eff': 2.3.12 - '@eslint-react/shared': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@eslint-react/var': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@typescript-eslint/scope-manager': 8.48.1 - '@typescript-eslint/type-utils': 8.48.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@typescript-eslint/types': 8.48.1 - '@typescript-eslint/utils': 8.48.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + eslint-plugin-react-naming-convention@2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3): + dependencies: + '@eslint-react/ast': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/core': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/eff': 2.3.13 + '@eslint-react/shared': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/var': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@typescript-eslint/scope-manager': 8.49.0 + '@typescript-eslint/type-utils': 8.49.0(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@typescript-eslint/types': 8.49.0 + '@typescript-eslint/utils': 8.49.0(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) eslint: 9.39.1(jiti@2.6.1) string-ts: 2.3.1 ts-pattern: 5.9.0 @@ -7280,16 +8563,16 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-plugin-react-web-api@2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3): + eslint-plugin-react-web-api@2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3): dependencies: - '@eslint-react/ast': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@eslint-react/core': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@eslint-react/eff': 2.3.12 - '@eslint-react/shared': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@eslint-react/var': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@typescript-eslint/scope-manager': 8.48.1 - '@typescript-eslint/types': 8.48.1 - '@typescript-eslint/utils': 8.48.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/ast': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/core': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/eff': 2.3.13 + '@eslint-react/shared': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/var': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@typescript-eslint/scope-manager': 8.49.0 + '@typescript-eslint/types': 8.49.0 + '@typescript-eslint/utils': 8.49.0(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) eslint: 9.39.1(jiti@2.6.1) string-ts: 2.3.1 ts-pattern: 5.9.0 @@ -7297,17 +8580,17 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-plugin-react-x@2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3): - dependencies: - '@eslint-react/ast': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@eslint-react/core': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@eslint-react/eff': 2.3.12 - '@eslint-react/shared': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@eslint-react/var': 2.3.12(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@typescript-eslint/scope-manager': 8.48.1 - '@typescript-eslint/type-utils': 8.48.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) - '@typescript-eslint/types': 8.48.1 - '@typescript-eslint/utils': 8.48.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + eslint-plugin-react-x@2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3): + dependencies: + '@eslint-react/ast': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/core': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/eff': 2.3.13 + '@eslint-react/shared': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@eslint-react/var': 2.3.13(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@typescript-eslint/scope-manager': 8.49.0 + '@typescript-eslint/type-utils': 8.49.0(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@typescript-eslint/types': 8.49.0 + '@typescript-eslint/utils': 8.49.0(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) compare-versions: 6.1.1 eslint: 9.39.1(jiti@2.6.1) is-immutable-type: 5.0.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) @@ -7398,6 +8681,8 @@ snapshots: estraverse@5.3.0: {} + estree-walker@2.0.2: {} + estree-walker@3.0.3: dependencies: '@types/estree': 1.0.8 @@ -7470,6 +8755,10 @@ snapshots: follow-redirects@1.15.11: {} + for-each@0.3.5: + dependencies: + is-callable: 1.2.7 + form-data@4.0.5: dependencies: asynckit: 0.4.0 @@ -7505,6 +8794,8 @@ snapshots: function-bind@1.1.2: {} + functions-have-names@1.2.3: {} + gensync@1.0.0-beta.2: {} get-caller-file@2.0.5: {} @@ -7572,8 +8863,14 @@ snapshots: '@types/whatwg-mimetype': 3.0.2 whatwg-mimetype: 3.0.0 + has-bigints@1.1.0: {} + has-flag@4.0.0: {} + has-property-descriptors@1.0.2: + dependencies: + es-define-property: 1.0.1 + has-symbols@1.1.0: {} has-tostringtag@1.0.2: @@ -7584,6 +8881,8 @@ snapshots: dependencies: function-bind: 1.1.2 + he@1.2.0: {} + hermes-estree@0.25.1: {} hermes-parser@0.25.1: @@ -7634,6 +8933,39 @@ snapshots: inherits@2.0.4: {} + internal-slot@1.1.0: + dependencies: + es-errors: 1.3.0 + hasown: 2.0.2 + side-channel: 1.1.0 + + is-arguments@1.2.0: + dependencies: + call-bound: 1.0.4 + has-tostringtag: 1.0.2 + + is-array-buffer@3.0.5: + dependencies: + call-bind: 1.0.8 + call-bound: 1.0.4 + get-intrinsic: 1.3.0 + + is-bigint@1.1.0: + dependencies: + has-bigints: 1.1.0 + + is-boolean-object@1.2.2: + dependencies: + call-bound: 1.0.4 + has-tostringtag: 1.0.2 + + is-callable@1.2.7: {} + + is-date-object@1.1.0: + dependencies: + call-bound: 1.0.4 + has-tostringtag: 1.0.2 + is-docker@2.2.1: {} is-extglob@2.1.1: {} @@ -7646,7 +8978,7 @@ snapshots: is-immutable-type@5.0.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3): dependencies: - '@typescript-eslint/type-utils': 8.48.1(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) + '@typescript-eslint/type-utils': 8.49.0(eslint@9.39.1(jiti@2.6.1))(typescript@5.9.3) eslint: 9.39.1(jiti@2.6.1) ts-api-utils: 2.1.0(typescript@5.9.3) ts-declaration-location: 1.0.7(typescript@5.9.3) @@ -7656,18 +8988,56 @@ snapshots: is-interactive@1.0.0: {} + is-map@2.0.3: {} + + is-number-object@1.1.1: + dependencies: + call-bound: 1.0.4 + has-tostringtag: 1.0.2 + is-number@7.0.0: {} is-reference@3.0.3: dependencies: '@types/estree': 1.0.8 + is-regex@1.2.1: + dependencies: + call-bound: 1.0.4 + gopd: 1.2.0 + has-tostringtag: 1.0.2 + hasown: 2.0.2 + + is-set@2.0.3: {} + + is-shared-array-buffer@1.0.4: + dependencies: + call-bound: 1.0.4 + + is-string@1.1.1: + dependencies: + call-bound: 1.0.4 + has-tostringtag: 1.0.2 + is-subdir@1.2.0: dependencies: better-path-resolve: 1.0.0 + is-symbol@1.1.1: + dependencies: + call-bound: 1.0.4 + has-symbols: 1.1.0 + safe-regex-test: 1.1.0 + is-unicode-supported@0.1.0: {} + is-weakmap@2.0.2: {} + + is-weakset@2.0.4: + dependencies: + call-bound: 1.0.4 + get-intrinsic: 1.3.0 + is-what@4.1.16: {} is-windows@1.0.2: {} @@ -7676,6 +9046,8 @@ snapshots: dependencies: is-docker: 2.2.1 + isarray@2.0.5: {} + isexe@2.0.0: {} jest-diff@30.2.0: @@ -7718,10 +9090,10 @@ snapshots: dependencies: json-buffer: 3.0.1 - knip@5.72.0(@types/node@24.10.1)(typescript@5.9.3): + knip@5.73.3(@types/node@25.0.0)(typescript@5.9.3): dependencies: '@nodelib/fs.walk': 1.2.8 - '@types/node': 24.10.1 + '@types/node': 25.0.0 fast-glob: 3.3.3 formatly: 0.3.0 jiti: 2.6.1 @@ -7735,6 +9107,8 @@ snapshots: typescript: 5.9.3 zod: 4.1.13 + kolorist@1.8.0: {} + levn@0.4.1: dependencies: prelude-ls: 1.2.1 @@ -7776,6 +9150,8 @@ snapshots: lunr@2.3.9: {} + lz-string@1.5.0: {} + magic-string@0.30.21: dependencies: '@jridgewell/sourcemap-codec': 1.5.5 @@ -7859,6 +9235,11 @@ snapshots: dependencies: whatwg-url: 5.0.0 + node-html-parser@6.1.13: + dependencies: + css-select: 5.2.2 + he: 1.2.0 + node-machine-id@1.1.12: {} node-releases@2.0.27: {} @@ -7871,7 +9252,7 @@ snapshots: dependencies: boolbase: 1.0.0 - nx@22.2.0: + nx@22.2.1: dependencies: '@napi-rs/wasm-runtime': 0.2.4 '@yarnpkg/lockfile': 1.1.0 @@ -7909,19 +9290,37 @@ snapshots: yargs: 17.7.2 yargs-parser: 21.1.1 optionalDependencies: - '@nx/nx-darwin-arm64': 22.2.0 - '@nx/nx-darwin-x64': 22.2.0 - '@nx/nx-freebsd-x64': 22.2.0 - '@nx/nx-linux-arm-gnueabihf': 22.2.0 - '@nx/nx-linux-arm64-gnu': 22.2.0 - '@nx/nx-linux-arm64-musl': 22.2.0 - '@nx/nx-linux-x64-gnu': 22.2.0 - '@nx/nx-linux-x64-musl': 22.2.0 - '@nx/nx-win32-arm64-msvc': 22.2.0 - '@nx/nx-win32-x64-msvc': 22.2.0 + '@nx/nx-darwin-arm64': 22.2.1 + '@nx/nx-darwin-x64': 22.2.1 + '@nx/nx-freebsd-x64': 22.2.1 + '@nx/nx-linux-arm-gnueabihf': 22.2.1 + '@nx/nx-linux-arm64-gnu': 22.2.1 + '@nx/nx-linux-arm64-musl': 22.2.1 + '@nx/nx-linux-x64-gnu': 22.2.1 + '@nx/nx-linux-x64-musl': 22.2.1 + '@nx/nx-win32-arm64-msvc': 22.2.1 + '@nx/nx-win32-x64-msvc': 22.2.1 transitivePeerDependencies: - debug + object-inspect@1.13.4: {} + + object-is@1.1.6: + dependencies: + call-bind: 1.0.8 + define-properties: 1.2.1 + + object-keys@1.1.1: {} + + object.assign@4.1.7: + dependencies: + call-bind: 1.0.8 + call-bound: 1.0.4 + define-properties: 1.2.1 + es-object-atoms: 1.1.1 + has-symbols: 1.1.0 + object-keys: 1.1.1 + obug@2.1.1: {} once@1.4.0: @@ -8046,12 +9445,16 @@ snapshots: pify@4.0.1: {} + possible-typed-array-names@1.1.0: {} + postcss@8.5.6: dependencies: nanoid: 3.3.11 picocolors: 1.1.1 source-map-js: 1.2.1 + preact@10.28.0: {} + prelude-ls@1.2.1: {} premove@4.0.0: {} @@ -8065,6 +9468,12 @@ snapshots: prettier@3.7.4: {} + pretty-format@27.5.1: + dependencies: + ansi-regex: 5.0.1 + ansi-styles: 5.2.0 + react-is: 17.0.2 + pretty-format@30.2.0: dependencies: '@jest/schemas': 30.0.5 @@ -8073,7 +9482,7 @@ snapshots: proxy-from-env@1.1.0: {} - publint@0.3.15: + publint@0.3.16: dependencies: '@publint/pack': 0.1.2 package-manager-detector: 1.6.0 @@ -8095,12 +9504,26 @@ snapshots: react: 19.2.1 scheduler: 0.27.0 + react-dom@19.2.1(react@19.2.3): + dependencies: + react: 19.2.3 + scheduler: 0.27.0 + + react-dom@19.2.3(react@19.2.3): + dependencies: + react: 19.2.3 + scheduler: 0.27.0 + + react-is@17.0.2: {} + react-is@18.3.1: {} react-refresh@0.18.0: {} react@19.2.1: {} + react@19.2.3: {} + read-yaml-file@1.1.0: dependencies: graceful-fs: 4.2.11 @@ -8119,6 +9542,15 @@ snapshots: indent-string: 4.0.0 strip-indent: 3.0.0 + regexp.prototype.flags@1.5.4: + dependencies: + call-bind: 1.0.8 + define-properties: 1.2.1 + es-errors: 1.3.0 + get-proto: 1.0.1 + gopd: 1.2.0 + set-function-name: 2.0.2 + require-directory@2.1.1: {} resolve-from@4.0.0: {} @@ -8210,6 +9642,12 @@ snapshots: safe-buffer@5.2.1: {} + safe-regex-test@1.1.0: + dependencies: + call-bound: 1.0.4 + es-errors: 1.3.0 + is-regex: 1.2.1 + safer-buffer@2.1.2: {} scheduler@0.27.0: {} @@ -8224,6 +9662,22 @@ snapshots: seroval@1.3.2: {} + set-function-length@1.2.2: + dependencies: + define-data-property: 1.1.4 + es-errors: 1.3.0 + function-bind: 1.1.2 + get-intrinsic: 1.3.0 + gopd: 1.2.0 + has-property-descriptors: 1.0.2 + + set-function-name@2.0.2: + dependencies: + define-data-property: 1.1.4 + es-errors: 1.3.0 + functions-have-names: 1.2.3 + has-property-descriptors: 1.0.2 + shebang-command@2.0.0: dependencies: shebang-regex: 3.0.0 @@ -8265,12 +9719,44 @@ snapshots: sherif-windows-arm64: 1.9.0 sherif-windows-x64: 1.9.0 + side-channel-list@1.0.0: + dependencies: + es-errors: 1.3.0 + object-inspect: 1.13.4 + + side-channel-map@1.0.1: + dependencies: + call-bound: 1.0.4 + es-errors: 1.3.0 + get-intrinsic: 1.3.0 + object-inspect: 1.13.4 + + side-channel-weakmap@1.0.2: + dependencies: + call-bound: 1.0.4 + es-errors: 1.3.0 + get-intrinsic: 1.3.0 + object-inspect: 1.13.4 + side-channel-map: 1.0.1 + + side-channel@1.1.0: + dependencies: + es-errors: 1.3.0 + object-inspect: 1.13.4 + side-channel-list: 1.0.0 + side-channel-map: 1.0.1 + side-channel-weakmap: 1.0.2 + siginfo@2.0.0: {} signal-exit@3.0.7: {} signal-exit@4.1.0: {} + simple-code-frame@1.3.0: + dependencies: + kolorist: 1.8.0 + size-limit@12.0.0(jiti@2.6.1): dependencies: bytes-iec: 3.1.1 @@ -8302,6 +9788,8 @@ snapshots: source-map-js@1.2.1: {} + source-map@0.7.6: {} + spawndamnit@3.0.1: dependencies: cross-spawn: 7.0.6 @@ -8311,10 +9799,17 @@ snapshots: stable-hash-x@0.2.0: {} + stack-trace@1.0.0-pre2: {} + stackback@0.0.2: {} std-env@3.10.0: {} + stop-iteration-iterator@1.1.0: + dependencies: + es-errors: 1.3.0 + internal-slot: 1.1.0 + string-ts@2.3.1: {} string-width@4.2.3: @@ -8413,7 +9908,7 @@ snapshots: minimist: 1.2.8 strip-bom: 3.0.0 - tsdown@0.17.2(@arethetypeswrong/core@0.18.2)(oxc-resolver@11.15.0)(publint@0.3.15)(typescript@5.9.3): + tsdown@0.17.2(@arethetypeswrong/core@0.18.2)(oxc-resolver@11.15.0)(publint@0.3.16)(typescript@5.9.3): dependencies: ansis: 4.2.0 cac: 6.7.14 @@ -8431,7 +9926,7 @@ snapshots: unrun: 0.2.19 optionalDependencies: '@arethetypeswrong/core': 0.18.2 - publint: 0.3.15 + publint: 0.3.16 typescript: 5.9.3 transitivePeerDependencies: - '@ts-macro/tsc' @@ -8533,16 +10028,16 @@ snapshots: dependencies: punycode: 2.3.1 - use-sync-external-store@1.6.0(react@19.2.1): + use-sync-external-store@1.6.0(react@19.2.3): dependencies: - react: 19.2.1 + react: 19.2.3 util-deprecate@1.0.2: {} validate-npm-package-name@5.0.1: optional: true - vite-plugin-solid@2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)): + vite-plugin-solid@2.11.10(@testing-library/jest-dom@6.9.1)(solid-js@1.9.10)(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)): dependencies: '@babel/core': 7.28.5 '@types/babel__core': 7.20.5 @@ -8550,14 +10045,24 @@ snapshots: merge-anything: 5.1.7 solid-js: 1.9.10 solid-refresh: 0.6.3(solid-js@1.9.10) - vite: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) - vitefu: 1.1.1(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + vite: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + vitefu: 1.1.1(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) optionalDependencies: '@testing-library/jest-dom': 6.9.1 transitivePeerDependencies: - supports-color - vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2): + vite-prerender-plugin@0.5.12(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)): + dependencies: + kolorist: 1.8.0 + magic-string: 0.30.21 + node-html-parser: 6.1.13 + simple-code-frame: 1.3.0 + source-map: 0.7.6 + stack-trace: 1.0.0-pre2 + vite: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) + + vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2): dependencies: esbuild: 0.25.12 fdir: 6.5.0(picomatch@4.0.3) @@ -8566,19 +10071,19 @@ snapshots: rollup: 4.53.3 tinyglobby: 0.2.15 optionalDependencies: - '@types/node': 24.10.1 + '@types/node': 25.0.0 fsevents: 2.3.3 jiti: 2.6.1 yaml: 2.8.2 - vitefu@1.1.1(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)): + vitefu@1.1.1(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)): optionalDependencies: - vite: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + vite: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) - vitest@4.0.15(@types/node@24.10.1)(happy-dom@20.0.11)(jiti@2.6.1)(yaml@2.8.2): + vitest@4.0.15(@types/node@25.0.0)(happy-dom@20.0.11)(jiti@2.6.1)(yaml@2.8.2): dependencies: '@vitest/expect': 4.0.15 - '@vitest/mocker': 4.0.15(vite@7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2)) + '@vitest/mocker': 4.0.15(vite@7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2)) '@vitest/pretty-format': 4.0.15 '@vitest/runner': 4.0.15 '@vitest/snapshot': 4.0.15 @@ -8595,10 +10100,10 @@ snapshots: tinyexec: 1.0.2 tinyglobby: 0.2.15 tinyrainbow: 3.0.3 - vite: 7.2.7(@types/node@24.10.1)(jiti@2.6.1)(yaml@2.8.2) + vite: 7.2.7(@types/node@25.0.0)(jiti@2.6.1)(yaml@2.8.2) why-is-node-running: 2.3.0 optionalDependencies: - '@types/node': 24.10.1 + '@types/node': 25.0.0 happy-dom: 20.0.11 transitivePeerDependencies: - jiti @@ -8646,6 +10151,31 @@ snapshots: tr46: 0.0.3 webidl-conversions: 3.0.1 + which-boxed-primitive@1.1.1: + dependencies: + is-bigint: 1.1.0 + is-boolean-object: 1.2.2 + is-number-object: 1.1.1 + is-string: 1.1.1 + is-symbol: 1.1.1 + + which-collection@1.0.2: + dependencies: + is-map: 2.0.3 + is-set: 2.0.3 + is-weakmap: 2.0.2 + is-weakset: 2.0.4 + + which-typed-array@1.1.19: + dependencies: + available-typed-arrays: 1.0.7 + call-bind: 1.0.8 + call-bound: 1.0.4 + for-each: 0.3.5 + get-proto: 1.0.1 + gopd: 1.2.0 + has-tostringtag: 1.0.2 + which@2.0.2: dependencies: isexe: 2.0.0 diff --git a/scripts/generate-docs.ts b/scripts/generate-docs.ts index 6257d8a5..d01f4eb6 100644 --- a/scripts/generate-docs.ts +++ b/scripts/generate-docs.ts @@ -12,6 +12,18 @@ await generateReferenceDocs({ tsconfig: resolve(__dirname, '../packages/pacer/tsconfig.docs.json'), outputDir: resolve(__dirname, '../docs/reference'), }, + { + name: 'preact-pacer', + entryPoints: [ + resolve(__dirname, '../packages/preact-pacer/src/index.ts'), + ], + tsconfig: resolve( + __dirname, + '../packages/preact-pacer/tsconfig.docs.json', + ), + outputDir: resolve(__dirname, '../docs/framework/preact/reference'), + exclude: ['packages/pacer/**/*'], + }, { name: 'react-pacer', entryPoints: [resolve(__dirname, '../packages/react-pacer/src/index.ts')], diff --git a/vitest.workspace.js b/vitest.workspace.js index e5a5d999..1cd65719 100644 --- a/vitest.workspace.js +++ b/vitest.workspace.js @@ -5,6 +5,8 @@ export default defineConfig({ projects: [ './packages/pacer/vite.config.ts', './packages/pacer-lite/vite.config.ts', + './packages/preact-pacer/vitest.config.ts', + './packages/preact-pacer-devtools/vitest.config.ts', './packages/react-pacer/vite.config.ts', './packages/react-pacer-devtools/vite.config.ts', './packages/solid-pacer/vite.config.ts',