@tanstack/preact-pacer 0.21.1 → 0.22.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/dist/async-batcher/useAsyncBatcher.cjs +2 -2
- package/dist/async-batcher/useAsyncBatcher.cjs.map +1 -1
- package/dist/async-batcher/useAsyncBatcher.d.cts +2 -2
- package/dist/async-batcher/useAsyncBatcher.d.ts +2 -2
- package/dist/async-batcher/useAsyncBatcher.js +3 -3
- package/dist/async-batcher/useAsyncBatcher.js.map +1 -1
- package/dist/async-debouncer/useAsyncDebouncer.cjs +2 -2
- package/dist/async-debouncer/useAsyncDebouncer.cjs.map +1 -1
- package/dist/async-debouncer/useAsyncDebouncer.d.cts +2 -2
- package/dist/async-debouncer/useAsyncDebouncer.d.ts +2 -2
- package/dist/async-debouncer/useAsyncDebouncer.js +3 -3
- package/dist/async-debouncer/useAsyncDebouncer.js.map +1 -1
- package/dist/async-queuer/useAsyncQueuer.cjs +2 -2
- package/dist/async-queuer/useAsyncQueuer.cjs.map +1 -1
- package/dist/async-queuer/useAsyncQueuer.d.cts +2 -2
- package/dist/async-queuer/useAsyncQueuer.d.ts +2 -2
- package/dist/async-queuer/useAsyncQueuer.js +3 -3
- package/dist/async-queuer/useAsyncQueuer.js.map +1 -1
- package/dist/async-rate-limiter/useAsyncRateLimiter.cjs +2 -2
- package/dist/async-rate-limiter/useAsyncRateLimiter.cjs.map +1 -1
- package/dist/async-rate-limiter/useAsyncRateLimiter.d.cts +2 -2
- package/dist/async-rate-limiter/useAsyncRateLimiter.d.ts +2 -2
- package/dist/async-rate-limiter/useAsyncRateLimiter.js +3 -3
- package/dist/async-rate-limiter/useAsyncRateLimiter.js.map +1 -1
- package/dist/async-throttler/useAsyncThrottler.cjs +2 -2
- package/dist/async-throttler/useAsyncThrottler.cjs.map +1 -1
- package/dist/async-throttler/useAsyncThrottler.d.cts +2 -2
- package/dist/async-throttler/useAsyncThrottler.d.ts +2 -2
- package/dist/async-throttler/useAsyncThrottler.js +3 -3
- package/dist/async-throttler/useAsyncThrottler.js.map +1 -1
- package/dist/batcher/useBatcher.cjs +2 -2
- package/dist/batcher/useBatcher.cjs.map +1 -1
- package/dist/batcher/useBatcher.d.cts +2 -2
- package/dist/batcher/useBatcher.d.ts +2 -2
- package/dist/batcher/useBatcher.js +3 -3
- package/dist/batcher/useBatcher.js.map +1 -1
- package/dist/debouncer/useDebouncer.cjs +2 -2
- package/dist/debouncer/useDebouncer.cjs.map +1 -1
- package/dist/debouncer/useDebouncer.d.cts +2 -2
- package/dist/debouncer/useDebouncer.d.ts +2 -2
- package/dist/debouncer/useDebouncer.js +3 -3
- package/dist/debouncer/useDebouncer.js.map +1 -1
- package/dist/queuer/useQueuer.cjs +2 -2
- package/dist/queuer/useQueuer.cjs.map +1 -1
- package/dist/queuer/useQueuer.d.cts +2 -2
- package/dist/queuer/useQueuer.d.ts +2 -2
- package/dist/queuer/useQueuer.js +3 -3
- package/dist/queuer/useQueuer.js.map +1 -1
- package/dist/rate-limiter/useRateLimiter.cjs +2 -2
- package/dist/rate-limiter/useRateLimiter.cjs.map +1 -1
- package/dist/rate-limiter/useRateLimiter.d.cts +2 -2
- package/dist/rate-limiter/useRateLimiter.d.ts +2 -2
- package/dist/rate-limiter/useRateLimiter.js +3 -3
- package/dist/rate-limiter/useRateLimiter.js.map +1 -1
- package/dist/throttler/useThrottler.cjs +2 -2
- package/dist/throttler/useThrottler.cjs.map +1 -1
- package/dist/throttler/useThrottler.d.cts +2 -2
- package/dist/throttler/useThrottler.d.ts +2 -2
- package/dist/throttler/useThrottler.js +3 -3
- package/dist/throttler/useThrottler.js.map +1 -1
- package/package.json +5 -5
- package/src/async-batcher/useAsyncBatcher.ts +6 -6
- package/src/async-debouncer/useAsyncDebouncer.ts +8 -6
- package/src/async-queuer/useAsyncQueuer.ts +6 -6
- package/src/async-rate-limiter/useAsyncRateLimiter.ts +8 -6
- package/src/async-throttler/useAsyncThrottler.ts +8 -6
- package/src/batcher/useBatcher.ts +6 -6
- package/src/debouncer/useDebouncer.ts +6 -6
- package/src/queuer/useQueuer.ts +6 -6
- package/src/rate-limiter/useRateLimiter.ts +6 -6
- package/src/throttler/useThrottler.ts +6 -6
|
@@ -37,8 +37,8 @@ interface PreactThrottler<TFn extends AnyFunction, TSelected = {}> extends Omit<
|
|
|
37
37
|
readonly state: Readonly<TSelected>;
|
|
38
38
|
/**
|
|
39
39
|
* @deprecated Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state.
|
|
40
|
-
* The state on the store object is not reactive, as it has not been wrapped in a `
|
|
41
|
-
* Although, you can make the state reactive by using the `
|
|
40
|
+
* The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
|
|
41
|
+
* Although, you can make the state reactive by using the `useSelector` in your own usage.
|
|
42
42
|
*/
|
|
43
43
|
readonly store: Store<Readonly<ThrottlerState<TFn>>>;
|
|
44
44
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useDefaultPacerOptions } from "../provider/PacerProvider.js";
|
|
2
2
|
import { useEffect, useMemo, useState } from "preact/hooks";
|
|
3
|
-
import { shallow,
|
|
3
|
+
import { shallow, useSelector } from "@tanstack/preact-store";
|
|
4
4
|
import { Throttler } from "@tanstack/pacer/throttler";
|
|
5
5
|
|
|
6
6
|
//#region src/throttler/useThrottler.ts
|
|
@@ -121,14 +121,14 @@ function useThrottler(fn, options, selector = () => ({})) {
|
|
|
121
121
|
const [throttler] = useState(() => {
|
|
122
122
|
const throttlerInstance = new Throttler(fn, mergedOptions);
|
|
123
123
|
throttlerInstance.Subscribe = function Subscribe(props) {
|
|
124
|
-
const selected =
|
|
124
|
+
const selected = useSelector(throttlerInstance.store, props.selector, { compare: shallow });
|
|
125
125
|
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
126
126
|
};
|
|
127
127
|
return throttlerInstance;
|
|
128
128
|
});
|
|
129
129
|
throttler.fn = fn;
|
|
130
130
|
throttler.setOptions(mergedOptions);
|
|
131
|
-
const state =
|
|
131
|
+
const state = useSelector(throttler.store, selector, { compare: shallow });
|
|
132
132
|
useEffect(() => {
|
|
133
133
|
return () => {
|
|
134
134
|
if (mergedOptions.onUnmount) mergedOptions.onUnmount(throttler);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useThrottler.js","names":[],"sources":["../../src/throttler/useThrottler.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from 'preact/hooks'\nimport { Throttler } from '@tanstack/pacer/throttler'\nimport { shallow,
|
|
1
|
+
{"version":3,"file":"useThrottler.js","names":[],"sources":["../../src/throttler/useThrottler.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from 'preact/hooks'\nimport { Throttler } from '@tanstack/pacer/throttler'\nimport { shallow, useSelector } from '@tanstack/preact-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/preact-store'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\nimport type { ComponentChildren } from 'preact'\n\nexport interface PreactThrottlerOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends ThrottlerOptions<TFn> {\n /**\n * Optional callback invoked when the component unmounts. Receives the throttler instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), reset(), cancel(), add logging, etc.\n */\n onUnmount?: (throttler: PreactThrottler<TFn, TSelected>) => void\n}\n\nexport interface PreactThrottler<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Throttler<TFn>, 'store'> {\n /**\n * A Preact HOC (Higher Order Component) that allows you to subscribe to the throttler state.\n *\n * This is useful for opting into state re-renders for specific parts of the throttler state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <throttler.Subscribe selector={(state) => ({ isPending: state.isPending })}>\n * {({ isPending }) => (\n * <div>{isPending ? 'Loading...' : 'Ready'}</div>\n * )}\n * </throttler.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: ThrottlerState<TFn>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n }) => ComponentChildren\n /**\n * Reactive state that will be updated and re-rendered when the throttler state changes\n *\n * Use this instead of `throttler.store.state`\n */\n readonly state: Readonly<TSelected>\n /**\n * @deprecated Use `throttler.state` instead of `throttler.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 `useSelector` hook internally.\n * Although, you can make the state reactive by using the `useSelector` in your own usage.\n */\n readonly store: Store<Readonly<ThrottlerState<TFn>>>\n}\n\n/**\n * A low-level Preact hook that creates a `Throttler` instance that limits how often the provided function can execute.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that\n * you can integrate with any state management solution (useState, Redux, Zustand, Jotai, etc). For a simpler and higher-level hook that\n * integrates directly with Preact's useState, see useThrottledState.\n *\n * Throttling ensures a function executes at most once within a specified time window,\n * regardless of how many times it is called. This is useful for rate-limiting\n * expensive operations or UI updates.\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 `throttler.Subscribe` HOC (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` HOC 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 a re-render\n * at the hook level, optimizing performance by preventing unnecessary re-renders 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` HOC. This prevents unnecessary\n * re-renders and gives you full control over when your component updates.\n *\n * Available state properties:\n * - `executionCount`: Number of function executions that have been completed\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last function execution in milliseconds\n * - `nextExecutionTime`: Timestamp when the next execution can occur in milliseconds\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * ## Unmount behavior\n *\n * By default, the hook cancels any pending execution when the component unmounts.\n * Use the `onUnmount` option to customize this. For example, to flush pending work instead:\n *\n * ```tsx\n * const throttler = useThrottler(fn, {\n * wait: 1000,\n * onUnmount: (t) => t.flush()\n * });\n * ```\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [value, setValue] = useState(0);\n * const throttler = useThrottler(setValue, { wait: 1000 });\n *\n * // Subscribe to state changes deep in component tree using Subscribe HOC\n * <throttler.Subscribe selector={(state) => ({ isPending: state.isPending })}>\n * {({ isPending }) => (\n * <div>{isPending ? 'Processing...' : 'Ready'}</div>\n * )}\n * </throttler.Subscribe>\n *\n * // Opt-in to re-render when execution count changes at hook level (optimized for tracking executions)\n * const [value, setValue] = useState(0);\n * const throttler = useThrottler(\n * setValue,\n * { wait: 1000 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to re-render when throttling state changes (optimized for loading indicators)\n * const [value, setValue] = useState(0);\n * const throttler = useThrottler(\n * setValue,\n * { wait: 1000 },\n * (state) => ({\n * isPending: state.isPending,\n * status: state.status\n * })\n * );\n *\n * // Opt-in to re-render when timing information changes (optimized for timing displays)\n * const [value, setValue] = useState(0);\n * const throttler = useThrottler(\n * setValue,\n * { wait: 1000 },\n * (state) => ({\n * lastExecutionTime: state.lastExecutionTime,\n * nextExecutionTime: state.nextExecutionTime\n * })\n * );\n *\n * // With any state manager\n * const throttler = useThrottler(\n * (value) => stateManager.setState(value),\n * {\n * wait: 2000,\n * leading: true, // Execute immediately on first call\n * trailing: false // Skip trailing edge updates\n * }\n * );\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { executionCount, isPending } = throttler.state;\n * ```\n */\nexport function useThrottler<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: PreactThrottlerOptions<TFn, TSelected>,\n selector: (state: ThrottlerState<TFn>) => TSelected = () => ({}) as TSelected,\n): PreactThrottler<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().throttler,\n ...options,\n } as PreactThrottlerOptions<TFn, TSelected>\n const [throttler] = useState(() => {\n const throttlerInstance = new Throttler<TFn>(\n fn,\n mergedOptions,\n ) as unknown as PreactThrottler<TFn, TSelected>\n\n throttlerInstance.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: ThrottlerState<TFn>) => TSelected\n children: ((state: TSelected) => ComponentChildren) | ComponentChildren\n }) {\n const selected = useSelector(throttlerInstance.store, props.selector, {\n compare: shallow,\n })\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n return throttlerInstance\n })\n\n throttler.fn = fn\n throttler.setOptions(mergedOptions)\n\n const state = useSelector(throttler.store, selector, { compare: shallow })\n\n /* eslint-disable react-hooks/exhaustive-deps -- cleanup only; runs on unmount */\n useEffect(() => {\n return () => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(throttler)\n } else {\n throttler.cancel()\n }\n }\n }, [])\n /* eslint-enable react-hooks/exhaustive-deps */\n\n return useMemo(\n () =>\n ({\n ...throttler,\n state,\n }) as PreactThrottler<TFn, TSelected>, // omit `store` in favor of `state`\n [throttler, state],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuKA,SAAgB,aACd,IACA,SACA,kBAA6D,EAAE,GAC9B;CACjC,MAAM,gBAAgB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ;CACD,MAAM,CAAC,aAAa,eAAe;EACjC,MAAM,oBAAoB,IAAI,UAC5B,IACA,cACD;AAED,oBAAkB,YAAY,SAAS,UAAqB,OAGzD;GACD,MAAM,WAAW,YAAY,kBAAkB,OAAO,MAAM,UAAU,EACpE,SAAS,SACV,CAAC;AAEF,UAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;AAGZ,SAAO;GACP;AAEF,WAAU,KAAK;AACf,WAAU,WAAW,cAAc;CAEnC,MAAM,QAAQ,YAAY,UAAU,OAAO,UAAU,EAAE,SAAS,SAAS,CAAC;AAG1E,iBAAgB;AACd,eAAa;AACX,OAAI,cAAc,UAChB,eAAc,UAAU,UAAU;OAElC,WAAU,QAAQ;;IAGrB,EAAE,CAAC;AAGN,QAAO,eAEF;EACC,GAAG;EACH;EACD,GACH,CAAC,WAAW,MAAM,CACnB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/preact-pacer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "Utilities for debouncing and throttling functions in Preact.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -98,13 +98,13 @@
|
|
|
98
98
|
"src"
|
|
99
99
|
],
|
|
100
100
|
"dependencies": {
|
|
101
|
-
"@tanstack/preact-store": "^0.
|
|
102
|
-
"@tanstack/pacer": "0.
|
|
101
|
+
"@tanstack/preact-store": "^0.13.0",
|
|
102
|
+
"@tanstack/pacer": "0.21.0"
|
|
103
103
|
},
|
|
104
104
|
"devDependencies": {
|
|
105
105
|
"@preact/preset-vite": "^2.10.5",
|
|
106
|
-
"eslint-plugin-react-hooks": "^7.0
|
|
107
|
-
"preact": "^10.29.
|
|
106
|
+
"eslint-plugin-react-hooks": "^7.1.0",
|
|
107
|
+
"preact": "^10.29.1"
|
|
108
108
|
},
|
|
109
109
|
"peerDependencies": {
|
|
110
110
|
"preact": ">=10.0.0"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useMemo, useState } from 'preact/hooks'
|
|
2
2
|
import { AsyncBatcher } from '@tanstack/pacer/async-batcher'
|
|
3
|
-
import { shallow,
|
|
3
|
+
import { shallow, useSelector } from '@tanstack/preact-store'
|
|
4
4
|
import { useDefaultPacerOptions } from '../provider/PacerProvider'
|
|
5
5
|
import type { Store } from '@tanstack/preact-store'
|
|
6
6
|
import type {
|
|
@@ -49,8 +49,8 @@ export interface PreactAsyncBatcher<TValue, TSelected = {}> extends Omit<
|
|
|
49
49
|
readonly state: Readonly<TSelected>
|
|
50
50
|
/**
|
|
51
51
|
* @deprecated Use `batcher.state` instead of `batcher.store.state` if you want to read reactive state.
|
|
52
|
-
* The state on the store object is not reactive, as it has not been wrapped in a `
|
|
53
|
-
* Although, you can make the state reactive by using the `
|
|
52
|
+
* The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
|
|
53
|
+
* Although, you can make the state reactive by using the `useSelector` in your own usage.
|
|
54
54
|
*/
|
|
55
55
|
readonly store: Store<Readonly<AsyncBatcherState<TValue>>>
|
|
56
56
|
}
|
|
@@ -252,8 +252,8 @@ export function useAsyncBatcher<TValue, TSelected = {}>(
|
|
|
252
252
|
selector: (state: AsyncBatcherState<TValue>) => TSelected
|
|
253
253
|
children: ((state: TSelected) => ComponentChildren) | ComponentChildren
|
|
254
254
|
}) {
|
|
255
|
-
const selected =
|
|
256
|
-
|
|
255
|
+
const selected = useSelector(batcherInstance.store, props.selector, {
|
|
256
|
+
compare: shallow,
|
|
257
257
|
})
|
|
258
258
|
|
|
259
259
|
return typeof props.children === 'function'
|
|
@@ -280,7 +280,7 @@ export function useAsyncBatcher<TValue, TSelected = {}>(
|
|
|
280
280
|
}, [])
|
|
281
281
|
/* eslint-enable react-hooks/exhaustive-deps */
|
|
282
282
|
|
|
283
|
-
const state =
|
|
283
|
+
const state = useSelector(asyncBatcher.store, selector, { compare: shallow })
|
|
284
284
|
|
|
285
285
|
return useMemo(
|
|
286
286
|
() =>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useMemo, useState } from 'preact/hooks'
|
|
2
2
|
import { AsyncDebouncer } from '@tanstack/pacer/async-debouncer'
|
|
3
|
-
import { shallow,
|
|
3
|
+
import { shallow, useSelector } from '@tanstack/preact-store'
|
|
4
4
|
import { useDefaultPacerOptions } from '../provider/PacerProvider'
|
|
5
5
|
import type { Store } from '@tanstack/preact-store'
|
|
6
6
|
import type { AnyAsyncFunction } from '@tanstack/pacer/types'
|
|
@@ -50,8 +50,8 @@ export interface PreactAsyncDebouncer<
|
|
|
50
50
|
readonly state: Readonly<TSelected>
|
|
51
51
|
/**
|
|
52
52
|
* @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state.
|
|
53
|
-
* The state on the store object is not reactive, as it has not been wrapped in a `
|
|
54
|
-
* Although, you can make the state reactive by using the `
|
|
53
|
+
* The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
|
|
54
|
+
* Although, you can make the state reactive by using the `useSelector` in your own usage.
|
|
55
55
|
*/
|
|
56
56
|
readonly store: Store<Readonly<AsyncDebouncerState<TFn>>>
|
|
57
57
|
}
|
|
@@ -231,8 +231,8 @@ export function useAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = {}>(
|
|
|
231
231
|
selector: (state: AsyncDebouncerState<TFn>) => TSelected
|
|
232
232
|
children: ((state: TSelected) => ComponentChildren) | ComponentChildren
|
|
233
233
|
}) {
|
|
234
|
-
const selected =
|
|
235
|
-
|
|
234
|
+
const selected = useSelector(debouncerInstance.store, props.selector, {
|
|
235
|
+
compare: shallow,
|
|
236
236
|
})
|
|
237
237
|
|
|
238
238
|
return typeof props.children === 'function'
|
|
@@ -246,7 +246,9 @@ export function useAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = {}>(
|
|
|
246
246
|
asyncDebouncer.fn = fn
|
|
247
247
|
asyncDebouncer.setOptions(mergedOptions)
|
|
248
248
|
|
|
249
|
-
const state =
|
|
249
|
+
const state = useSelector(asyncDebouncer.store, selector, {
|
|
250
|
+
compare: shallow,
|
|
251
|
+
})
|
|
250
252
|
|
|
251
253
|
/* eslint-disable react-hooks/exhaustive-deps -- cleanup only; runs on unmount */
|
|
252
254
|
useEffect(() => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useMemo, useState } from 'preact/hooks'
|
|
2
2
|
import { AsyncQueuer } from '@tanstack/pacer/async-queuer'
|
|
3
|
-
import { shallow,
|
|
3
|
+
import { shallow, useSelector } from '@tanstack/preact-store'
|
|
4
4
|
import { useDefaultPacerOptions } from '../provider/PacerProvider'
|
|
5
5
|
import type { Store } from '@tanstack/preact-store'
|
|
6
6
|
import type {
|
|
@@ -49,8 +49,8 @@ export interface PreactAsyncQueuer<TValue, TSelected = {}> extends Omit<
|
|
|
49
49
|
readonly state: Readonly<TSelected>
|
|
50
50
|
/**
|
|
51
51
|
* @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.
|
|
52
|
-
* The state on the store object is not reactive, as it has not been wrapped in a `
|
|
53
|
-
* Although, you can make the state reactive by using the `
|
|
52
|
+
* The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
|
|
53
|
+
* Although, you can make the state reactive by using the `useSelector` in your own usage.
|
|
54
54
|
*/
|
|
55
55
|
readonly store: Store<Readonly<AsyncQueuerState<TValue>>>
|
|
56
56
|
}
|
|
@@ -252,8 +252,8 @@ export function useAsyncQueuer<TValue, TSelected = {}>(
|
|
|
252
252
|
selector: (state: AsyncQueuerState<TValue>) => TSelected
|
|
253
253
|
children: ((state: TSelected) => ComponentChildren) | ComponentChildren
|
|
254
254
|
}) {
|
|
255
|
-
const selected =
|
|
256
|
-
|
|
255
|
+
const selected = useSelector(queuerInstance.store, props.selector, {
|
|
256
|
+
compare: shallow,
|
|
257
257
|
})
|
|
258
258
|
|
|
259
259
|
return typeof props.children === 'function'
|
|
@@ -280,7 +280,7 @@ export function useAsyncQueuer<TValue, TSelected = {}>(
|
|
|
280
280
|
}, [])
|
|
281
281
|
/* eslint-enable react-hooks/exhaustive-deps */
|
|
282
282
|
|
|
283
|
-
const state =
|
|
283
|
+
const state = useSelector(asyncQueuer.store, selector, { compare: shallow })
|
|
284
284
|
|
|
285
285
|
return useMemo(
|
|
286
286
|
() =>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useMemo, useState } from 'preact/hooks'
|
|
2
2
|
import { AsyncRateLimiter } from '@tanstack/pacer/async-rate-limiter'
|
|
3
|
-
import { shallow,
|
|
3
|
+
import { shallow, useSelector } from '@tanstack/preact-store'
|
|
4
4
|
import { useDefaultPacerOptions } from '../provider/PacerProvider'
|
|
5
5
|
import type { Store } from '@tanstack/preact-store'
|
|
6
6
|
import type { AnyAsyncFunction } from '@tanstack/pacer/types'
|
|
@@ -50,8 +50,8 @@ export interface PreactAsyncRateLimiter<
|
|
|
50
50
|
readonly state: Readonly<TSelected>
|
|
51
51
|
/**
|
|
52
52
|
* @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.
|
|
53
|
-
* The state on the store object is not reactive, as it has not been wrapped in a `
|
|
54
|
-
* Although, you can make the state reactive by using the `
|
|
53
|
+
* The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
|
|
54
|
+
* Although, you can make the state reactive by using the `useSelector` in your own usage.
|
|
55
55
|
*/
|
|
56
56
|
readonly store: Store<Readonly<AsyncRateLimiterState<TFn>>>
|
|
57
57
|
}
|
|
@@ -252,8 +252,8 @@ export function useAsyncRateLimiter<
|
|
|
252
252
|
selector: (state: AsyncRateLimiterState<TFn>) => TSelected
|
|
253
253
|
children: ((state: TSelected) => ComponentChildren) | ComponentChildren
|
|
254
254
|
}) {
|
|
255
|
-
const selected =
|
|
256
|
-
|
|
255
|
+
const selected = useSelector(rateLimiterInstance.store, props.selector, {
|
|
256
|
+
compare: shallow,
|
|
257
257
|
})
|
|
258
258
|
|
|
259
259
|
return typeof props.children === 'function'
|
|
@@ -279,7 +279,9 @@ export function useAsyncRateLimiter<
|
|
|
279
279
|
}, [])
|
|
280
280
|
/* eslint-enable react-hooks/exhaustive-deps */
|
|
281
281
|
|
|
282
|
-
const state =
|
|
282
|
+
const state = useSelector(asyncRateLimiter.store, selector, {
|
|
283
|
+
compare: shallow,
|
|
284
|
+
})
|
|
283
285
|
|
|
284
286
|
return useMemo(
|
|
285
287
|
() =>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useMemo, useState } from 'preact/hooks'
|
|
2
2
|
import { AsyncThrottler } from '@tanstack/pacer/async-throttler'
|
|
3
|
-
import { shallow,
|
|
3
|
+
import { shallow, useSelector } from '@tanstack/preact-store'
|
|
4
4
|
import { useDefaultPacerOptions } from '../provider/PacerProvider'
|
|
5
5
|
import type { Store } from '@tanstack/preact-store'
|
|
6
6
|
import type { AnyAsyncFunction } from '@tanstack/pacer/types'
|
|
@@ -50,8 +50,8 @@ export interface PreactAsyncThrottler<
|
|
|
50
50
|
readonly state: Readonly<TSelected>
|
|
51
51
|
/**
|
|
52
52
|
* @deprecated Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state.
|
|
53
|
-
* The state on the store object is not reactive, as it has not been wrapped in a `
|
|
54
|
-
* Although, you can make the state reactive by using the `
|
|
53
|
+
* The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
|
|
54
|
+
* Although, you can make the state reactive by using the `useSelector` in your own usage.
|
|
55
55
|
*/
|
|
56
56
|
readonly store: Store<Readonly<AsyncThrottlerState<TFn>>>
|
|
57
57
|
}
|
|
@@ -242,8 +242,8 @@ export function useAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}>(
|
|
|
242
242
|
selector: (state: AsyncThrottlerState<TFn>) => TSelected
|
|
243
243
|
children: ((state: TSelected) => ComponentChildren) | ComponentChildren
|
|
244
244
|
}) {
|
|
245
|
-
const selected =
|
|
246
|
-
|
|
245
|
+
const selected = useSelector(throttlerInstance.store, props.selector, {
|
|
246
|
+
compare: shallow,
|
|
247
247
|
})
|
|
248
248
|
|
|
249
249
|
return typeof props.children === 'function'
|
|
@@ -257,7 +257,9 @@ export function useAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}>(
|
|
|
257
257
|
asyncThrottler.fn = fn
|
|
258
258
|
asyncThrottler.setOptions(mergedOptions)
|
|
259
259
|
|
|
260
|
-
const state =
|
|
260
|
+
const state = useSelector(asyncThrottler.store, selector, {
|
|
261
|
+
compare: shallow,
|
|
262
|
+
})
|
|
261
263
|
|
|
262
264
|
/* eslint-disable react-hooks/exhaustive-deps -- cleanup only; runs on unmount */
|
|
263
265
|
useEffect(() => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useMemo, useState } from 'preact/hooks'
|
|
2
2
|
import { Batcher } from '@tanstack/pacer/batcher'
|
|
3
|
-
import { shallow,
|
|
3
|
+
import { shallow, useSelector } from '@tanstack/preact-store'
|
|
4
4
|
import { useDefaultPacerOptions } from '../provider/PacerProvider'
|
|
5
5
|
import type { Store } from '@tanstack/preact-store'
|
|
6
6
|
import type { BatcherOptions, BatcherState } from '@tanstack/pacer/batcher'
|
|
@@ -46,8 +46,8 @@ export interface PreactBatcher<TValue, TSelected = {}> extends Omit<
|
|
|
46
46
|
readonly state: Readonly<TSelected>
|
|
47
47
|
/**
|
|
48
48
|
* @deprecated Use `batcher.state` instead of `batcher.store.state` if you want to read reactive state.
|
|
49
|
-
* The state on the store object is not reactive, as it has not been wrapped in a `
|
|
50
|
-
* Although, you can make the state reactive by using the `
|
|
49
|
+
* The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
|
|
50
|
+
* Although, you can make the state reactive by using the `useSelector` in your own usage.
|
|
51
51
|
*/
|
|
52
52
|
readonly store: Store<Readonly<BatcherState<TValue>>>
|
|
53
53
|
}
|
|
@@ -201,8 +201,8 @@ export function useBatcher<TValue, TSelected = {}>(
|
|
|
201
201
|
selector: (state: BatcherState<TValue>) => TSelected
|
|
202
202
|
children: ((state: TSelected) => ComponentChildren) | ComponentChildren
|
|
203
203
|
}) {
|
|
204
|
-
const selected =
|
|
205
|
-
|
|
204
|
+
const selected = useSelector(batcherInstance.store, props.selector, {
|
|
205
|
+
compare: shallow,
|
|
206
206
|
})
|
|
207
207
|
|
|
208
208
|
return typeof props.children === 'function'
|
|
@@ -228,7 +228,7 @@ export function useBatcher<TValue, TSelected = {}>(
|
|
|
228
228
|
}, [])
|
|
229
229
|
/* eslint-enable react-hooks/exhaustive-deps */
|
|
230
230
|
|
|
231
|
-
const state =
|
|
231
|
+
const state = useSelector(batcher.store, selector, { compare: shallow })
|
|
232
232
|
|
|
233
233
|
return useMemo(
|
|
234
234
|
() =>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useMemo, useState } from 'preact/hooks'
|
|
2
2
|
import { Debouncer } from '@tanstack/pacer/debouncer'
|
|
3
|
-
import { shallow,
|
|
3
|
+
import { shallow, useSelector } from '@tanstack/preact-store'
|
|
4
4
|
import { useDefaultPacerOptions } from '../provider/PacerProvider'
|
|
5
5
|
import type { Store } from '@tanstack/preact-store'
|
|
6
6
|
import type {
|
|
@@ -50,8 +50,8 @@ export interface PreactDebouncer<
|
|
|
50
50
|
readonly state: Readonly<TSelected>
|
|
51
51
|
/**
|
|
52
52
|
* @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state.
|
|
53
|
-
* The state on the store object is not reactive, as it has not been wrapped in a `
|
|
54
|
-
* Although, you can make the state reactive by using the `
|
|
53
|
+
* The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
|
|
54
|
+
* Although, you can make the state reactive by using the `useSelector` in your own usage.
|
|
55
55
|
*/
|
|
56
56
|
readonly store: Store<Readonly<DebouncerState<TFn>>>
|
|
57
57
|
}
|
|
@@ -179,8 +179,8 @@ export function useDebouncer<TFn extends AnyFunction, TSelected = {}>(
|
|
|
179
179
|
selector: (state: DebouncerState<TFn>) => TSelected
|
|
180
180
|
children: ((state: TSelected) => ComponentChildren) | ComponentChildren
|
|
181
181
|
}) {
|
|
182
|
-
const selected =
|
|
183
|
-
|
|
182
|
+
const selected = useSelector(debouncerInstance.store, props.selector, {
|
|
183
|
+
compare: shallow,
|
|
184
184
|
})
|
|
185
185
|
|
|
186
186
|
return typeof props.children === 'function'
|
|
@@ -206,7 +206,7 @@ export function useDebouncer<TFn extends AnyFunction, TSelected = {}>(
|
|
|
206
206
|
}, [])
|
|
207
207
|
/* eslint-enable react-hooks/exhaustive-deps */
|
|
208
208
|
|
|
209
|
-
const state =
|
|
209
|
+
const state = useSelector(debouncer.store, selector, { compare: shallow })
|
|
210
210
|
|
|
211
211
|
return useMemo(
|
|
212
212
|
() =>
|
package/src/queuer/useQueuer.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useMemo, useState } from 'preact/hooks'
|
|
2
2
|
import { Queuer } from '@tanstack/pacer/queuer'
|
|
3
|
-
import { shallow,
|
|
3
|
+
import { shallow, useSelector } from '@tanstack/preact-store'
|
|
4
4
|
import { useDefaultPacerOptions } from '../provider/PacerProvider'
|
|
5
5
|
import type { Store } from '@tanstack/preact-store'
|
|
6
6
|
import type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'
|
|
@@ -46,8 +46,8 @@ export interface PreactQueuer<TValue, TSelected = {}> extends Omit<
|
|
|
46
46
|
readonly state: Readonly<TSelected>
|
|
47
47
|
/**
|
|
48
48
|
* @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.
|
|
49
|
-
* The state on the store object is not reactive, as it has not been wrapped in a `
|
|
50
|
-
* Although, you can make the state reactive by using the `
|
|
49
|
+
* The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
|
|
50
|
+
* Although, you can make the state reactive by using the `useSelector` in your own usage.
|
|
51
51
|
*/
|
|
52
52
|
readonly store: Store<Readonly<QueuerState<TValue>>>
|
|
53
53
|
}
|
|
@@ -211,8 +211,8 @@ export function useQueuer<TValue, TSelected = {}>(
|
|
|
211
211
|
selector: (state: QueuerState<TValue>) => TSelected
|
|
212
212
|
children: ((state: TSelected) => ComponentChildren) | ComponentChildren
|
|
213
213
|
}) {
|
|
214
|
-
const selected =
|
|
215
|
-
|
|
214
|
+
const selected = useSelector(queuerInstance.store, props.selector, {
|
|
215
|
+
compare: shallow,
|
|
216
216
|
})
|
|
217
217
|
|
|
218
218
|
return typeof props.children === 'function'
|
|
@@ -238,7 +238,7 @@ export function useQueuer<TValue, TSelected = {}>(
|
|
|
238
238
|
}, [])
|
|
239
239
|
/* eslint-enable react-hooks/exhaustive-deps */
|
|
240
240
|
|
|
241
|
-
const state =
|
|
241
|
+
const state = useSelector(queuer.store, selector, { compare: shallow })
|
|
242
242
|
|
|
243
243
|
return useMemo(
|
|
244
244
|
() =>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useMemo, useState } from 'preact/hooks'
|
|
2
2
|
import { RateLimiter } from '@tanstack/pacer/rate-limiter'
|
|
3
|
-
import { shallow,
|
|
3
|
+
import { shallow, useSelector } from '@tanstack/preact-store'
|
|
4
4
|
import { useDefaultPacerOptions } from '../provider/PacerProvider'
|
|
5
5
|
import type { Store } from '@tanstack/preact-store'
|
|
6
6
|
import type {
|
|
@@ -50,8 +50,8 @@ export interface PreactRateLimiter<
|
|
|
50
50
|
readonly state: Readonly<TSelected>
|
|
51
51
|
/**
|
|
52
52
|
* @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.
|
|
53
|
-
* The state on the store object is not reactive, as it has not been wrapped in a `
|
|
54
|
-
* Although, you can make the state reactive by using the `
|
|
53
|
+
* The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
|
|
54
|
+
* Although, you can make the state reactive by using the `useSelector` in your own usage.
|
|
55
55
|
*/
|
|
56
56
|
readonly store: Store<Readonly<RateLimiterState>>
|
|
57
57
|
}
|
|
@@ -206,8 +206,8 @@ export function useRateLimiter<TFn extends AnyFunction, TSelected = {}>(
|
|
|
206
206
|
selector: (state: RateLimiterState) => TSelected
|
|
207
207
|
children: ((state: TSelected) => ComponentChildren) | ComponentChildren
|
|
208
208
|
}) {
|
|
209
|
-
const selected =
|
|
210
|
-
|
|
209
|
+
const selected = useSelector(rateLimiterInstance.store, props.selector, {
|
|
210
|
+
compare: shallow,
|
|
211
211
|
})
|
|
212
212
|
|
|
213
213
|
return typeof props.children === 'function'
|
|
@@ -231,7 +231,7 @@ export function useRateLimiter<TFn extends AnyFunction, TSelected = {}>(
|
|
|
231
231
|
}, [])
|
|
232
232
|
/* eslint-enable react-hooks/exhaustive-deps */
|
|
233
233
|
|
|
234
|
-
const state =
|
|
234
|
+
const state = useSelector(rateLimiter.store, selector, { compare: shallow })
|
|
235
235
|
|
|
236
236
|
return useMemo(
|
|
237
237
|
() =>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useMemo, useState } from 'preact/hooks'
|
|
2
2
|
import { Throttler } from '@tanstack/pacer/throttler'
|
|
3
|
-
import { shallow,
|
|
3
|
+
import { shallow, useSelector } from '@tanstack/preact-store'
|
|
4
4
|
import { useDefaultPacerOptions } from '../provider/PacerProvider'
|
|
5
5
|
import type { Store } from '@tanstack/preact-store'
|
|
6
6
|
import type { AnyFunction } from '@tanstack/pacer/types'
|
|
@@ -50,8 +50,8 @@ export interface PreactThrottler<
|
|
|
50
50
|
readonly state: Readonly<TSelected>
|
|
51
51
|
/**
|
|
52
52
|
* @deprecated Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state.
|
|
53
|
-
* The state on the store object is not reactive, as it has not been wrapped in a `
|
|
54
|
-
* Although, you can make the state reactive by using the `
|
|
53
|
+
* The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
|
|
54
|
+
* Although, you can make the state reactive by using the `useSelector` in your own usage.
|
|
55
55
|
*/
|
|
56
56
|
readonly store: Store<Readonly<ThrottlerState<TFn>>>
|
|
57
57
|
}
|
|
@@ -184,8 +184,8 @@ export function useThrottler<TFn extends AnyFunction, TSelected = {}>(
|
|
|
184
184
|
selector: (state: ThrottlerState<TFn>) => TSelected
|
|
185
185
|
children: ((state: TSelected) => ComponentChildren) | ComponentChildren
|
|
186
186
|
}) {
|
|
187
|
-
const selected =
|
|
188
|
-
|
|
187
|
+
const selected = useSelector(throttlerInstance.store, props.selector, {
|
|
188
|
+
compare: shallow,
|
|
189
189
|
})
|
|
190
190
|
|
|
191
191
|
return typeof props.children === 'function'
|
|
@@ -199,7 +199,7 @@ export function useThrottler<TFn extends AnyFunction, TSelected = {}>(
|
|
|
199
199
|
throttler.fn = fn
|
|
200
200
|
throttler.setOptions(mergedOptions)
|
|
201
201
|
|
|
202
|
-
const state =
|
|
202
|
+
const state = useSelector(throttler.store, selector, { compare: shallow })
|
|
203
203
|
|
|
204
204
|
/* eslint-disable react-hooks/exhaustive-deps -- cleanup only; runs on unmount */
|
|
205
205
|
useEffect(() => {
|