@tanstack/solid-pacer 0.18.3 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/async-batcher/createAsyncBatcher.cjs +32 -2
- package/dist/async-batcher/createAsyncBatcher.cjs.map +1 -1
- package/dist/async-batcher/createAsyncBatcher.d.cts +28 -2
- package/dist/async-batcher/createAsyncBatcher.d.ts +28 -2
- package/dist/async-batcher/createAsyncBatcher.js +32 -2
- package/dist/async-batcher/createAsyncBatcher.js.map +1 -1
- package/dist/async-batcher/index.cjs +1 -0
- package/dist/async-batcher/index.d.cts +2 -2
- package/dist/async-batcher/index.d.ts +2 -2
- package/dist/async-debouncer/createAsyncDebouncer.cjs +26 -3
- package/dist/async-debouncer/createAsyncDebouncer.cjs.map +1 -1
- package/dist/async-debouncer/createAsyncDebouncer.d.cts +27 -2
- package/dist/async-debouncer/createAsyncDebouncer.d.ts +27 -2
- package/dist/async-debouncer/createAsyncDebouncer.js +26 -3
- package/dist/async-debouncer/createAsyncDebouncer.js.map +1 -1
- package/dist/async-debouncer/index.cjs +1 -0
- package/dist/async-debouncer/index.d.cts +2 -2
- package/dist/async-debouncer/index.d.ts +2 -2
- package/dist/async-queuer/createAsyncQueuer.cjs +32 -2
- package/dist/async-queuer/createAsyncQueuer.cjs.map +1 -1
- package/dist/async-queuer/createAsyncQueuer.d.cts +28 -2
- package/dist/async-queuer/createAsyncQueuer.d.ts +28 -2
- package/dist/async-queuer/createAsyncQueuer.js +32 -2
- package/dist/async-queuer/createAsyncQueuer.js.map +1 -1
- package/dist/async-queuer/index.cjs +1 -0
- package/dist/async-queuer/index.d.cts +2 -2
- package/dist/async-queuer/index.d.ts +2 -2
- package/dist/async-rate-limiter/createAsyncRateLimiter.cjs +16 -2
- package/dist/async-rate-limiter/createAsyncRateLimiter.cjs.map +1 -1
- package/dist/async-rate-limiter/createAsyncRateLimiter.d.cts +15 -2
- package/dist/async-rate-limiter/createAsyncRateLimiter.d.ts +15 -2
- package/dist/async-rate-limiter/createAsyncRateLimiter.js +16 -2
- package/dist/async-rate-limiter/createAsyncRateLimiter.js.map +1 -1
- package/dist/async-rate-limiter/index.cjs +1 -0
- package/dist/async-rate-limiter/index.d.cts +2 -2
- package/dist/async-rate-limiter/index.d.ts +2 -2
- package/dist/async-throttler/createAsyncThrottler.cjs +31 -2
- package/dist/async-throttler/createAsyncThrottler.cjs.map +1 -1
- package/dist/async-throttler/createAsyncThrottler.d.cts +27 -2
- package/dist/async-throttler/createAsyncThrottler.d.ts +27 -2
- package/dist/async-throttler/createAsyncThrottler.js +31 -2
- package/dist/async-throttler/createAsyncThrottler.js.map +1 -1
- package/dist/async-throttler/index.cjs +1 -0
- package/dist/async-throttler/index.d.cts +2 -2
- package/dist/async-throttler/index.d.ts +2 -2
- package/dist/batcher/createBatcher.cjs +23 -2
- package/dist/batcher/createBatcher.cjs.map +1 -1
- package/dist/batcher/createBatcher.d.cts +22 -2
- package/dist/batcher/createBatcher.d.ts +22 -2
- package/dist/batcher/createBatcher.js +23 -2
- package/dist/batcher/createBatcher.js.map +1 -1
- package/dist/batcher/index.cjs +1 -0
- package/dist/batcher/index.d.cts +2 -2
- package/dist/batcher/index.d.ts +2 -2
- package/dist/debouncer/createDebouncedSignal.cjs.map +1 -1
- package/dist/debouncer/createDebouncedSignal.d.cts +3 -4
- package/dist/debouncer/createDebouncedSignal.d.ts +3 -4
- package/dist/debouncer/createDebouncedSignal.js.map +1 -1
- package/dist/debouncer/createDebouncedValue.cjs.map +1 -1
- package/dist/debouncer/createDebouncedValue.d.cts +3 -4
- package/dist/debouncer/createDebouncedValue.d.ts +3 -4
- package/dist/debouncer/createDebouncedValue.js.map +1 -1
- package/dist/debouncer/createDebouncer.cjs +17 -3
- package/dist/debouncer/createDebouncer.cjs.map +1 -1
- package/dist/debouncer/createDebouncer.d.cts +21 -2
- package/dist/debouncer/createDebouncer.d.ts +21 -2
- package/dist/debouncer/createDebouncer.js +17 -3
- package/dist/debouncer/createDebouncer.js.map +1 -1
- package/dist/debouncer/index.cjs +1 -0
- package/dist/debouncer/index.d.cts +2 -2
- package/dist/debouncer/index.d.ts +2 -2
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +11 -11
- package/dist/index.d.ts +11 -11
- package/dist/provider/index.cjs +1 -0
- package/dist/queuer/createQueuedSignal.cjs.map +1 -1
- package/dist/queuer/createQueuedSignal.d.cts +3 -4
- package/dist/queuer/createQueuedSignal.d.ts +3 -4
- package/dist/queuer/createQueuedSignal.js.map +1 -1
- package/dist/queuer/createQueuer.cjs +23 -2
- package/dist/queuer/createQueuer.cjs.map +1 -1
- package/dist/queuer/createQueuer.d.cts +22 -2
- package/dist/queuer/createQueuer.d.ts +22 -2
- package/dist/queuer/createQueuer.js +23 -2
- package/dist/queuer/createQueuer.js.map +1 -1
- package/dist/queuer/index.cjs +1 -0
- package/dist/queuer/index.d.cts +2 -2
- package/dist/queuer/index.d.ts +2 -2
- package/dist/rate-limiter/createRateLimitedSignal.cjs.map +1 -1
- package/dist/rate-limiter/createRateLimitedSignal.d.cts +3 -4
- package/dist/rate-limiter/createRateLimitedSignal.d.ts +3 -4
- package/dist/rate-limiter/createRateLimitedSignal.js.map +1 -1
- package/dist/rate-limiter/createRateLimitedValue.cjs.map +1 -1
- package/dist/rate-limiter/createRateLimitedValue.d.cts +3 -4
- package/dist/rate-limiter/createRateLimitedValue.d.ts +3 -4
- package/dist/rate-limiter/createRateLimitedValue.js.map +1 -1
- package/dist/rate-limiter/createRateLimiter.cjs +9 -2
- package/dist/rate-limiter/createRateLimiter.cjs.map +1 -1
- package/dist/rate-limiter/createRateLimiter.d.cts +9 -2
- package/dist/rate-limiter/createRateLimiter.d.ts +9 -2
- package/dist/rate-limiter/createRateLimiter.js +9 -2
- package/dist/rate-limiter/createRateLimiter.js.map +1 -1
- package/dist/rate-limiter/index.cjs +1 -0
- package/dist/rate-limiter/index.d.cts +2 -2
- package/dist/rate-limiter/index.d.ts +2 -2
- package/dist/throttler/createThrottledSignal.cjs.map +1 -1
- package/dist/throttler/createThrottledSignal.d.cts +3 -4
- package/dist/throttler/createThrottledSignal.d.ts +3 -4
- package/dist/throttler/createThrottledSignal.js.map +1 -1
- package/dist/throttler/createThrottledValue.cjs.map +1 -1
- package/dist/throttler/createThrottledValue.d.cts +3 -4
- package/dist/throttler/createThrottledValue.d.ts +3 -4
- package/dist/throttler/createThrottledValue.js.map +1 -1
- package/dist/throttler/createThrottler.cjs +17 -3
- package/dist/throttler/createThrottler.cjs.map +1 -1
- package/dist/throttler/createThrottler.d.cts +21 -2
- package/dist/throttler/createThrottler.d.ts +21 -2
- package/dist/throttler/createThrottler.js +17 -3
- package/dist/throttler/createThrottler.js.map +1 -1
- package/dist/throttler/index.cjs +1 -0
- package/dist/throttler/index.d.cts +2 -2
- package/dist/throttler/index.d.ts +2 -2
- package/package.json +33 -32
- package/src/async-batcher/createAsyncBatcher.ts +44 -3
- package/src/async-debouncer/createAsyncDebouncer.ts +37 -4
- package/src/async-queuer/createAsyncQueuer.ts +44 -3
- package/src/async-rate-limiter/createAsyncRateLimiter.ts +30 -3
- package/src/async-throttler/createAsyncThrottler.ts +43 -3
- package/src/batcher/createBatcher.ts +38 -3
- package/src/debouncer/createDebouncedSignal.ts +3 -6
- package/src/debouncer/createDebouncedValue.ts +3 -6
- package/src/debouncer/createDebouncer.ts +30 -4
- package/src/queuer/createQueuedSignal.ts +3 -3
- package/src/queuer/createQueuer.ts +37 -3
- package/src/rate-limiter/createRateLimitedSignal.ts +6 -6
- package/src/rate-limiter/createRateLimitedValue.ts +6 -6
- package/src/rate-limiter/createRateLimiter.ts +22 -3
- package/src/throttler/createThrottledSignal.ts +3 -6
- package/src/throttler/createThrottledValue.ts +3 -6
- package/src/throttler/createThrottler.ts +30 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRateLimitedValue.cjs","names":["createRateLimitedSignal"],"sources":["../../src/rate-limiter/createRateLimitedValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createRateLimitedSignal } from './createRateLimitedSignal'\nimport type {
|
|
1
|
+
{"version":3,"file":"createRateLimitedValue.cjs","names":["createRateLimitedSignal"],"sources":["../../src/rate-limiter/createRateLimitedValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createRateLimitedSignal } from './createRateLimitedSignal'\nimport type {\n SolidRateLimiter,\n SolidRateLimiterOptions,\n} from './createRateLimiter'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { RateLimiterState } from '@tanstack/pacer/rate-limiter'\n\n/**\n * A high-level Solid hook that creates a rate-limited version of a value that updates at most a certain number of times within a time window.\n * This hook uses Solid's createSignal internally to manage the rate-limited state.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All updates within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more\n * consistent rate of updates over time.\n *\n * For smoother update patterns, consider:\n * - createThrottledValue: When you want consistent spacing between updates (e.g. UI changes)\n * - createDebouncedValue: When you want to collapse rapid updates into a single update (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.\n *\n * The hook returns a tuple containing:\n * - An accessor function that provides the rate-limited value\n * - The rate limiter instance with control methods\n *\n * For more direct control over rate limiting behavior without Solid state management,\n * consider using the lower-level createRateLimiter hook instead.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying rate limiter instance.\n * The `selector` parameter allows you to specify which rate limiter state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you\n * full control over when your component subscribes to state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available rate limiter state properties:\n * - `executionCount`: Number of function executions that have been completed\n * - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations\n * - `rejectionCount`: Number of function executions that have been rejected due to rate limiting\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to reactive updates when execution count changes (optimized for tracking successful updates)\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to reactive updates when rejection count changes (optimized for tracking rate limit violations)\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n *\n * // Opt-in to reactive updates when execution times change (optimized for window calculations)\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionTimes: state.executionTimes })\n * );\n *\n * // With rejection callback and fixed window\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {\n * limit: 3,\n * window: 5000,\n * windowType: 'fixed',\n * onReject: (rateLimiter) => {\n * console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Access the selected rate limiter state (will be empty object {} unless selector provided)\n * const { executionCount, rejectionCount } = rateLimiter.state;\n * ```\n */\nexport function createRateLimitedValue<TValue, TSelected = {}>(\n value: Accessor<TValue>,\n initialOptions: SolidRateLimiterOptions<Setter<TValue>, TSelected>,\n selector?: (state: RateLimiterState) => TSelected,\n): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>, TSelected>] {\n const [rateLimitedValue, setRateLimitedValue, rateLimiter] =\n createRateLimitedSignal(value(), initialOptions, selector)\n\n createEffect(() => {\n setRateLimitedValue(value() as any)\n })\n\n return [rateLimitedValue, rateLimiter]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgGA,SAAgB,uBACd,OACA,gBACA,UACiE;CACjE,MAAM,CAAC,kBAAkB,qBAAqB,eAC5CA,wDAAwB,OAAO,EAAE,gBAAgB,SAAS;AAE5D,kCAAmB;AACjB,sBAAoB,OAAO,CAAQ;GACnC;AAEF,QAAO,CAAC,kBAAkB,YAAY"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { SolidRateLimiter } from "./createRateLimiter.cjs";
|
|
1
|
+
import { SolidRateLimiter, SolidRateLimiterOptions } from "./createRateLimiter.cjs";
|
|
2
2
|
import { Accessor, Setter } from "solid-js";
|
|
3
|
-
import {
|
|
3
|
+
import { RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
4
4
|
|
|
5
5
|
//#region src/rate-limiter/createRateLimitedValue.d.ts
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* A high-level Solid hook that creates a rate-limited version of a value that updates at most a certain number of times within a time window.
|
|
9
8
|
* This hook uses Solid's createSignal internally to manage the rate-limited state.
|
|
@@ -91,7 +90,7 @@ import { RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limit
|
|
|
91
90
|
* const { executionCount, rejectionCount } = rateLimiter.state;
|
|
92
91
|
* ```
|
|
93
92
|
*/
|
|
94
|
-
declare function createRateLimitedValue<TValue, TSelected = {}>(value: Accessor<TValue>, initialOptions:
|
|
93
|
+
declare function createRateLimitedValue<TValue, TSelected = {}>(value: Accessor<TValue>, initialOptions: SolidRateLimiterOptions<Setter<TValue>, TSelected>, selector?: (state: RateLimiterState) => TSelected): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>, TSelected>];
|
|
95
94
|
//#endregion
|
|
96
95
|
export { createRateLimitedValue };
|
|
97
96
|
//# sourceMappingURL=createRateLimitedValue.d.cts.map
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { SolidRateLimiter } from "./createRateLimiter.js";
|
|
1
|
+
import { SolidRateLimiter, SolidRateLimiterOptions } from "./createRateLimiter.js";
|
|
2
2
|
import { Accessor, Setter } from "solid-js";
|
|
3
|
-
import {
|
|
3
|
+
import { RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
4
4
|
|
|
5
5
|
//#region src/rate-limiter/createRateLimitedValue.d.ts
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* A high-level Solid hook that creates a rate-limited version of a value that updates at most a certain number of times within a time window.
|
|
9
8
|
* This hook uses Solid's createSignal internally to manage the rate-limited state.
|
|
@@ -91,7 +90,7 @@ import { RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limit
|
|
|
91
90
|
* const { executionCount, rejectionCount } = rateLimiter.state;
|
|
92
91
|
* ```
|
|
93
92
|
*/
|
|
94
|
-
declare function createRateLimitedValue<TValue, TSelected = {}>(value: Accessor<TValue>, initialOptions:
|
|
93
|
+
declare function createRateLimitedValue<TValue, TSelected = {}>(value: Accessor<TValue>, initialOptions: SolidRateLimiterOptions<Setter<TValue>, TSelected>, selector?: (state: RateLimiterState) => TSelected): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>, TSelected>];
|
|
95
94
|
//#endregion
|
|
96
95
|
export { createRateLimitedValue };
|
|
97
96
|
//# sourceMappingURL=createRateLimitedValue.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRateLimitedValue.js","names":[],"sources":["../../src/rate-limiter/createRateLimitedValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createRateLimitedSignal } from './createRateLimitedSignal'\nimport type {
|
|
1
|
+
{"version":3,"file":"createRateLimitedValue.js","names":[],"sources":["../../src/rate-limiter/createRateLimitedValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createRateLimitedSignal } from './createRateLimitedSignal'\nimport type {\n SolidRateLimiter,\n SolidRateLimiterOptions,\n} from './createRateLimiter'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { RateLimiterState } from '@tanstack/pacer/rate-limiter'\n\n/**\n * A high-level Solid hook that creates a rate-limited version of a value that updates at most a certain number of times within a time window.\n * This hook uses Solid's createSignal internally to manage the rate-limited state.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All updates within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more\n * consistent rate of updates over time.\n *\n * For smoother update patterns, consider:\n * - createThrottledValue: When you want consistent spacing between updates (e.g. UI changes)\n * - createDebouncedValue: When you want to collapse rapid updates into a single update (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.\n *\n * The hook returns a tuple containing:\n * - An accessor function that provides the rate-limited value\n * - The rate limiter instance with control methods\n *\n * For more direct control over rate limiting behavior without Solid state management,\n * consider using the lower-level createRateLimiter hook instead.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying rate limiter instance.\n * The `selector` parameter allows you to specify which rate limiter state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you\n * full control over when your component subscribes to state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available rate limiter state properties:\n * - `executionCount`: Number of function executions that have been completed\n * - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations\n * - `rejectionCount`: Number of function executions that have been rejected due to rate limiting\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to reactive updates when execution count changes (optimized for tracking successful updates)\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to reactive updates when rejection count changes (optimized for tracking rate limit violations)\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n *\n * // Opt-in to reactive updates when execution times change (optimized for window calculations)\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionTimes: state.executionTimes })\n * );\n *\n * // With rejection callback and fixed window\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {\n * limit: 3,\n * window: 5000,\n * windowType: 'fixed',\n * onReject: (rateLimiter) => {\n * console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Access the selected rate limiter state (will be empty object {} unless selector provided)\n * const { executionCount, rejectionCount } = rateLimiter.state;\n * ```\n */\nexport function createRateLimitedValue<TValue, TSelected = {}>(\n value: Accessor<TValue>,\n initialOptions: SolidRateLimiterOptions<Setter<TValue>, TSelected>,\n selector?: (state: RateLimiterState) => TSelected,\n): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>, TSelected>] {\n const [rateLimitedValue, setRateLimitedValue, rateLimiter] =\n createRateLimitedSignal(value(), initialOptions, selector)\n\n createEffect(() => {\n setRateLimitedValue(value() as any)\n })\n\n return [rateLimitedValue, rateLimiter]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgGA,SAAgB,uBACd,OACA,gBACA,UACiE;CACjE,MAAM,CAAC,kBAAkB,qBAAqB,eAC5C,wBAAwB,OAAO,EAAE,gBAAgB,SAAS;AAE5D,oBAAmB;AACjB,sBAAoB,OAAO,CAAQ;GACnC;AAEF,QAAO,CAAC,kBAAkB,YAAY"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const require_PacerProvider = require('../provider/PacerProvider.cjs');
|
|
2
|
+
let solid_js = require("solid-js");
|
|
2
3
|
let _tanstack_solid_store = require("@tanstack/solid-store");
|
|
3
4
|
let _tanstack_pacer_rate_limiter = require("@tanstack/pacer/rate-limiter");
|
|
4
5
|
|
|
@@ -130,15 +131,21 @@ let _tanstack_pacer_rate_limiter = require("@tanstack/pacer/rate-limiter");
|
|
|
130
131
|
* ```
|
|
131
132
|
*/
|
|
132
133
|
function createRateLimiter(fn, options, selector = () => ({})) {
|
|
133
|
-
const
|
|
134
|
+
const mergedOptions = {
|
|
134
135
|
...require_PacerProvider.useDefaultPacerOptions().rateLimiter,
|
|
135
136
|
...options
|
|
136
|
-
}
|
|
137
|
+
};
|
|
138
|
+
const rateLimiter = new _tanstack_pacer_rate_limiter.RateLimiter(fn, mergedOptions);
|
|
137
139
|
rateLimiter.Subscribe = function Subscribe(props) {
|
|
138
140
|
const selected = (0, _tanstack_solid_store.useStore)(rateLimiter.store, props.selector);
|
|
139
141
|
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
140
142
|
};
|
|
141
143
|
const state = (0, _tanstack_solid_store.useStore)(rateLimiter.store, selector);
|
|
144
|
+
(0, solid_js.createEffect)(() => {
|
|
145
|
+
(0, solid_js.onCleanup)(() => {
|
|
146
|
+
if (mergedOptions.onUnmount) mergedOptions.onUnmount(rateLimiter);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
142
149
|
return {
|
|
143
150
|
...rateLimiter,
|
|
144
151
|
state
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRateLimiter.cjs","names":["
|
|
1
|
+
{"version":3,"file":"createRateLimiter.cjs","names":["useDefaultPacerOptions","RateLimiter"],"sources":["../../src/rate-limiter/createRateLimiter.ts"],"sourcesContent":["import { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { useStore } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor, JSX } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\nexport interface SolidRateLimiterOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends RateLimiterOptions<TFn> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the rate limiter instance.\n * When provided, replaces the default cleanup; use it to call reset(), add logging, etc.\n */\n onUnmount?: (rateLimiter: SolidRateLimiter<TFn, TSelected>) => void\n}\n\nexport interface SolidRateLimiter<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<RateLimiter<TFn>, 'store'> {\n /**\n * A Solid component that allows you to subscribe to the rate limiter state.\n *\n * This is useful for tracking specific parts of the rate limiter state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <rateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount })}>\n * {(state) => (\n * <div>Rejections: {state().rejectionCount}</div>\n * )}\n * </rateLimiter.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: RateLimiterState) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the rate limiter state changes\n *\n * Use this instead of `rateLimiter.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<RateLimiterState>>\n}\n\n/**\n * A low-level Solid hook that creates a `RateLimiter` instance to enforce rate limits on function execution.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Rate limiting is a simple \"hard limit\" approach that allows executions until a maximum count is reached within\n * a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,\n * it does not attempt to space out or collapse executions intelligently.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All executions within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more\n * consistent rate of execution over time.\n *\n * For smoother execution patterns:\n * - Use throttling when you want consistent spacing between executions (e.g. UI updates)\n * - Use debouncing when you want to collapse rapid-fire events (e.g. search input)\n * - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `rateLimiter.Subscribe` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `executionCount`: Number of function executions that have been completed\n * - `rejectionCount`: Number of function calls that were rejected due to rate limiting\n * - `remainingInWindow`: Number of executions remaining in the current window\n * - `nextWindowTime`: Timestamp when the next window begins\n * - `currentWindowStart`: Timestamp when the current window started\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const rateLimiter = createRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * });\n *\n * // Subscribe to state changes deep in component tree using Subscribe component\n * <rateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount })}>\n * {(state) => (\n * <div>Rejections: {state().rejectionCount}</div>\n * )}\n * </rateLimiter.Subscribe>\n *\n * // Opt-in to track execution count changes at hook level (optimized for tracking successful executions)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to track rejection count changes (optimized for tracking rate limit violations)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n *\n * // Opt-in to track execution times changes (optimized for window calculations)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ executionTimes: state.executionTimes })\n * );\n *\n * // Multiple state properties - track when any of these change\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({\n * executionCount: state.executionCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Monitor rate limit status\n * const handleClick = () => {\n * const remaining = rateLimiter.getRemainingInWindow();\n * if (remaining > 0) {\n * rateLimiter.maybeExecute(data);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { executionCount, rejectionCount } = rateLimiter.state();\n * ```\n */\nexport function createRateLimiter<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: SolidRateLimiterOptions<TFn, TSelected>,\n selector: (state: RateLimiterState) => TSelected = () => ({}) as TSelected,\n): SolidRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().rateLimiter,\n ...options,\n } as SolidRateLimiterOptions<TFn, TSelected>\n const rateLimiter = new RateLimiter<TFn>(\n fn,\n mergedOptions,\n ) as unknown as SolidRateLimiter<TFn, TSelected>\n\n rateLimiter.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: RateLimiterState) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useStore(rateLimiter.store, props.selector)\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useStore(rateLimiter.store, selector)\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(rateLimiter)\n }\n })\n })\n\n return {\n ...rateLimiter,\n state,\n } as SolidRateLimiter<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwLA,SAAgB,kBACd,IACA,SACA,kBAA0D,EAAE,GAC1B;CAClC,MAAM,gBAAgB;EACpB,GAAGA,8CAAwB,CAAC;EAC5B,GAAG;EACJ;CACD,MAAM,cAAc,IAAIC,yCACtB,IACA,cACD;AAED,aAAY,YAAY,SAAS,UAAqB,OAGnD;EACD,MAAM,+CAAoB,YAAY,OAAO,MAAM,SAAS;AAE5D,SAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,4CAAiB,YAAY,OAAO,SAAS;AAEnD,kCAAmB;AACjB,gCAAgB;AACd,OAAI,cAAc,UAChB,eAAc,UAAU,YAAY;IAEtC;GACF;AAEF,QAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -4,6 +4,13 @@ import { AnyFunction } from "@tanstack/pacer/types";
|
|
|
4
4
|
import { RateLimiter, RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
5
5
|
|
|
6
6
|
//#region src/rate-limiter/createRateLimiter.d.ts
|
|
7
|
+
interface SolidRateLimiterOptions<TFn extends AnyFunction, TSelected = {}> extends RateLimiterOptions<TFn> {
|
|
8
|
+
/**
|
|
9
|
+
* Optional callback invoked when the owning component unmounts. Receives the rate limiter instance.
|
|
10
|
+
* When provided, replaces the default cleanup; use it to call reset(), add logging, etc.
|
|
11
|
+
*/
|
|
12
|
+
onUnmount?: (rateLimiter: SolidRateLimiter<TFn, TSelected>) => void;
|
|
13
|
+
}
|
|
7
14
|
interface SolidRateLimiter<TFn extends AnyFunction, TSelected = {}> extends Omit<RateLimiter<TFn>, 'store'> {
|
|
8
15
|
/**
|
|
9
16
|
* A Solid component that allows you to subscribe to the rate limiter state.
|
|
@@ -161,7 +168,7 @@ interface SolidRateLimiter<TFn extends AnyFunction, TSelected = {}> extends Omit
|
|
|
161
168
|
* const { executionCount, rejectionCount } = rateLimiter.state();
|
|
162
169
|
* ```
|
|
163
170
|
*/
|
|
164
|
-
declare function createRateLimiter<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options:
|
|
171
|
+
declare function createRateLimiter<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: SolidRateLimiterOptions<TFn, TSelected>, selector?: (state: RateLimiterState) => TSelected): SolidRateLimiter<TFn, TSelected>;
|
|
165
172
|
//#endregion
|
|
166
|
-
export { SolidRateLimiter, createRateLimiter };
|
|
173
|
+
export { SolidRateLimiter, SolidRateLimiterOptions, createRateLimiter };
|
|
167
174
|
//# sourceMappingURL=createRateLimiter.d.cts.map
|
|
@@ -4,6 +4,13 @@ import { RateLimiter, RateLimiterOptions, RateLimiterState } from "@tanstack/pac
|
|
|
4
4
|
import { AnyFunction } from "@tanstack/pacer/types";
|
|
5
5
|
|
|
6
6
|
//#region src/rate-limiter/createRateLimiter.d.ts
|
|
7
|
+
interface SolidRateLimiterOptions<TFn extends AnyFunction, TSelected = {}> extends RateLimiterOptions<TFn> {
|
|
8
|
+
/**
|
|
9
|
+
* Optional callback invoked when the owning component unmounts. Receives the rate limiter instance.
|
|
10
|
+
* When provided, replaces the default cleanup; use it to call reset(), add logging, etc.
|
|
11
|
+
*/
|
|
12
|
+
onUnmount?: (rateLimiter: SolidRateLimiter<TFn, TSelected>) => void;
|
|
13
|
+
}
|
|
7
14
|
interface SolidRateLimiter<TFn extends AnyFunction, TSelected = {}> extends Omit<RateLimiter<TFn>, 'store'> {
|
|
8
15
|
/**
|
|
9
16
|
* A Solid component that allows you to subscribe to the rate limiter state.
|
|
@@ -161,7 +168,7 @@ interface SolidRateLimiter<TFn extends AnyFunction, TSelected = {}> extends Omit
|
|
|
161
168
|
* const { executionCount, rejectionCount } = rateLimiter.state();
|
|
162
169
|
* ```
|
|
163
170
|
*/
|
|
164
|
-
declare function createRateLimiter<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options:
|
|
171
|
+
declare function createRateLimiter<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: SolidRateLimiterOptions<TFn, TSelected>, selector?: (state: RateLimiterState) => TSelected): SolidRateLimiter<TFn, TSelected>;
|
|
165
172
|
//#endregion
|
|
166
|
-
export { SolidRateLimiter, createRateLimiter };
|
|
173
|
+
export { SolidRateLimiter, SolidRateLimiterOptions, createRateLimiter };
|
|
167
174
|
//# sourceMappingURL=createRateLimiter.d.ts.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useDefaultPacerOptions } from "../provider/PacerProvider.js";
|
|
2
|
+
import { createEffect, onCleanup } from "solid-js";
|
|
2
3
|
import { useStore } from "@tanstack/solid-store";
|
|
3
4
|
import { RateLimiter } from "@tanstack/pacer/rate-limiter";
|
|
4
5
|
|
|
@@ -130,15 +131,21 @@ import { RateLimiter } from "@tanstack/pacer/rate-limiter";
|
|
|
130
131
|
* ```
|
|
131
132
|
*/
|
|
132
133
|
function createRateLimiter(fn, options, selector = () => ({})) {
|
|
133
|
-
const
|
|
134
|
+
const mergedOptions = {
|
|
134
135
|
...useDefaultPacerOptions().rateLimiter,
|
|
135
136
|
...options
|
|
136
|
-
}
|
|
137
|
+
};
|
|
138
|
+
const rateLimiter = new RateLimiter(fn, mergedOptions);
|
|
137
139
|
rateLimiter.Subscribe = function Subscribe(props) {
|
|
138
140
|
const selected = useStore(rateLimiter.store, props.selector);
|
|
139
141
|
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
140
142
|
};
|
|
141
143
|
const state = useStore(rateLimiter.store, selector);
|
|
144
|
+
createEffect(() => {
|
|
145
|
+
onCleanup(() => {
|
|
146
|
+
if (mergedOptions.onUnmount) mergedOptions.onUnmount(rateLimiter);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
142
149
|
return {
|
|
143
150
|
...rateLimiter,
|
|
144
151
|
state
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRateLimiter.js","names":[],"sources":["../../src/rate-limiter/createRateLimiter.ts"],"sourcesContent":["import { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { useStore } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor, JSX } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\nexport interface SolidRateLimiter<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<RateLimiter<TFn>, 'store'> {\n /**\n * A Solid component that allows you to subscribe to the rate limiter state.\n *\n * This is useful for tracking specific parts of the rate limiter state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <rateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount })}>\n * {(state) => (\n * <div>Rejections: {state().rejectionCount}</div>\n * )}\n * </rateLimiter.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: RateLimiterState) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the rate limiter state changes\n *\n * Use this instead of `rateLimiter.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<RateLimiterState>>\n}\n\n/**\n * A low-level Solid hook that creates a `RateLimiter` instance to enforce rate limits on function execution.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Rate limiting is a simple \"hard limit\" approach that allows executions until a maximum count is reached within\n * a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,\n * it does not attempt to space out or collapse executions intelligently.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All executions within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more\n * consistent rate of execution over time.\n *\n * For smoother execution patterns:\n * - Use throttling when you want consistent spacing between executions (e.g. UI updates)\n * - Use debouncing when you want to collapse rapid-fire events (e.g. search input)\n * - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `rateLimiter.Subscribe` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `executionCount`: Number of function executions that have been completed\n * - `rejectionCount`: Number of function calls that were rejected due to rate limiting\n * - `remainingInWindow`: Number of executions remaining in the current window\n * - `nextWindowTime`: Timestamp when the next window begins\n * - `currentWindowStart`: Timestamp when the current window started\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const rateLimiter = createRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * });\n *\n * // Subscribe to state changes deep in component tree using Subscribe component\n * <rateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount })}>\n * {(state) => (\n * <div>Rejections: {state().rejectionCount}</div>\n * )}\n * </rateLimiter.Subscribe>\n *\n * // Opt-in to track execution count changes at hook level (optimized for tracking successful executions)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to track rejection count changes (optimized for tracking rate limit violations)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n *\n * // Opt-in to track execution times changes (optimized for window calculations)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ executionTimes: state.executionTimes })\n * );\n *\n * // Multiple state properties - track when any of these change\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({\n * executionCount: state.executionCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Monitor rate limit status\n * const handleClick = () => {\n * const remaining = rateLimiter.getRemainingInWindow();\n * if (remaining > 0) {\n * rateLimiter.maybeExecute(data);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { executionCount, rejectionCount } = rateLimiter.state();\n * ```\n */\nexport function createRateLimiter<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options:
|
|
1
|
+
{"version":3,"file":"createRateLimiter.js","names":[],"sources":["../../src/rate-limiter/createRateLimiter.ts"],"sourcesContent":["import { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { useStore } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor, JSX } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\nexport interface SolidRateLimiterOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends RateLimiterOptions<TFn> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the rate limiter instance.\n * When provided, replaces the default cleanup; use it to call reset(), add logging, etc.\n */\n onUnmount?: (rateLimiter: SolidRateLimiter<TFn, TSelected>) => void\n}\n\nexport interface SolidRateLimiter<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<RateLimiter<TFn>, 'store'> {\n /**\n * A Solid component that allows you to subscribe to the rate limiter state.\n *\n * This is useful for tracking specific parts of the rate limiter state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <rateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount })}>\n * {(state) => (\n * <div>Rejections: {state().rejectionCount}</div>\n * )}\n * </rateLimiter.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: RateLimiterState) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the rate limiter state changes\n *\n * Use this instead of `rateLimiter.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<RateLimiterState>>\n}\n\n/**\n * A low-level Solid hook that creates a `RateLimiter` instance to enforce rate limits on function execution.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Rate limiting is a simple \"hard limit\" approach that allows executions until a maximum count is reached within\n * a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,\n * it does not attempt to space out or collapse executions intelligently.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All executions within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more\n * consistent rate of execution over time.\n *\n * For smoother execution patterns:\n * - Use throttling when you want consistent spacing between executions (e.g. UI updates)\n * - Use debouncing when you want to collapse rapid-fire events (e.g. search input)\n * - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `rateLimiter.Subscribe` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `executionCount`: Number of function executions that have been completed\n * - `rejectionCount`: Number of function calls that were rejected due to rate limiting\n * - `remainingInWindow`: Number of executions remaining in the current window\n * - `nextWindowTime`: Timestamp when the next window begins\n * - `currentWindowStart`: Timestamp when the current window started\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const rateLimiter = createRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * });\n *\n * // Subscribe to state changes deep in component tree using Subscribe component\n * <rateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount })}>\n * {(state) => (\n * <div>Rejections: {state().rejectionCount}</div>\n * )}\n * </rateLimiter.Subscribe>\n *\n * // Opt-in to track execution count changes at hook level (optimized for tracking successful executions)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to track rejection count changes (optimized for tracking rate limit violations)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n *\n * // Opt-in to track execution times changes (optimized for window calculations)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ executionTimes: state.executionTimes })\n * );\n *\n * // Multiple state properties - track when any of these change\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({\n * executionCount: state.executionCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Monitor rate limit status\n * const handleClick = () => {\n * const remaining = rateLimiter.getRemainingInWindow();\n * if (remaining > 0) {\n * rateLimiter.maybeExecute(data);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { executionCount, rejectionCount } = rateLimiter.state();\n * ```\n */\nexport function createRateLimiter<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: SolidRateLimiterOptions<TFn, TSelected>,\n selector: (state: RateLimiterState) => TSelected = () => ({}) as TSelected,\n): SolidRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().rateLimiter,\n ...options,\n } as SolidRateLimiterOptions<TFn, TSelected>\n const rateLimiter = new RateLimiter<TFn>(\n fn,\n mergedOptions,\n ) as unknown as SolidRateLimiter<TFn, TSelected>\n\n rateLimiter.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: RateLimiterState) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useStore(rateLimiter.store, props.selector)\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useStore(rateLimiter.store, selector)\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(rateLimiter)\n }\n })\n })\n\n return {\n ...rateLimiter,\n state,\n } as SolidRateLimiter<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwLA,SAAgB,kBACd,IACA,SACA,kBAA0D,EAAE,GAC1B;CAClC,MAAM,gBAAgB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ;CACD,MAAM,cAAc,IAAI,YACtB,IACA,cACD;AAED,aAAY,YAAY,SAAS,UAAqB,OAGnD;EACD,MAAM,WAAW,SAAS,YAAY,OAAO,MAAM,SAAS;AAE5D,SAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,QAAQ,SAAS,YAAY,OAAO,SAAS;AAEnD,oBAAmB;AACjB,kBAAgB;AACd,OAAI,cAAc,UAChB,eAAc,UAAU,YAAY;IAEtC;GACF;AAEF,QAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
1
2
|
const require_createRateLimiter = require('./createRateLimiter.cjs');
|
|
2
3
|
const require_createRateLimitedSignal = require('./createRateLimitedSignal.cjs');
|
|
3
4
|
const require_createRateLimitedValue = require('./createRateLimitedValue.cjs');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SolidRateLimiter, createRateLimiter } from "./createRateLimiter.cjs";
|
|
1
|
+
import { SolidRateLimiter, SolidRateLimiterOptions, createRateLimiter } from "./createRateLimiter.cjs";
|
|
2
2
|
import { createRateLimitedSignal } from "./createRateLimitedSignal.cjs";
|
|
3
3
|
import { createRateLimitedValue } from "./createRateLimitedValue.cjs";
|
|
4
4
|
export * from "@tanstack/pacer/rate-limiter";
|
|
5
|
-
export { SolidRateLimiter, createRateLimitedSignal, createRateLimitedValue, createRateLimiter };
|
|
5
|
+
export { SolidRateLimiter, SolidRateLimiterOptions, createRateLimitedSignal, createRateLimitedValue, createRateLimiter };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SolidRateLimiter, createRateLimiter } from "./createRateLimiter.js";
|
|
1
|
+
import { SolidRateLimiter, SolidRateLimiterOptions, createRateLimiter } from "./createRateLimiter.js";
|
|
2
2
|
import { createRateLimitedSignal } from "./createRateLimitedSignal.js";
|
|
3
3
|
import { createRateLimitedValue } from "./createRateLimitedValue.js";
|
|
4
4
|
export * from "@tanstack/pacer/rate-limiter";
|
|
5
|
-
export { SolidRateLimiter, createRateLimitedSignal, createRateLimitedValue, createRateLimiter };
|
|
5
|
+
export { SolidRateLimiter, SolidRateLimiterOptions, createRateLimitedSignal, createRateLimitedValue, createRateLimiter };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createThrottledSignal.cjs","names":["createThrottler"],"sources":["../../src/throttler/createThrottledSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createThrottler } from './createThrottler'\nimport type { SolidThrottler } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type {
|
|
1
|
+
{"version":3,"file":"createThrottledSignal.cjs","names":["createThrottler"],"sources":["../../src/throttler/createThrottledSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createThrottler } from './createThrottler'\nimport type { SolidThrottler, SolidThrottlerOptions } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { ThrottlerState } from '@tanstack/pacer/throttler'\n\n/**\n * A Solid hook that creates a throttled state value that updates at most once within a specified time window.\n * This hook combines Solid's createSignal with throttling functionality to provide controlled state updates.\n *\n * Throttling ensures state updates occur at a controlled rate regardless of how frequently the setter is called.\n * This is useful for rate-limiting expensive updates or operations that depend on rapidly changing state.\n *\n * The hook returns a tuple containing:\n * - The throttled state value accessor\n * - A throttled setter function that respects the configured wait time\n * - The throttler instance for additional control\n *\n * For more direct control over throttling without state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying throttler instance.\n * The `selector` parameter allows you to specify which throttler state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you\n * full control over when your component subscribes to state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger trailing execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Unix timestamp of the last execution\n * - `nextExecutionTime`: Unix timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [value, setValue, throttler] = createThrottledSignal(0, { wait: 1000 });\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const [value, setValue, throttler] = createThrottledSignal(\n * 0,\n * { wait: 1000 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // With custom leading/trailing behavior\n * const [value, setValue] = createThrottledSignal(0, {\n * wait: 1000,\n * leading: true, // Update immediately on first change\n * trailing: false // Skip trailing edge updates\n * });\n *\n * // Access throttler state via signals\n * console.log('Executions:', throttler.state().executionCount);\n * console.log('Is pending:', throttler.state().isPending);\n * console.log('Last execution:', throttler.state().lastExecutionTime);\n * console.log('Next execution:', throttler.state().nextExecutionTime);\n * ```\n */\nexport function createThrottledSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: SolidThrottlerOptions<Setter<TValue>, TSelected>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidThrottler<Setter<TValue>, TSelected>,\n] {\n const [throttledValue, setThrottledValue] = createSignal<TValue>(value)\n const throttler = createThrottler(setThrottledValue, initialOptions, selector)\n return [throttledValue, throttler.maybeExecute as Setter<TValue>, throttler]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,SAAgB,sBACd,OACA,gBACA,UAKA;CACA,MAAM,CAAC,gBAAgB,gDAA0C,MAAM;CACvE,MAAM,YAAYA,wCAAgB,mBAAmB,gBAAgB,SAAS;AAC9E,QAAO;EAAC;EAAgB,UAAU;EAAgC;EAAU"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { SolidThrottler } from "./createThrottler.cjs";
|
|
1
|
+
import { SolidThrottler, SolidThrottlerOptions } from "./createThrottler.cjs";
|
|
2
2
|
import { Accessor, Setter } from "solid-js";
|
|
3
|
-
import {
|
|
3
|
+
import { ThrottlerState } from "@tanstack/pacer/throttler";
|
|
4
4
|
|
|
5
5
|
//#region src/throttler/createThrottledSignal.d.ts
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* A Solid hook that creates a throttled state value that updates at most once within a specified time window.
|
|
9
8
|
* This hook combines Solid's createSignal with throttling functionality to provide controlled state updates.
|
|
@@ -66,7 +65,7 @@ import { ThrottlerOptions, ThrottlerState } from "@tanstack/pacer/throttler";
|
|
|
66
65
|
* console.log('Next execution:', throttler.state().nextExecutionTime);
|
|
67
66
|
* ```
|
|
68
67
|
*/
|
|
69
|
-
declare function createThrottledSignal<TValue, TSelected = {}>(value: TValue, initialOptions:
|
|
68
|
+
declare function createThrottledSignal<TValue, TSelected = {}>(value: TValue, initialOptions: SolidThrottlerOptions<Setter<TValue>, TSelected>, selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected): [Accessor<TValue>, Setter<TValue>, SolidThrottler<Setter<TValue>, TSelected>];
|
|
70
69
|
//#endregion
|
|
71
70
|
export { createThrottledSignal };
|
|
72
71
|
//# sourceMappingURL=createThrottledSignal.d.cts.map
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { SolidThrottler } from "./createThrottler.js";
|
|
1
|
+
import { SolidThrottler, SolidThrottlerOptions } from "./createThrottler.js";
|
|
2
2
|
import { Accessor, Setter } from "solid-js";
|
|
3
|
-
import {
|
|
3
|
+
import { ThrottlerState } from "@tanstack/pacer/throttler";
|
|
4
4
|
|
|
5
5
|
//#region src/throttler/createThrottledSignal.d.ts
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* A Solid hook that creates a throttled state value that updates at most once within a specified time window.
|
|
9
8
|
* This hook combines Solid's createSignal with throttling functionality to provide controlled state updates.
|
|
@@ -66,7 +65,7 @@ import { ThrottlerOptions, ThrottlerState } from "@tanstack/pacer/throttler";
|
|
|
66
65
|
* console.log('Next execution:', throttler.state().nextExecutionTime);
|
|
67
66
|
* ```
|
|
68
67
|
*/
|
|
69
|
-
declare function createThrottledSignal<TValue, TSelected = {}>(value: TValue, initialOptions:
|
|
68
|
+
declare function createThrottledSignal<TValue, TSelected = {}>(value: TValue, initialOptions: SolidThrottlerOptions<Setter<TValue>, TSelected>, selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected): [Accessor<TValue>, Setter<TValue>, SolidThrottler<Setter<TValue>, TSelected>];
|
|
70
69
|
//#endregion
|
|
71
70
|
export { createThrottledSignal };
|
|
72
71
|
//# sourceMappingURL=createThrottledSignal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createThrottledSignal.js","names":[],"sources":["../../src/throttler/createThrottledSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createThrottler } from './createThrottler'\nimport type { SolidThrottler } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type {
|
|
1
|
+
{"version":3,"file":"createThrottledSignal.js","names":[],"sources":["../../src/throttler/createThrottledSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createThrottler } from './createThrottler'\nimport type { SolidThrottler, SolidThrottlerOptions } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { ThrottlerState } from '@tanstack/pacer/throttler'\n\n/**\n * A Solid hook that creates a throttled state value that updates at most once within a specified time window.\n * This hook combines Solid's createSignal with throttling functionality to provide controlled state updates.\n *\n * Throttling ensures state updates occur at a controlled rate regardless of how frequently the setter is called.\n * This is useful for rate-limiting expensive updates or operations that depend on rapidly changing state.\n *\n * The hook returns a tuple containing:\n * - The throttled state value accessor\n * - A throttled setter function that respects the configured wait time\n * - The throttler instance for additional control\n *\n * For more direct control over throttling without state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying throttler instance.\n * The `selector` parameter allows you to specify which throttler state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you\n * full control over when your component subscribes to state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger trailing execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Unix timestamp of the last execution\n * - `nextExecutionTime`: Unix timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [value, setValue, throttler] = createThrottledSignal(0, { wait: 1000 });\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const [value, setValue, throttler] = createThrottledSignal(\n * 0,\n * { wait: 1000 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // With custom leading/trailing behavior\n * const [value, setValue] = createThrottledSignal(0, {\n * wait: 1000,\n * leading: true, // Update immediately on first change\n * trailing: false // Skip trailing edge updates\n * });\n *\n * // Access throttler state via signals\n * console.log('Executions:', throttler.state().executionCount);\n * console.log('Is pending:', throttler.state().isPending);\n * console.log('Last execution:', throttler.state().lastExecutionTime);\n * console.log('Next execution:', throttler.state().nextExecutionTime);\n * ```\n */\nexport function createThrottledSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: SolidThrottlerOptions<Setter<TValue>, TSelected>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidThrottler<Setter<TValue>, TSelected>,\n] {\n const [throttledValue, setThrottledValue] = createSignal<TValue>(value)\n const throttler = createThrottler(setThrottledValue, initialOptions, selector)\n return [throttledValue, throttler.maybeExecute as Setter<TValue>, throttler]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,SAAgB,sBACd,OACA,gBACA,UAKA;CACA,MAAM,CAAC,gBAAgB,qBAAqB,aAAqB,MAAM;CACvE,MAAM,YAAY,gBAAgB,mBAAmB,gBAAgB,SAAS;AAC9E,QAAO;EAAC;EAAgB,UAAU;EAAgC;EAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createThrottledValue.cjs","names":["createThrottledSignal"],"sources":["../../src/throttler/createThrottledValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createThrottledSignal } from './createThrottledSignal'\nimport type { SolidThrottler } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type {
|
|
1
|
+
{"version":3,"file":"createThrottledValue.cjs","names":["createThrottledSignal"],"sources":["../../src/throttler/createThrottledValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createThrottledSignal } from './createThrottledSignal'\nimport type { SolidThrottler, SolidThrottlerOptions } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { ThrottlerState } from '@tanstack/pacer/throttler'\n\n/**\n * A high-level Solid hook that creates a throttled version of a value that updates at most once within a specified time window.\n * This hook uses Solid's createSignal internally to manage the throttled state.\n *\n * Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes.\n * This is useful for rate-limiting expensive updates or API calls that depend on rapidly changing values.\n *\n * The hook returns a tuple containing:\n * - An accessor function that provides the throttled value\n * - The throttler instance with control methods\n *\n * The throttled value will update according to the leading/trailing edge behavior specified in the options.\n *\n * For more direct control over throttling behavior without Solid state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying throttler instance.\n * The `selector` parameter allows you to specify which throttler state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you\n * full control over when your component subscribes to state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger trailing execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Unix timestamp of the last execution\n * - `nextExecutionTime`: Unix timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [throttledValue, throttler] = createThrottledValue(rawValue, { wait: 1000 });\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const [throttledValue, throttler] = createThrottledValue(\n * rawValue,\n * { wait: 1000 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Use the throttled value\n * console.log(throttledValue()); // Access the current throttled value\n *\n * // Access throttler state via signals\n * console.log('Is pending:', throttler.state().isPending);\n *\n * // Control the throttler\n * throttler.cancel(); // Cancel any pending updates\n * ```\n */\nexport function createThrottledValue<TValue, TSelected = {}>(\n value: Accessor<TValue>,\n initialOptions: SolidThrottlerOptions<Setter<TValue>, TSelected>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): [Accessor<TValue>, SolidThrottler<Setter<TValue>, TSelected>] {\n const [throttledValue, setThrottledValue, throttler] = createThrottledSignal(\n value(),\n initialOptions,\n selector,\n )\n\n createEffect(() => {\n setThrottledValue(value() as any)\n })\n\n return [throttledValue, throttler]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,SAAgB,qBACd,OACA,gBACA,UAC+D;CAC/D,MAAM,CAAC,gBAAgB,mBAAmB,aAAaA,oDACrD,OAAO,EACP,gBACA,SACD;AAED,kCAAmB;AACjB,oBAAkB,OAAO,CAAQ;GACjC;AAEF,QAAO,CAAC,gBAAgB,UAAU"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { SolidThrottler } from "./createThrottler.cjs";
|
|
1
|
+
import { SolidThrottler, SolidThrottlerOptions } from "./createThrottler.cjs";
|
|
2
2
|
import { Accessor, Setter } from "solid-js";
|
|
3
|
-
import {
|
|
3
|
+
import { ThrottlerState } from "@tanstack/pacer/throttler";
|
|
4
4
|
|
|
5
5
|
//#region src/throttler/createThrottledValue.d.ts
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* A high-level Solid hook that creates a throttled version of a value that updates at most once within a specified time window.
|
|
9
8
|
* This hook uses Solid's createSignal internally to manage the throttled state.
|
|
@@ -63,7 +62,7 @@ import { ThrottlerOptions, ThrottlerState } from "@tanstack/pacer/throttler";
|
|
|
63
62
|
* throttler.cancel(); // Cancel any pending updates
|
|
64
63
|
* ```
|
|
65
64
|
*/
|
|
66
|
-
declare function createThrottledValue<TValue, TSelected = {}>(value: Accessor<TValue>, initialOptions:
|
|
65
|
+
declare function createThrottledValue<TValue, TSelected = {}>(value: Accessor<TValue>, initialOptions: SolidThrottlerOptions<Setter<TValue>, TSelected>, selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected): [Accessor<TValue>, SolidThrottler<Setter<TValue>, TSelected>];
|
|
67
66
|
//#endregion
|
|
68
67
|
export { createThrottledValue };
|
|
69
68
|
//# sourceMappingURL=createThrottledValue.d.cts.map
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { SolidThrottler } from "./createThrottler.js";
|
|
1
|
+
import { SolidThrottler, SolidThrottlerOptions } from "./createThrottler.js";
|
|
2
2
|
import { Accessor, Setter } from "solid-js";
|
|
3
|
-
import {
|
|
3
|
+
import { ThrottlerState } from "@tanstack/pacer/throttler";
|
|
4
4
|
|
|
5
5
|
//#region src/throttler/createThrottledValue.d.ts
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* A high-level Solid hook that creates a throttled version of a value that updates at most once within a specified time window.
|
|
9
8
|
* This hook uses Solid's createSignal internally to manage the throttled state.
|
|
@@ -63,7 +62,7 @@ import { ThrottlerOptions, ThrottlerState } from "@tanstack/pacer/throttler";
|
|
|
63
62
|
* throttler.cancel(); // Cancel any pending updates
|
|
64
63
|
* ```
|
|
65
64
|
*/
|
|
66
|
-
declare function createThrottledValue<TValue, TSelected = {}>(value: Accessor<TValue>, initialOptions:
|
|
65
|
+
declare function createThrottledValue<TValue, TSelected = {}>(value: Accessor<TValue>, initialOptions: SolidThrottlerOptions<Setter<TValue>, TSelected>, selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected): [Accessor<TValue>, SolidThrottler<Setter<TValue>, TSelected>];
|
|
67
66
|
//#endregion
|
|
68
67
|
export { createThrottledValue };
|
|
69
68
|
//# sourceMappingURL=createThrottledValue.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createThrottledValue.js","names":[],"sources":["../../src/throttler/createThrottledValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createThrottledSignal } from './createThrottledSignal'\nimport type { SolidThrottler } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type {
|
|
1
|
+
{"version":3,"file":"createThrottledValue.js","names":[],"sources":["../../src/throttler/createThrottledValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createThrottledSignal } from './createThrottledSignal'\nimport type { SolidThrottler, SolidThrottlerOptions } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { ThrottlerState } from '@tanstack/pacer/throttler'\n\n/**\n * A high-level Solid hook that creates a throttled version of a value that updates at most once within a specified time window.\n * This hook uses Solid's createSignal internally to manage the throttled state.\n *\n * Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes.\n * This is useful for rate-limiting expensive updates or API calls that depend on rapidly changing values.\n *\n * The hook returns a tuple containing:\n * - An accessor function that provides the throttled value\n * - The throttler instance with control methods\n *\n * The throttled value will update according to the leading/trailing edge behavior specified in the options.\n *\n * For more direct control over throttling behavior without Solid state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying throttler instance.\n * The `selector` parameter allows you to specify which throttler state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you\n * full control over when your component subscribes to state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger trailing execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Unix timestamp of the last execution\n * - `nextExecutionTime`: Unix timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [throttledValue, throttler] = createThrottledValue(rawValue, { wait: 1000 });\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const [throttledValue, throttler] = createThrottledValue(\n * rawValue,\n * { wait: 1000 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Use the throttled value\n * console.log(throttledValue()); // Access the current throttled value\n *\n * // Access throttler state via signals\n * console.log('Is pending:', throttler.state().isPending);\n *\n * // Control the throttler\n * throttler.cancel(); // Cancel any pending updates\n * ```\n */\nexport function createThrottledValue<TValue, TSelected = {}>(\n value: Accessor<TValue>,\n initialOptions: SolidThrottlerOptions<Setter<TValue>, TSelected>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): [Accessor<TValue>, SolidThrottler<Setter<TValue>, TSelected>] {\n const [throttledValue, setThrottledValue, throttler] = createThrottledSignal(\n value(),\n initialOptions,\n selector,\n )\n\n createEffect(() => {\n setThrottledValue(value() as any)\n })\n\n return [throttledValue, throttler]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,SAAgB,qBACd,OACA,gBACA,UAC+D;CAC/D,MAAM,CAAC,gBAAgB,mBAAmB,aAAa,sBACrD,OAAO,EACP,gBACA,SACD;AAED,oBAAmB;AACjB,oBAAkB,OAAO,CAAQ;GACjC;AAEF,QAAO,CAAC,gBAAgB,UAAU"}
|
|
@@ -46,6 +46,18 @@ let _tanstack_pacer_throttler = require("@tanstack/pacer/throttler");
|
|
|
46
46
|
* - `nextExecutionTime`: Timestamp of the next allowed execution
|
|
47
47
|
* - `status`: Current execution status ('disabled' | 'idle' | 'pending')
|
|
48
48
|
*
|
|
49
|
+
* ## Unmount behavior
|
|
50
|
+
*
|
|
51
|
+
* By default, the primitive cancels any pending execution when the owning component unmounts.
|
|
52
|
+
* Use the `onUnmount` option to customize this. For example, to flush pending work instead:
|
|
53
|
+
*
|
|
54
|
+
* ```tsx
|
|
55
|
+
* const throttler = createThrottler(fn, {
|
|
56
|
+
* wait: 1000,
|
|
57
|
+
* onUnmount: (t) => t.flush()
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
49
61
|
* @example
|
|
50
62
|
* ```tsx
|
|
51
63
|
* // Default behavior - no reactive state subscriptions
|
|
@@ -93,10 +105,11 @@ let _tanstack_pacer_throttler = require("@tanstack/pacer/throttler");
|
|
|
93
105
|
* ```
|
|
94
106
|
*/
|
|
95
107
|
function createThrottler(fn, options, selector = () => ({})) {
|
|
96
|
-
const
|
|
108
|
+
const mergedOptions = {
|
|
97
109
|
...require_PacerProvider.useDefaultPacerOptions().throttler,
|
|
98
110
|
...options
|
|
99
|
-
}
|
|
111
|
+
};
|
|
112
|
+
const asyncThrottler = new _tanstack_pacer_throttler.Throttler(fn, mergedOptions);
|
|
100
113
|
asyncThrottler.Subscribe = function Subscribe(props) {
|
|
101
114
|
const selected = (0, _tanstack_solid_store.useStore)(asyncThrottler.store, props.selector);
|
|
102
115
|
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
@@ -104,7 +117,8 @@ function createThrottler(fn, options, selector = () => ({})) {
|
|
|
104
117
|
const state = (0, _tanstack_solid_store.useStore)(asyncThrottler.store, selector);
|
|
105
118
|
(0, solid_js.createEffect)(() => {
|
|
106
119
|
(0, solid_js.onCleanup)(() => {
|
|
107
|
-
|
|
120
|
+
if (mergedOptions.onUnmount) mergedOptions.onUnmount(asyncThrottler);
|
|
121
|
+
else asyncThrottler.cancel();
|
|
108
122
|
});
|
|
109
123
|
});
|
|
110
124
|
return {
|