@tanstack/angular-pacer 0.23.1 → 0.24.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 +17 -2
- package/dist/async-batcher/injectAsyncBatchedCallback.cjs.map +1 -1
- package/dist/async-batcher/injectAsyncBatchedCallback.d.cts +0 -1
- package/dist/async-batcher/injectAsyncBatchedCallback.d.ts +0 -1
- package/dist/async-batcher/injectAsyncBatchedCallback.js.map +1 -1
- package/dist/async-batcher/injectAsyncBatcher.cjs.map +1 -1
- package/dist/async-batcher/injectAsyncBatcher.d.cts +0 -1
- package/dist/async-batcher/injectAsyncBatcher.d.ts +0 -1
- package/dist/async-batcher/injectAsyncBatcher.js.map +1 -1
- package/dist/async-debouncer/injectAsyncDebouncedCallback.cjs.map +1 -1
- package/dist/async-debouncer/injectAsyncDebouncedCallback.d.cts +0 -1
- package/dist/async-debouncer/injectAsyncDebouncedCallback.d.ts +0 -1
- package/dist/async-debouncer/injectAsyncDebouncedCallback.js.map +1 -1
- package/dist/async-debouncer/injectAsyncDebouncer.cjs.map +1 -1
- package/dist/async-debouncer/injectAsyncDebouncer.d.cts +0 -1
- package/dist/async-debouncer/injectAsyncDebouncer.d.ts +0 -1
- package/dist/async-debouncer/injectAsyncDebouncer.js.map +1 -1
- package/dist/async-queuer/injectAsyncQueuedSignal.cjs.map +1 -1
- package/dist/async-queuer/injectAsyncQueuedSignal.d.cts +0 -1
- package/dist/async-queuer/injectAsyncQueuedSignal.d.ts +0 -1
- package/dist/async-queuer/injectAsyncQueuedSignal.js.map +1 -1
- package/dist/async-queuer/injectAsyncQueuer.cjs.map +1 -1
- package/dist/async-queuer/injectAsyncQueuer.d.cts +0 -1
- package/dist/async-queuer/injectAsyncQueuer.d.ts +0 -1
- package/dist/async-queuer/injectAsyncQueuer.js.map +1 -1
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.cjs.map +1 -1
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.d.cts +0 -1
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.d.ts +0 -1
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.js.map +1 -1
- package/dist/async-rate-limiter/injectAsyncRateLimiter.cjs.map +1 -1
- package/dist/async-rate-limiter/injectAsyncRateLimiter.d.cts +0 -1
- package/dist/async-rate-limiter/injectAsyncRateLimiter.d.ts +0 -1
- package/dist/async-rate-limiter/injectAsyncRateLimiter.js.map +1 -1
- package/dist/async-retryer/index.cjs +0 -1
- package/dist/async-throttler/injectAsyncThrottledCallback.cjs.map +1 -1
- package/dist/async-throttler/injectAsyncThrottledCallback.d.cts +0 -1
- package/dist/async-throttler/injectAsyncThrottledCallback.d.ts +0 -1
- package/dist/async-throttler/injectAsyncThrottledCallback.js.map +1 -1
- package/dist/async-throttler/injectAsyncThrottler.cjs.map +1 -1
- package/dist/async-throttler/injectAsyncThrottler.d.cts +0 -1
- package/dist/async-throttler/injectAsyncThrottler.d.ts +0 -1
- package/dist/async-throttler/injectAsyncThrottler.js.map +1 -1
- package/dist/batcher/injectBatchedCallback.cjs.map +1 -1
- package/dist/batcher/injectBatchedCallback.d.cts +0 -1
- package/dist/batcher/injectBatchedCallback.d.ts +0 -1
- package/dist/batcher/injectBatchedCallback.js.map +1 -1
- package/dist/batcher/injectBatcher.cjs.map +1 -1
- package/dist/batcher/injectBatcher.d.cts +0 -1
- package/dist/batcher/injectBatcher.d.ts +0 -1
- package/dist/batcher/injectBatcher.js.map +1 -1
- package/dist/debouncer/injectDebouncedCallback.cjs.map +1 -1
- package/dist/debouncer/injectDebouncedCallback.d.cts +0 -1
- package/dist/debouncer/injectDebouncedCallback.d.ts +0 -1
- package/dist/debouncer/injectDebouncedCallback.js.map +1 -1
- package/dist/debouncer/injectDebouncedSignal.cjs.map +1 -1
- package/dist/debouncer/injectDebouncedSignal.d.cts +0 -1
- package/dist/debouncer/injectDebouncedSignal.d.ts +0 -1
- package/dist/debouncer/injectDebouncedSignal.js.map +1 -1
- package/dist/debouncer/injectDebouncedValue.cjs.map +1 -1
- package/dist/debouncer/injectDebouncedValue.d.cts +0 -1
- package/dist/debouncer/injectDebouncedValue.d.ts +0 -1
- package/dist/debouncer/injectDebouncedValue.js.map +1 -1
- package/dist/debouncer/injectDebouncer.cjs.map +1 -1
- package/dist/debouncer/injectDebouncer.d.cts +0 -1
- package/dist/debouncer/injectDebouncer.d.ts +0 -1
- package/dist/debouncer/injectDebouncer.js.map +1 -1
- package/dist/provider/pacer-context.cjs.map +1 -1
- package/dist/provider/pacer-context.d.cts +0 -1
- package/dist/provider/pacer-context.d.ts +0 -1
- package/dist/provider/pacer-context.js.map +1 -1
- package/dist/provider/pacer-provider.cjs.map +1 -1
- package/dist/provider/pacer-provider.d.cts +0 -1
- package/dist/provider/pacer-provider.d.ts +0 -1
- package/dist/provider/pacer-provider.js.map +1 -1
- package/dist/queuer/injectQueuedSignal.cjs.map +1 -1
- package/dist/queuer/injectQueuedSignal.d.cts +0 -1
- package/dist/queuer/injectQueuedSignal.d.ts +0 -1
- package/dist/queuer/injectQueuedSignal.js.map +1 -1
- package/dist/queuer/injectQueuedValue.cjs.map +1 -1
- package/dist/queuer/injectQueuedValue.d.cts +0 -1
- package/dist/queuer/injectQueuedValue.d.ts +0 -1
- package/dist/queuer/injectQueuedValue.js.map +1 -1
- package/dist/queuer/injectQueuer.cjs.map +1 -1
- package/dist/queuer/injectQueuer.d.cts +0 -1
- package/dist/queuer/injectQueuer.d.ts +0 -1
- package/dist/queuer/injectQueuer.js.map +1 -1
- package/dist/rate-limiter/injectRateLimitedCallback.cjs.map +1 -1
- package/dist/rate-limiter/injectRateLimitedCallback.d.cts +0 -1
- package/dist/rate-limiter/injectRateLimitedCallback.d.ts +0 -1
- package/dist/rate-limiter/injectRateLimitedCallback.js.map +1 -1
- package/dist/rate-limiter/injectRateLimitedSignal.cjs.map +1 -1
- package/dist/rate-limiter/injectRateLimitedSignal.d.cts +0 -1
- package/dist/rate-limiter/injectRateLimitedSignal.d.ts +0 -1
- package/dist/rate-limiter/injectRateLimitedSignal.js.map +1 -1
- package/dist/rate-limiter/injectRateLimitedValue.cjs.map +1 -1
- package/dist/rate-limiter/injectRateLimitedValue.d.cts +0 -1
- package/dist/rate-limiter/injectRateLimitedValue.d.ts +0 -1
- package/dist/rate-limiter/injectRateLimitedValue.js.map +1 -1
- package/dist/rate-limiter/injectRateLimiter.cjs.map +1 -1
- package/dist/rate-limiter/injectRateLimiter.d.cts +0 -1
- package/dist/rate-limiter/injectRateLimiter.d.ts +0 -1
- package/dist/rate-limiter/injectRateLimiter.js.map +1 -1
- package/dist/throttler/injectThrottledCallback.cjs.map +1 -1
- package/dist/throttler/injectThrottledCallback.d.cts +0 -1
- package/dist/throttler/injectThrottledCallback.d.ts +0 -1
- package/dist/throttler/injectThrottledCallback.js.map +1 -1
- package/dist/throttler/injectThrottledSignal.cjs.map +1 -1
- package/dist/throttler/injectThrottledSignal.d.cts +0 -1
- package/dist/throttler/injectThrottledSignal.d.ts +0 -1
- package/dist/throttler/injectThrottledSignal.js.map +1 -1
- package/dist/throttler/injectThrottledValue.cjs.map +1 -1
- package/dist/throttler/injectThrottledValue.d.cts +0 -1
- package/dist/throttler/injectThrottledValue.d.ts +0 -1
- package/dist/throttler/injectThrottledValue.js.map +1 -1
- package/dist/throttler/injectThrottler.cjs.map +1 -1
- package/dist/throttler/injectThrottler.d.cts +0 -1
- package/dist/throttler/injectThrottler.d.ts +0 -1
- package/dist/throttler/injectThrottler.js.map +1 -1
- package/dist/types/index.cjs +0 -1
- package/dist/utils/index.cjs +0 -1
- package/package.json +5 -5
- package/src/debouncer/injectDebouncedValue.ts +1 -2
- package/src/queuer/injectQueuedValue.ts +2 -4
- package/src/rate-limiter/injectRateLimitedValue.ts +1 -2
- package/src/throttler/injectThrottledValue.ts +1 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectQueuedSignal.cjs","names":["injectQueuer"],"sources":["../../src/queuer/injectQueuedSignal.ts"],"sourcesContent":["import { computed } from '@angular/core'\nimport { injectQueuer } from './injectQueuer'\nimport type { AngularQueuer } from './injectQueuer'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport interface QueuedSignal<TValue, TSelected = {}> {\n (): Array<TValue>\n addItem: AngularQueuer<TValue, TSelected>['addItem']\n queuer: AngularQueuer<TValue, TSelected>\n}\n\n/**\n * An Angular function that creates a queuer with managed state, combining Angular's signals with queuing functionality.\n * This function provides both the current queue state and queue control methods.\n *\n * The queue state is automatically updated whenever items are added, removed, or reordered in the queue.\n * All queue operations are reflected in the state array returned by the function.\n *\n * The function returns a callable object:\n * - `queued()`: Get the current queue items as an array\n * - `queued.addItem(...)`: Add an item to the queue\n * - `queued.queue`: The queuer instance with additional control methods\n *\n * @example\n * ```ts\n * // Default behavior - track items\n * const queued = injectQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 }\n * );\n *\n * // Add items\n * queued.addItem('task1');\n *\n * // Access items\n * console.log(queued()); // ['task1']\n *\n * // Control the queue\n * queued.queuer.start();\n * queued.queuer.stop();\n * ```\n */\nexport function injectQueuedSignal<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n fn: (item: TValue) => void,\n options: QueuerOptions<TValue> = {},\n selector: (state: QueuerState<TValue>) => TSelected = (state) =>\n ({ items: state.items }) as TSelected,\n): QueuedSignal<TValue, TSelected> {\n const queuer = injectQueuer(fn, options, selector)\n\n const items = computed(() => queuer.state().items as Array<TValue>)\n\n const queued = Object.assign(items, {\n addItem: queuer.addItem.bind(queuer),\n queuer,\n }) as QueuedSignal<TValue, TSelected>\n\n return queued\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAgB,mBAOd,IACA,UAAiC,
|
|
1
|
+
{"version":3,"file":"injectQueuedSignal.cjs","names":["injectQueuer","computed"],"sources":["../../src/queuer/injectQueuedSignal.ts"],"sourcesContent":["import { computed } from '@angular/core'\nimport { injectQueuer } from './injectQueuer'\nimport type { AngularQueuer } from './injectQueuer'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport interface QueuedSignal<TValue, TSelected = {}> {\n (): Array<TValue>\n addItem: AngularQueuer<TValue, TSelected>['addItem']\n queuer: AngularQueuer<TValue, TSelected>\n}\n\n/**\n * An Angular function that creates a queuer with managed state, combining Angular's signals with queuing functionality.\n * This function provides both the current queue state and queue control methods.\n *\n * The queue state is automatically updated whenever items are added, removed, or reordered in the queue.\n * All queue operations are reflected in the state array returned by the function.\n *\n * The function returns a callable object:\n * - `queued()`: Get the current queue items as an array\n * - `queued.addItem(...)`: Add an item to the queue\n * - `queued.queue`: The queuer instance with additional control methods\n *\n * @example\n * ```ts\n * // Default behavior - track items\n * const queued = injectQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 }\n * );\n *\n * // Add items\n * queued.addItem('task1');\n *\n * // Access items\n * console.log(queued()); // ['task1']\n *\n * // Control the queue\n * queued.queuer.start();\n * queued.queuer.stop();\n * ```\n */\nexport function injectQueuedSignal<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n fn: (item: TValue) => void,\n options: QueuerOptions<TValue> = {},\n selector: (state: QueuerState<TValue>) => TSelected = (state) =>\n ({ items: state.items }) as TSelected,\n): QueuedSignal<TValue, TSelected> {\n const queuer = injectQueuer(fn, options, selector)\n\n const items = computed(() => queuer.state().items as Array<TValue>)\n\n const queued = Object.assign(items, {\n addItem: queuer.addItem.bind(queuer),\n queuer,\n }) as QueuedSignal<TValue, TSelected>\n\n return queued\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAgB,mBAOd,IACA,UAAiC,CAAC,GAClC,YAAuD,WACpD,EAAE,OAAO,MAAM,MAAM,IACS;CACjC,MAAM,SAASA,kCAAa,IAAI,SAAS,QAAQ;CAEjD,MAAM,YAAQC,8BAAe,OAAO,MAAM,CAAC,CAAC,KAAsB;CAOlE,OALe,OAAO,OAAO,OAAO;EAClC,SAAS,OAAO,QAAQ,KAAK,MAAM;EACnC;CACF,CAEY;AACd"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectQueuedSignal.js","names":[],"sources":["../../src/queuer/injectQueuedSignal.ts"],"sourcesContent":["import { computed } from '@angular/core'\nimport { injectQueuer } from './injectQueuer'\nimport type { AngularQueuer } from './injectQueuer'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport interface QueuedSignal<TValue, TSelected = {}> {\n (): Array<TValue>\n addItem: AngularQueuer<TValue, TSelected>['addItem']\n queuer: AngularQueuer<TValue, TSelected>\n}\n\n/**\n * An Angular function that creates a queuer with managed state, combining Angular's signals with queuing functionality.\n * This function provides both the current queue state and queue control methods.\n *\n * The queue state is automatically updated whenever items are added, removed, or reordered in the queue.\n * All queue operations are reflected in the state array returned by the function.\n *\n * The function returns a callable object:\n * - `queued()`: Get the current queue items as an array\n * - `queued.addItem(...)`: Add an item to the queue\n * - `queued.queue`: The queuer instance with additional control methods\n *\n * @example\n * ```ts\n * // Default behavior - track items\n * const queued = injectQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 }\n * );\n *\n * // Add items\n * queued.addItem('task1');\n *\n * // Access items\n * console.log(queued()); // ['task1']\n *\n * // Control the queue\n * queued.queuer.start();\n * queued.queuer.stop();\n * ```\n */\nexport function injectQueuedSignal<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n fn: (item: TValue) => void,\n options: QueuerOptions<TValue> = {},\n selector: (state: QueuerState<TValue>) => TSelected = (state) =>\n ({ items: state.items }) as TSelected,\n): QueuedSignal<TValue, TSelected> {\n const queuer = injectQueuer(fn, options, selector)\n\n const items = computed(() => queuer.state().items as Array<TValue>)\n\n const queued = Object.assign(items, {\n addItem: queuer.addItem.bind(queuer),\n queuer,\n }) as QueuedSignal<TValue, TSelected>\n\n return queued\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAgB,mBAOd,IACA,UAAiC,
|
|
1
|
+
{"version":3,"file":"injectQueuedSignal.js","names":[],"sources":["../../src/queuer/injectQueuedSignal.ts"],"sourcesContent":["import { computed } from '@angular/core'\nimport { injectQueuer } from './injectQueuer'\nimport type { AngularQueuer } from './injectQueuer'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport interface QueuedSignal<TValue, TSelected = {}> {\n (): Array<TValue>\n addItem: AngularQueuer<TValue, TSelected>['addItem']\n queuer: AngularQueuer<TValue, TSelected>\n}\n\n/**\n * An Angular function that creates a queuer with managed state, combining Angular's signals with queuing functionality.\n * This function provides both the current queue state and queue control methods.\n *\n * The queue state is automatically updated whenever items are added, removed, or reordered in the queue.\n * All queue operations are reflected in the state array returned by the function.\n *\n * The function returns a callable object:\n * - `queued()`: Get the current queue items as an array\n * - `queued.addItem(...)`: Add an item to the queue\n * - `queued.queue`: The queuer instance with additional control methods\n *\n * @example\n * ```ts\n * // Default behavior - track items\n * const queued = injectQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 }\n * );\n *\n * // Add items\n * queued.addItem('task1');\n *\n * // Access items\n * console.log(queued()); // ['task1']\n *\n * // Control the queue\n * queued.queuer.start();\n * queued.queuer.stop();\n * ```\n */\nexport function injectQueuedSignal<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n fn: (item: TValue) => void,\n options: QueuerOptions<TValue> = {},\n selector: (state: QueuerState<TValue>) => TSelected = (state) =>\n ({ items: state.items }) as TSelected,\n): QueuedSignal<TValue, TSelected> {\n const queuer = injectQueuer(fn, options, selector)\n\n const items = computed(() => queuer.state().items as Array<TValue>)\n\n const queued = Object.assign(items, {\n addItem: queuer.addItem.bind(queuer),\n queuer,\n }) as QueuedSignal<TValue, TSelected>\n\n return queued\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAgB,mBAOd,IACA,UAAiC,CAAC,GAClC,YAAuD,WACpD,EAAE,OAAO,MAAM,MAAM,IACS;CACjC,MAAM,SAAS,aAAa,IAAI,SAAS,QAAQ;CAEjD,MAAM,QAAQ,eAAe,OAAO,MAAM,CAAC,CAAC,KAAsB;CAOlE,OALe,OAAO,OAAO,OAAO;EAClC,SAAS,OAAO,QAAQ,KAAK,MAAM;EACnC;CACF,CAEY;AACd"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectQueuedValue.cjs","names":["injectQueuedSignal"],"sources":["../../src/queuer/injectQueuedValue.ts"],"sourcesContent":["import { effect, linkedSignal, signal } from '@angular/core'\nimport { injectQueuedSignal } from './injectQueuedSignal'\nimport type { QueuedSignal } from './injectQueuedSignal'\nimport type { Signal } from '@angular/core'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\n/**\n * An Angular function that creates a queued value that processes state changes in order with an optional delay.\n * This function uses injectQueuedSignal internally to manage a queue of state changes and apply them sequentially.\n *\n * The queued value will process changes in the order they are received, with optional delays between\n * processing each change. This is useful for handling state updates that need to be processed\n * in a specific order, like animations or sequential UI updates.\n *\n * The function returns a tuple containing:\n * - A Signal that provides the current queued value\n * - The queuer instance with control methods\n *\n * @example\n * ```ts\n * const initialValue = signal('initial')\n * const queued = injectQueuedValue(initialValue, {\n * wait: 500,\n * started: true,\n * })\n *\n * // Add changes to the queue\n * queued.addItem('new value')\n * ```\n */\nexport function injectQueuedValue<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n value: Signal<TValue>,\n options?: QueuerOptions<TValue>,\n selector?: (state: QueuerState<TValue>) => TSelected,\n): QueuedSignal<TValue, TSelected>\nexport function injectQueuedValue<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n value: Signal<TValue>,\n initialValue: TValue,\n options?: QueuerOptions<TValue>,\n selector?: (state: QueuerState<TValue>) => TSelected,\n): QueuedSignal<TValue, TSelected>\nexport function injectQueuedValue<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n value: Signal<TValue>,\n initialValueOrOptions?: TValue | QueuerOptions<TValue>,\n initialOptionsOrSelector?:\n
|
|
1
|
+
{"version":3,"file":"injectQueuedValue.cjs","names":["linkedSignal","signal","injectQueuedSignal"],"sources":["../../src/queuer/injectQueuedValue.ts"],"sourcesContent":["import { effect, linkedSignal, signal } from '@angular/core'\nimport { injectQueuedSignal } from './injectQueuedSignal'\nimport type { QueuedSignal } from './injectQueuedSignal'\nimport type { Signal } from '@angular/core'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\n/**\n * An Angular function that creates a queued value that processes state changes in order with an optional delay.\n * This function uses injectQueuedSignal internally to manage a queue of state changes and apply them sequentially.\n *\n * The queued value will process changes in the order they are received, with optional delays between\n * processing each change. This is useful for handling state updates that need to be processed\n * in a specific order, like animations or sequential UI updates.\n *\n * The function returns a tuple containing:\n * - A Signal that provides the current queued value\n * - The queuer instance with control methods\n *\n * @example\n * ```ts\n * const initialValue = signal('initial')\n * const queued = injectQueuedValue(initialValue, {\n * wait: 500,\n * started: true,\n * })\n *\n * // Add changes to the queue\n * queued.addItem('new value')\n * ```\n */\nexport function injectQueuedValue<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n value: Signal<TValue>,\n options?: QueuerOptions<TValue>,\n selector?: (state: QueuerState<TValue>) => TSelected,\n): QueuedSignal<TValue, TSelected>\nexport function injectQueuedValue<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n value: Signal<TValue>,\n initialValue: TValue,\n options?: QueuerOptions<TValue>,\n selector?: (state: QueuerState<TValue>) => TSelected,\n): QueuedSignal<TValue, TSelected>\nexport function injectQueuedValue<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n value: Signal<TValue>,\n initialValueOrOptions?: TValue | QueuerOptions<TValue>,\n initialOptionsOrSelector?:\n QueuerOptions<TValue> | ((state: QueuerState<TValue>) => TSelected),\n maybeSelector?: (state: QueuerState<TValue>) => TSelected,\n): QueuedSignal<TValue, TSelected> {\n const hasSelector = typeof initialOptionsOrSelector === 'function'\n const hasInitialValue =\n (initialOptionsOrSelector !== undefined && !hasSelector) ||\n maybeSelector !== undefined\n\n const initialValue = hasInitialValue\n ? (initialValueOrOptions as TValue)\n : value()\n const initialOptions = hasInitialValue\n ? (initialOptionsOrSelector as QueuerOptions<TValue>)\n : (initialValueOrOptions as QueuerOptions<TValue>)\n const selector = hasInitialValue\n ? maybeSelector\n : (initialOptionsOrSelector as\n ((state: QueuerState<TValue>) => TSelected) | undefined)\n\n const linkedValue = linkedSignal(() => value())\n const queuedValue = signal<TValue>(initialValue)\n\n const queued = injectQueuedSignal(\n (item) => {\n queuedValue.set(item)\n },\n initialOptions,\n selector,\n )\n\n effect(() => {\n queued.addItem(linkedValue())\n })\n\n return queued\n}\n"],"mappings":";;;;AAqDA,SAAgB,kBAOd,OACA,uBACA,0BAEA,eACiC;CAEjC,MAAM,kBACH,6BAA6B,UAAa,EAFzB,OAAO,6BAA6B,eAGtD,kBAAkB;CAEpB,MAAM,eAAe,kBAChB,wBACD,MAAM;CACV,MAAM,iBAAiB,kBAClB,2BACA;CACL,MAAM,WAAW,kBACb,gBACC;CAGL,MAAM,kBAAcA,kCAAmB,MAAM,CAAC;CAC9C,MAAM,kBAAcC,sBAAe,YAAY;CAE/C,MAAM,SAASC,+CACZ,SAAS;EACR,YAAY,IAAI,IAAI;CACtB,GACA,gBACA,QACF;CAEA,gCAAa;EACX,OAAO,QAAQ,YAAY,CAAC;CAC9B,CAAC;CAED,OAAO;AACT"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { QueuedSignal } from "./injectQueuedSignal.cjs";
|
|
2
2
|
import { Signal } from "@angular/core";
|
|
3
3
|
import { QueuerOptions, QueuerState } from "@tanstack/pacer/queuer";
|
|
4
|
-
|
|
5
4
|
//#region src/queuer/injectQueuedValue.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* An Angular function that creates a queued value that processes state changes in order with an optional delay.
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { QueuedSignal } from "./injectQueuedSignal.js";
|
|
2
2
|
import { Signal } from "@angular/core";
|
|
3
3
|
import { QueuerOptions, QueuerState } from "@tanstack/pacer/queuer";
|
|
4
|
-
|
|
5
4
|
//#region src/queuer/injectQueuedValue.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* An Angular function that creates a queued value that processes state changes in order with an optional delay.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectQueuedValue.js","names":[],"sources":["../../src/queuer/injectQueuedValue.ts"],"sourcesContent":["import { effect, linkedSignal, signal } from '@angular/core'\nimport { injectQueuedSignal } from './injectQueuedSignal'\nimport type { QueuedSignal } from './injectQueuedSignal'\nimport type { Signal } from '@angular/core'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\n/**\n * An Angular function that creates a queued value that processes state changes in order with an optional delay.\n * This function uses injectQueuedSignal internally to manage a queue of state changes and apply them sequentially.\n *\n * The queued value will process changes in the order they are received, with optional delays between\n * processing each change. This is useful for handling state updates that need to be processed\n * in a specific order, like animations or sequential UI updates.\n *\n * The function returns a tuple containing:\n * - A Signal that provides the current queued value\n * - The queuer instance with control methods\n *\n * @example\n * ```ts\n * const initialValue = signal('initial')\n * const queued = injectQueuedValue(initialValue, {\n * wait: 500,\n * started: true,\n * })\n *\n * // Add changes to the queue\n * queued.addItem('new value')\n * ```\n */\nexport function injectQueuedValue<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n value: Signal<TValue>,\n options?: QueuerOptions<TValue>,\n selector?: (state: QueuerState<TValue>) => TSelected,\n): QueuedSignal<TValue, TSelected>\nexport function injectQueuedValue<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n value: Signal<TValue>,\n initialValue: TValue,\n options?: QueuerOptions<TValue>,\n selector?: (state: QueuerState<TValue>) => TSelected,\n): QueuedSignal<TValue, TSelected>\nexport function injectQueuedValue<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n value: Signal<TValue>,\n initialValueOrOptions?: TValue | QueuerOptions<TValue>,\n initialOptionsOrSelector?:\n
|
|
1
|
+
{"version":3,"file":"injectQueuedValue.js","names":[],"sources":["../../src/queuer/injectQueuedValue.ts"],"sourcesContent":["import { effect, linkedSignal, signal } from '@angular/core'\nimport { injectQueuedSignal } from './injectQueuedSignal'\nimport type { QueuedSignal } from './injectQueuedSignal'\nimport type { Signal } from '@angular/core'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\n/**\n * An Angular function that creates a queued value that processes state changes in order with an optional delay.\n * This function uses injectQueuedSignal internally to manage a queue of state changes and apply them sequentially.\n *\n * The queued value will process changes in the order they are received, with optional delays between\n * processing each change. This is useful for handling state updates that need to be processed\n * in a specific order, like animations or sequential UI updates.\n *\n * The function returns a tuple containing:\n * - A Signal that provides the current queued value\n * - The queuer instance with control methods\n *\n * @example\n * ```ts\n * const initialValue = signal('initial')\n * const queued = injectQueuedValue(initialValue, {\n * wait: 500,\n * started: true,\n * })\n *\n * // Add changes to the queue\n * queued.addItem('new value')\n * ```\n */\nexport function injectQueuedValue<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n value: Signal<TValue>,\n options?: QueuerOptions<TValue>,\n selector?: (state: QueuerState<TValue>) => TSelected,\n): QueuedSignal<TValue, TSelected>\nexport function injectQueuedValue<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n value: Signal<TValue>,\n initialValue: TValue,\n options?: QueuerOptions<TValue>,\n selector?: (state: QueuerState<TValue>) => TSelected,\n): QueuedSignal<TValue, TSelected>\nexport function injectQueuedValue<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n value: Signal<TValue>,\n initialValueOrOptions?: TValue | QueuerOptions<TValue>,\n initialOptionsOrSelector?:\n QueuerOptions<TValue> | ((state: QueuerState<TValue>) => TSelected),\n maybeSelector?: (state: QueuerState<TValue>) => TSelected,\n): QueuedSignal<TValue, TSelected> {\n const hasSelector = typeof initialOptionsOrSelector === 'function'\n const hasInitialValue =\n (initialOptionsOrSelector !== undefined && !hasSelector) ||\n maybeSelector !== undefined\n\n const initialValue = hasInitialValue\n ? (initialValueOrOptions as TValue)\n : value()\n const initialOptions = hasInitialValue\n ? (initialOptionsOrSelector as QueuerOptions<TValue>)\n : (initialValueOrOptions as QueuerOptions<TValue>)\n const selector = hasInitialValue\n ? maybeSelector\n : (initialOptionsOrSelector as\n ((state: QueuerState<TValue>) => TSelected) | undefined)\n\n const linkedValue = linkedSignal(() => value())\n const queuedValue = signal<TValue>(initialValue)\n\n const queued = injectQueuedSignal(\n (item) => {\n queuedValue.set(item)\n },\n initialOptions,\n selector,\n )\n\n effect(() => {\n queued.addItem(linkedValue())\n })\n\n return queued\n}\n"],"mappings":";;;;AAqDA,SAAgB,kBAOd,OACA,uBACA,0BAEA,eACiC;CAEjC,MAAM,kBACH,6BAA6B,UAAa,EAFzB,OAAO,6BAA6B,eAGtD,kBAAkB;CAEpB,MAAM,eAAe,kBAChB,wBACD,MAAM;CACV,MAAM,iBAAiB,kBAClB,2BACA;CACL,MAAM,WAAW,kBACb,gBACC;CAGL,MAAM,cAAc,mBAAmB,MAAM,CAAC;CAC9C,MAAM,cAAc,OAAe,YAAY;CAE/C,MAAM,SAAS,oBACZ,SAAS;EACR,YAAY,IAAI,IAAI;CACtB,GACA,gBACA,QACF;CAEA,aAAa;EACX,OAAO,QAAQ,YAAY,CAAC;CAC9B,CAAC;CAED,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectQueuer.cjs","names":["injectPacerOptions","Queuer","DestroyRef"],"sources":["../../src/queuer/injectQueuer.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } from '@tanstack/angular-store'\nimport { Queuer } from '@tanstack/pacer/queuer'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport interface AngularQueuerOptions<\n TValue,\n TSelected = {},\n> extends QueuerOptions<TValue> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the queuer instance.\n * When provided, replaces the default cleanup (stop); use it to call flush(), stop(), add logging, etc.\n */\n onUnmount?: (queuer: AngularQueuer<TValue, TSelected>) => void\n}\n\nexport interface AngularQueuer<TValue, TSelected = {}> extends Omit<\n Queuer<TValue>,\n 'store'\n> {\n /**\n * Reactive state signal that will be updated when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<QueuerState<TValue>>>\n}\n\n/**\n * An Angular function that creates and manages a Queuer instance.\n *\n * This is a lower-level function that provides direct access to the Queuer's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * The Queuer processes items synchronously in order, with optional delays between processing each item.\n * The queuer includes an internal tick mechanism that can be started and stopped, making it useful as a scheduler.\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates 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 updates and gives you\n * full control over when your component tracks state changes.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const queue = injectQueuer(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 }\n * );\n *\n * // Opt-in to track queue contents changes\n * const queue = injectQueuer(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({ items: state.items, size: state.size })\n * );\n *\n * // Add items\n * queue.addItem('task1');\n *\n * // Access the selected state\n * const { items, isRunning } = queue.state();\n * ```\n *\n * ## Cleanup on Destroy\n *\n * By default, the function stops the queuer when the component is destroyed.\n * Use the `onUnmount` option to customize this. For example, to flush pending items instead:\n *\n * ```ts\n * const queue = injectQueuer(fn, {\n * started: true,\n * onUnmount: (q) => q.flush()\n * });\n * ```\n */\nexport function injectQueuer<TValue, TSelected = {}>(\n fn: (item: TValue) => void,\n options: AngularQueuerOptions<TValue, TSelected> = {},\n selector: (state: QueuerState<TValue>) => TSelected = () => ({}) as TSelected,\n): AngularQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().queuer,\n ...options,\n } as AngularQueuerOptions<TValue, TSelected>\n\n const queuer = new Queuer<TValue>(fn, mergedOptions)\n const state = injectSelector(queuer.store, selector)\n\n const result = {\n ...queuer,\n state,\n } as AngularQueuer<TValue, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n queuer.stop()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,SAAgB,aACd,IACA,UAAmD,
|
|
1
|
+
{"version":3,"file":"injectQueuer.cjs","names":["injectPacerOptions","Queuer","injectSelector","inject","DestroyRef"],"sources":["../../src/queuer/injectQueuer.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } from '@tanstack/angular-store'\nimport { Queuer } from '@tanstack/pacer/queuer'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport interface AngularQueuerOptions<\n TValue,\n TSelected = {},\n> extends QueuerOptions<TValue> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the queuer instance.\n * When provided, replaces the default cleanup (stop); use it to call flush(), stop(), add logging, etc.\n */\n onUnmount?: (queuer: AngularQueuer<TValue, TSelected>) => void\n}\n\nexport interface AngularQueuer<TValue, TSelected = {}> extends Omit<\n Queuer<TValue>,\n 'store'\n> {\n /**\n * Reactive state signal that will be updated when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<QueuerState<TValue>>>\n}\n\n/**\n * An Angular function that creates and manages a Queuer instance.\n *\n * This is a lower-level function that provides direct access to the Queuer's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * The Queuer processes items synchronously in order, with optional delays between processing each item.\n * The queuer includes an internal tick mechanism that can be started and stopped, making it useful as a scheduler.\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates 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 updates and gives you\n * full control over when your component tracks state changes.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const queue = injectQueuer(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 }\n * );\n *\n * // Opt-in to track queue contents changes\n * const queue = injectQueuer(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({ items: state.items, size: state.size })\n * );\n *\n * // Add items\n * queue.addItem('task1');\n *\n * // Access the selected state\n * const { items, isRunning } = queue.state();\n * ```\n *\n * ## Cleanup on Destroy\n *\n * By default, the function stops the queuer when the component is destroyed.\n * Use the `onUnmount` option to customize this. For example, to flush pending items instead:\n *\n * ```ts\n * const queue = injectQueuer(fn, {\n * started: true,\n * onUnmount: (q) => q.flush()\n * });\n * ```\n */\nexport function injectQueuer<TValue, TSelected = {}>(\n fn: (item: TValue) => void,\n options: AngularQueuerOptions<TValue, TSelected> = {},\n selector: (state: QueuerState<TValue>) => TSelected = () => ({}) as TSelected,\n): AngularQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().queuer,\n ...options,\n } as AngularQueuerOptions<TValue, TSelected>\n\n const queuer = new Queuer<TValue>(fn, mergedOptions)\n const state = injectSelector(queuer.store, selector)\n\n const result = {\n ...queuer,\n state,\n } as AngularQueuer<TValue, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n queuer.stop()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,SAAgB,aACd,IACA,UAAmD,CAAC,GACpD,kBAA6D,CAAC,IAC5B;CAClC,MAAM,gBAAgB;EACpB,GAAGA,yCAAmB,CAAC,CAAC;EACxB,GAAG;CACL;CAEA,MAAM,SAAS,IAAIC,8BAAe,IAAI,aAAa;CACnD,MAAM,YAAQC,wCAAe,OAAO,OAAO,QAAQ;CAEnD,MAAM,SAAS;EACb,GAAG;EACH;CACF;CAGA,IADmBC,sBAAOC,0BAAY,EAAE,UAAU,KAAK,CAC9C,CAAC,EAAE,gBAAgB;EAC1B,IAAI,cAAc,WAChB,cAAc,UAAU,MAAM;OAE9B,OAAO,KAAK;CAEhB,CAAC;CAED,OAAO;AACT"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Signal } from "@angular/core";
|
|
2
2
|
import { Store } from "@tanstack/angular-store";
|
|
3
3
|
import { Queuer, QueuerOptions, QueuerState } from "@tanstack/pacer/queuer";
|
|
4
|
-
|
|
5
4
|
//#region src/queuer/injectQueuer.d.ts
|
|
6
5
|
interface AngularQueuerOptions<TValue, TSelected = {}> extends QueuerOptions<TValue> {
|
|
7
6
|
/**
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Signal } from "@angular/core";
|
|
2
2
|
import { Store } from "@tanstack/angular-store";
|
|
3
3
|
import { Queuer, QueuerOptions, QueuerState } from "@tanstack/pacer/queuer";
|
|
4
|
-
|
|
5
4
|
//#region src/queuer/injectQueuer.d.ts
|
|
6
5
|
interface AngularQueuerOptions<TValue, TSelected = {}> extends QueuerOptions<TValue> {
|
|
7
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectQueuer.js","names":[],"sources":["../../src/queuer/injectQueuer.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } from '@tanstack/angular-store'\nimport { Queuer } from '@tanstack/pacer/queuer'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport interface AngularQueuerOptions<\n TValue,\n TSelected = {},\n> extends QueuerOptions<TValue> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the queuer instance.\n * When provided, replaces the default cleanup (stop); use it to call flush(), stop(), add logging, etc.\n */\n onUnmount?: (queuer: AngularQueuer<TValue, TSelected>) => void\n}\n\nexport interface AngularQueuer<TValue, TSelected = {}> extends Omit<\n Queuer<TValue>,\n 'store'\n> {\n /**\n * Reactive state signal that will be updated when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<QueuerState<TValue>>>\n}\n\n/**\n * An Angular function that creates and manages a Queuer instance.\n *\n * This is a lower-level function that provides direct access to the Queuer's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * The Queuer processes items synchronously in order, with optional delays between processing each item.\n * The queuer includes an internal tick mechanism that can be started and stopped, making it useful as a scheduler.\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates 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 updates and gives you\n * full control over when your component tracks state changes.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const queue = injectQueuer(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 }\n * );\n *\n * // Opt-in to track queue contents changes\n * const queue = injectQueuer(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({ items: state.items, size: state.size })\n * );\n *\n * // Add items\n * queue.addItem('task1');\n *\n * // Access the selected state\n * const { items, isRunning } = queue.state();\n * ```\n *\n * ## Cleanup on Destroy\n *\n * By default, the function stops the queuer when the component is destroyed.\n * Use the `onUnmount` option to customize this. For example, to flush pending items instead:\n *\n * ```ts\n * const queue = injectQueuer(fn, {\n * started: true,\n * onUnmount: (q) => q.flush()\n * });\n * ```\n */\nexport function injectQueuer<TValue, TSelected = {}>(\n fn: (item: TValue) => void,\n options: AngularQueuerOptions<TValue, TSelected> = {},\n selector: (state: QueuerState<TValue>) => TSelected = () => ({}) as TSelected,\n): AngularQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().queuer,\n ...options,\n } as AngularQueuerOptions<TValue, TSelected>\n\n const queuer = new Queuer<TValue>(fn, mergedOptions)\n const state = injectSelector(queuer.store, selector)\n\n const result = {\n ...queuer,\n state,\n } as AngularQueuer<TValue, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n queuer.stop()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,SAAgB,aACd,IACA,UAAmD,
|
|
1
|
+
{"version":3,"file":"injectQueuer.js","names":[],"sources":["../../src/queuer/injectQueuer.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } from '@tanstack/angular-store'\nimport { Queuer } from '@tanstack/pacer/queuer'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport interface AngularQueuerOptions<\n TValue,\n TSelected = {},\n> extends QueuerOptions<TValue> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the queuer instance.\n * When provided, replaces the default cleanup (stop); use it to call flush(), stop(), add logging, etc.\n */\n onUnmount?: (queuer: AngularQueuer<TValue, TSelected>) => void\n}\n\nexport interface AngularQueuer<TValue, TSelected = {}> extends Omit<\n Queuer<TValue>,\n 'store'\n> {\n /**\n * Reactive state signal that will be updated when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive in Angular signals.\n */\n readonly store: Store<Readonly<QueuerState<TValue>>>\n}\n\n/**\n * An Angular function that creates and manages a Queuer instance.\n *\n * This is a lower-level function that provides direct access to the Queuer's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * The Queuer processes items synchronously in order, with optional delays between processing each item.\n * The queuer includes an internal tick mechanism that can be started and stopped, making it useful as a scheduler.\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates 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 updates and gives you\n * full control over when your component tracks state changes.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const queue = injectQueuer(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 }\n * );\n *\n * // Opt-in to track queue contents changes\n * const queue = injectQueuer(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({ items: state.items, size: state.size })\n * );\n *\n * // Add items\n * queue.addItem('task1');\n *\n * // Access the selected state\n * const { items, isRunning } = queue.state();\n * ```\n *\n * ## Cleanup on Destroy\n *\n * By default, the function stops the queuer when the component is destroyed.\n * Use the `onUnmount` option to customize this. For example, to flush pending items instead:\n *\n * ```ts\n * const queue = injectQueuer(fn, {\n * started: true,\n * onUnmount: (q) => q.flush()\n * });\n * ```\n */\nexport function injectQueuer<TValue, TSelected = {}>(\n fn: (item: TValue) => void,\n options: AngularQueuerOptions<TValue, TSelected> = {},\n selector: (state: QueuerState<TValue>) => TSelected = () => ({}) as TSelected,\n): AngularQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().queuer,\n ...options,\n } as AngularQueuerOptions<TValue, TSelected>\n\n const queuer = new Queuer<TValue>(fn, mergedOptions)\n const state = injectSelector(queuer.store, selector)\n\n const result = {\n ...queuer,\n state,\n } as AngularQueuer<TValue, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n queuer.stop()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,SAAgB,aACd,IACA,UAAmD,CAAC,GACpD,kBAA6D,CAAC,IAC5B;CAClC,MAAM,gBAAgB;EACpB,GAAG,mBAAmB,CAAC,CAAC;EACxB,GAAG;CACL;CAEA,MAAM,SAAS,IAAI,OAAe,IAAI,aAAa;CACnD,MAAM,QAAQ,eAAe,OAAO,OAAO,QAAQ;CAEnD,MAAM,SAAS;EACb,GAAG;EACH;CACF;CAGA,AADmB,OAAO,YAAY,EAAE,UAAU,KAAK,CAC9C,CAAC,EAAE,gBAAgB;EAC1B,IAAI,cAAc,WAChB,cAAc,UAAU,MAAM;OAE9B,OAAO,KAAK;CAEhB,CAAC;CAED,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectRateLimitedCallback.cjs","names":["injectRateLimiter"],"sources":["../../src/rate-limiter/injectRateLimitedCallback.ts"],"sourcesContent":["import { injectRateLimiter } from './injectRateLimiter'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\nimport type { AnyFunction } from '@tanstack/pacer/types'\n\n/**\n * An Angular function that creates a rate-limited version of a callback function.\n * This function is essentially a wrapper around `injectRateLimiter` that provides\n * a simplified API for basic rate limiting needs.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all calls until the limit\n * is reached, then blocks subsequent calls until the window resets. Unlike throttling\n * or debouncing, it does not attempt to space out or intelligently collapse calls.\n *\n * This function provides a simpler API compared to `injectRateLimiter`, making it ideal for basic\n * rate limiting needs. However, it does not expose the underlying RateLimiter instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation/reset\n * - Access to execution counts\n * - State tracking\n *\n * Consider using the `injectRateLimiter` function instead.\n *\n * @example\n * ```ts\n * // Rate limit API calls to maximum 5 calls per minute\n * const makeApiCall = injectRateLimitedCallback(\n * (data: ApiData) => {\n * return fetch('/api/endpoint', { method: 'POST', body: JSON.stringify(data) });\n * },\n * {\n * limit: 5,\n * window: 60000, // 1 minute\n * windowType: 'sliding',\n * }\n * );\n * ```\n */\nexport function injectRateLimitedCallback<TFn extends AnyFunction>(\n fn: TFn,\n options: RateLimiterOptions<TFn>,\n): (...args: Parameters<TFn>) => boolean {\n const rateLimiter = injectRateLimiter(fn, options)\n return (...args: Parameters<TFn>) => rateLimiter.maybeExecute(...args)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,0BACd,IACA,SACuC;CACvC,MAAM,cAAcA,4CAAkB,IAAI,
|
|
1
|
+
{"version":3,"file":"injectRateLimitedCallback.cjs","names":["injectRateLimiter"],"sources":["../../src/rate-limiter/injectRateLimitedCallback.ts"],"sourcesContent":["import { injectRateLimiter } from './injectRateLimiter'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\nimport type { AnyFunction } from '@tanstack/pacer/types'\n\n/**\n * An Angular function that creates a rate-limited version of a callback function.\n * This function is essentially a wrapper around `injectRateLimiter` that provides\n * a simplified API for basic rate limiting needs.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all calls until the limit\n * is reached, then blocks subsequent calls until the window resets. Unlike throttling\n * or debouncing, it does not attempt to space out or intelligently collapse calls.\n *\n * This function provides a simpler API compared to `injectRateLimiter`, making it ideal for basic\n * rate limiting needs. However, it does not expose the underlying RateLimiter instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation/reset\n * - Access to execution counts\n * - State tracking\n *\n * Consider using the `injectRateLimiter` function instead.\n *\n * @example\n * ```ts\n * // Rate limit API calls to maximum 5 calls per minute\n * const makeApiCall = injectRateLimitedCallback(\n * (data: ApiData) => {\n * return fetch('/api/endpoint', { method: 'POST', body: JSON.stringify(data) });\n * },\n * {\n * limit: 5,\n * window: 60000, // 1 minute\n * windowType: 'sliding',\n * }\n * );\n * ```\n */\nexport function injectRateLimitedCallback<TFn extends AnyFunction>(\n fn: TFn,\n options: RateLimiterOptions<TFn>,\n): (...args: Parameters<TFn>) => boolean {\n const rateLimiter = injectRateLimiter(fn, options)\n return (...args: Parameters<TFn>) => rateLimiter.maybeExecute(...args)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,0BACd,IACA,SACuC;CACvC,MAAM,cAAcA,4CAAkB,IAAI,OAAO;CACjD,QAAQ,GAAG,SAA0B,YAAY,aAAa,GAAG,IAAI;AACvE"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AnyFunction } from "@tanstack/pacer/types";
|
|
2
2
|
import { RateLimiterOptions } from "@tanstack/pacer/rate-limiter";
|
|
3
|
-
|
|
4
3
|
//#region src/rate-limiter/injectRateLimitedCallback.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* An Angular function that creates a rate-limited version of a callback function.
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { RateLimiterOptions } from "@tanstack/pacer/rate-limiter";
|
|
2
2
|
import { AnyFunction } from "@tanstack/pacer/types";
|
|
3
|
-
|
|
4
3
|
//#region src/rate-limiter/injectRateLimitedCallback.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* An Angular function that creates a rate-limited version of a callback function.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectRateLimitedCallback.js","names":[],"sources":["../../src/rate-limiter/injectRateLimitedCallback.ts"],"sourcesContent":["import { injectRateLimiter } from './injectRateLimiter'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\nimport type { AnyFunction } from '@tanstack/pacer/types'\n\n/**\n * An Angular function that creates a rate-limited version of a callback function.\n * This function is essentially a wrapper around `injectRateLimiter` that provides\n * a simplified API for basic rate limiting needs.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all calls until the limit\n * is reached, then blocks subsequent calls until the window resets. Unlike throttling\n * or debouncing, it does not attempt to space out or intelligently collapse calls.\n *\n * This function provides a simpler API compared to `injectRateLimiter`, making it ideal for basic\n * rate limiting needs. However, it does not expose the underlying RateLimiter instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation/reset\n * - Access to execution counts\n * - State tracking\n *\n * Consider using the `injectRateLimiter` function instead.\n *\n * @example\n * ```ts\n * // Rate limit API calls to maximum 5 calls per minute\n * const makeApiCall = injectRateLimitedCallback(\n * (data: ApiData) => {\n * return fetch('/api/endpoint', { method: 'POST', body: JSON.stringify(data) });\n * },\n * {\n * limit: 5,\n * window: 60000, // 1 minute\n * windowType: 'sliding',\n * }\n * );\n * ```\n */\nexport function injectRateLimitedCallback<TFn extends AnyFunction>(\n fn: TFn,\n options: RateLimiterOptions<TFn>,\n): (...args: Parameters<TFn>) => boolean {\n const rateLimiter = injectRateLimiter(fn, options)\n return (...args: Parameters<TFn>) => rateLimiter.maybeExecute(...args)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,0BACd,IACA,SACuC;CACvC,MAAM,cAAc,kBAAkB,IAAI,
|
|
1
|
+
{"version":3,"file":"injectRateLimitedCallback.js","names":[],"sources":["../../src/rate-limiter/injectRateLimitedCallback.ts"],"sourcesContent":["import { injectRateLimiter } from './injectRateLimiter'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\nimport type { AnyFunction } from '@tanstack/pacer/types'\n\n/**\n * An Angular function that creates a rate-limited version of a callback function.\n * This function is essentially a wrapper around `injectRateLimiter` that provides\n * a simplified API for basic rate limiting needs.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all calls until the limit\n * is reached, then blocks subsequent calls until the window resets. Unlike throttling\n * or debouncing, it does not attempt to space out or intelligently collapse calls.\n *\n * This function provides a simpler API compared to `injectRateLimiter`, making it ideal for basic\n * rate limiting needs. However, it does not expose the underlying RateLimiter instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation/reset\n * - Access to execution counts\n * - State tracking\n *\n * Consider using the `injectRateLimiter` function instead.\n *\n * @example\n * ```ts\n * // Rate limit API calls to maximum 5 calls per minute\n * const makeApiCall = injectRateLimitedCallback(\n * (data: ApiData) => {\n * return fetch('/api/endpoint', { method: 'POST', body: JSON.stringify(data) });\n * },\n * {\n * limit: 5,\n * window: 60000, // 1 minute\n * windowType: 'sliding',\n * }\n * );\n * ```\n */\nexport function injectRateLimitedCallback<TFn extends AnyFunction>(\n fn: TFn,\n options: RateLimiterOptions<TFn>,\n): (...args: Parameters<TFn>) => boolean {\n const rateLimiter = injectRateLimiter(fn, options)\n return (...args: Parameters<TFn>) => rateLimiter.maybeExecute(...args)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,0BACd,IACA,SACuC;CACvC,MAAM,cAAc,kBAAkB,IAAI,OAAO;CACjD,QAAQ,GAAG,SAA0B,YAAY,aAAa,GAAG,IAAI;AACvE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectRateLimitedSignal.cjs","names":["injectRateLimiter"],"sources":["../../src/rate-limiter/injectRateLimitedSignal.ts"],"sourcesContent":["import { signal } from '@angular/core'\nimport { injectRateLimiter } from './injectRateLimiter'\nimport type { AngularRateLimiter } from './injectRateLimiter'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\nexport interface RateLimitedSignal<TValue, TSelected = {}> {\n (): TValue\n set: Setter<TValue>\n rateLimiter: AngularRateLimiter<Setter<TValue>, TSelected>\n}\n\n/**\n * An Angular function that creates a rate-limited state signal, combining Angular's signal with rate limiting functionality.\n * This function provides both the current rate-limited value and methods to update it.\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.\n *\n * The function returns a callable object:\n * - `rateLimited()`: Get the current rate-limited value\n * - `rateLimited.set(...)`: Set or update the rate-limited value (rate-limited via maybeExecute)\n * - `rateLimited.rateLimiter`: The rate limiter instance with additional control methods and state signals\n *\n * ## State Management and Selector\n *\n * The function 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 signal 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 updates and gives you\n * full control over when your component tracks state changes.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const rateLimited = injectRateLimitedSignal(0, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to reactive updates when limit state changes\n * const rateLimited = injectRateLimitedSignal(\n * 0,\n * { limit: 5, window: 60000 },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n * ```\n */\nexport function injectRateLimitedSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n selector?: (state: RateLimiterState) => TSelected,\n): RateLimitedSignal<TValue, TSelected> {\n const rateLimitedValue = signal<TValue>(value)\n\n const rateLimiter = injectRateLimiter(\n (newValue: TValue | ((prev: TValue) => TValue)) => {\n if (typeof newValue === 'function') {\n rateLimitedValue.update(newValue as (prev: TValue) => TValue)\n } else {\n rateLimitedValue.set(newValue)\n }\n },\n initialOptions,\n selector,\n )\n\n const set: Setter<TValue> = (\n newValue: TValue | ((prev: TValue) => TValue),\n ) => {\n rateLimiter.maybeExecute(newValue)\n }\n\n const rateLimited = Object.assign(() => rateLimitedValue(), {\n set,\n rateLimiter,\n }) as RateLimitedSignal<TValue, TSelected>\n\n return rateLimited\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,SAAgB,wBACd,OACA,gBACA,UACsC;CACtC,MAAM,
|
|
1
|
+
{"version":3,"file":"injectRateLimitedSignal.cjs","names":["signal","injectRateLimiter"],"sources":["../../src/rate-limiter/injectRateLimitedSignal.ts"],"sourcesContent":["import { signal } from '@angular/core'\nimport { injectRateLimiter } from './injectRateLimiter'\nimport type { AngularRateLimiter } from './injectRateLimiter'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\nexport interface RateLimitedSignal<TValue, TSelected = {}> {\n (): TValue\n set: Setter<TValue>\n rateLimiter: AngularRateLimiter<Setter<TValue>, TSelected>\n}\n\n/**\n * An Angular function that creates a rate-limited state signal, combining Angular's signal with rate limiting functionality.\n * This function provides both the current rate-limited value and methods to update it.\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.\n *\n * The function returns a callable object:\n * - `rateLimited()`: Get the current rate-limited value\n * - `rateLimited.set(...)`: Set or update the rate-limited value (rate-limited via maybeExecute)\n * - `rateLimited.rateLimiter`: The rate limiter instance with additional control methods and state signals\n *\n * ## State Management and Selector\n *\n * The function 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 signal 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 updates and gives you\n * full control over when your component tracks state changes.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const rateLimited = injectRateLimitedSignal(0, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to reactive updates when limit state changes\n * const rateLimited = injectRateLimitedSignal(\n * 0,\n * { limit: 5, window: 60000 },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n * ```\n */\nexport function injectRateLimitedSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n selector?: (state: RateLimiterState) => TSelected,\n): RateLimitedSignal<TValue, TSelected> {\n const rateLimitedValue = signal<TValue>(value)\n\n const rateLimiter = injectRateLimiter(\n (newValue: TValue | ((prev: TValue) => TValue)) => {\n if (typeof newValue === 'function') {\n rateLimitedValue.update(newValue as (prev: TValue) => TValue)\n } else {\n rateLimitedValue.set(newValue)\n }\n },\n initialOptions,\n selector,\n )\n\n const set: Setter<TValue> = (\n newValue: TValue | ((prev: TValue) => TValue),\n ) => {\n rateLimiter.maybeExecute(newValue)\n }\n\n const rateLimited = Object.assign(() => rateLimitedValue(), {\n set,\n rateLimiter,\n }) as RateLimitedSignal<TValue, TSelected>\n\n return rateLimited\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,SAAgB,wBACd,OACA,gBACA,UACsC;CACtC,MAAM,uBAAmBA,sBAAe,KAAK;CAE7C,MAAM,cAAcC,6CACjB,aAAkD;EACjD,IAAI,OAAO,aAAa,YACtB,iBAAiB,OAAO,QAAoC;OAE5D,iBAAiB,IAAI,QAAQ;CAEjC,GACA,gBACA,QACF;CAEA,MAAM,OACJ,aACG;EACH,YAAY,aAAa,QAAQ;CACnC;CAOA,OALoB,OAAO,aAAa,iBAAiB,GAAG;EAC1D;EACA;CACF,CAEiB;AACnB"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AngularRateLimiter } from "./injectRateLimiter.cjs";
|
|
2
2
|
import { RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
3
|
-
|
|
4
3
|
//#region src/rate-limiter/injectRateLimitedSignal.d.ts
|
|
5
4
|
type Setter<T> = (value: T | ((prev: T) => T)) => void;
|
|
6
5
|
interface RateLimitedSignal<TValue, TSelected = {}> {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AngularRateLimiter } from "./injectRateLimiter.js";
|
|
2
2
|
import { RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
3
|
-
|
|
4
3
|
//#region src/rate-limiter/injectRateLimitedSignal.d.ts
|
|
5
4
|
type Setter<T> = (value: T | ((prev: T) => T)) => void;
|
|
6
5
|
interface RateLimitedSignal<TValue, TSelected = {}> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectRateLimitedSignal.js","names":[],"sources":["../../src/rate-limiter/injectRateLimitedSignal.ts"],"sourcesContent":["import { signal } from '@angular/core'\nimport { injectRateLimiter } from './injectRateLimiter'\nimport type { AngularRateLimiter } from './injectRateLimiter'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\nexport interface RateLimitedSignal<TValue, TSelected = {}> {\n (): TValue\n set: Setter<TValue>\n rateLimiter: AngularRateLimiter<Setter<TValue>, TSelected>\n}\n\n/**\n * An Angular function that creates a rate-limited state signal, combining Angular's signal with rate limiting functionality.\n * This function provides both the current rate-limited value and methods to update it.\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.\n *\n * The function returns a callable object:\n * - `rateLimited()`: Get the current rate-limited value\n * - `rateLimited.set(...)`: Set or update the rate-limited value (rate-limited via maybeExecute)\n * - `rateLimited.rateLimiter`: The rate limiter instance with additional control methods and state signals\n *\n * ## State Management and Selector\n *\n * The function 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 signal 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 updates and gives you\n * full control over when your component tracks state changes.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const rateLimited = injectRateLimitedSignal(0, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to reactive updates when limit state changes\n * const rateLimited = injectRateLimitedSignal(\n * 0,\n * { limit: 5, window: 60000 },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n * ```\n */\nexport function injectRateLimitedSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n selector?: (state: RateLimiterState) => TSelected,\n): RateLimitedSignal<TValue, TSelected> {\n const rateLimitedValue = signal<TValue>(value)\n\n const rateLimiter = injectRateLimiter(\n (newValue: TValue | ((prev: TValue) => TValue)) => {\n if (typeof newValue === 'function') {\n rateLimitedValue.update(newValue as (prev: TValue) => TValue)\n } else {\n rateLimitedValue.set(newValue)\n }\n },\n initialOptions,\n selector,\n )\n\n const set: Setter<TValue> = (\n newValue: TValue | ((prev: TValue) => TValue),\n ) => {\n rateLimiter.maybeExecute(newValue)\n }\n\n const rateLimited = Object.assign(() => rateLimitedValue(), {\n set,\n rateLimiter,\n }) as RateLimitedSignal<TValue, TSelected>\n\n return rateLimited\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,SAAgB,wBACd,OACA,gBACA,UACsC;CACtC,MAAM,mBAAmB,OAAe,
|
|
1
|
+
{"version":3,"file":"injectRateLimitedSignal.js","names":[],"sources":["../../src/rate-limiter/injectRateLimitedSignal.ts"],"sourcesContent":["import { signal } from '@angular/core'\nimport { injectRateLimiter } from './injectRateLimiter'\nimport type { AngularRateLimiter } from './injectRateLimiter'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\nexport interface RateLimitedSignal<TValue, TSelected = {}> {\n (): TValue\n set: Setter<TValue>\n rateLimiter: AngularRateLimiter<Setter<TValue>, TSelected>\n}\n\n/**\n * An Angular function that creates a rate-limited state signal, combining Angular's signal with rate limiting functionality.\n * This function provides both the current rate-limited value and methods to update it.\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.\n *\n * The function returns a callable object:\n * - `rateLimited()`: Get the current rate-limited value\n * - `rateLimited.set(...)`: Set or update the rate-limited value (rate-limited via maybeExecute)\n * - `rateLimited.rateLimiter`: The rate limiter instance with additional control methods and state signals\n *\n * ## State Management and Selector\n *\n * The function 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 signal 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 updates and gives you\n * full control over when your component tracks state changes.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const rateLimited = injectRateLimitedSignal(0, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to reactive updates when limit state changes\n * const rateLimited = injectRateLimitedSignal(\n * 0,\n * { limit: 5, window: 60000 },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n * ```\n */\nexport function injectRateLimitedSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n selector?: (state: RateLimiterState) => TSelected,\n): RateLimitedSignal<TValue, TSelected> {\n const rateLimitedValue = signal<TValue>(value)\n\n const rateLimiter = injectRateLimiter(\n (newValue: TValue | ((prev: TValue) => TValue)) => {\n if (typeof newValue === 'function') {\n rateLimitedValue.update(newValue as (prev: TValue) => TValue)\n } else {\n rateLimitedValue.set(newValue)\n }\n },\n initialOptions,\n selector,\n )\n\n const set: Setter<TValue> = (\n newValue: TValue | ((prev: TValue) => TValue),\n ) => {\n rateLimiter.maybeExecute(newValue)\n }\n\n const rateLimited = Object.assign(() => rateLimitedValue(), {\n set,\n rateLimiter,\n }) as RateLimitedSignal<TValue, TSelected>\n\n return rateLimited\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,SAAgB,wBACd,OACA,gBACA,UACsC;CACtC,MAAM,mBAAmB,OAAe,KAAK;CAE7C,MAAM,cAAc,mBACjB,aAAkD;EACjD,IAAI,OAAO,aAAa,YACtB,iBAAiB,OAAO,QAAoC;OAE5D,iBAAiB,IAAI,QAAQ;CAEjC,GACA,gBACA,QACF;CAEA,MAAM,OACJ,aACG;EACH,YAAY,aAAa,QAAQ;CACnC;CAOA,OALoB,OAAO,aAAa,iBAAiB,GAAG;EAC1D;EACA;CACF,CAEiB;AACnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectRateLimitedValue.cjs","names":["injectRateLimitedSignal"],"sources":["../../src/rate-limiter/injectRateLimitedValue.ts"],"sourcesContent":["import { effect } from '@angular/core'\nimport { injectRateLimitedSignal } from './injectRateLimitedSignal'\nimport type { RateLimitedSignal } from './injectRateLimitedSignal'\nimport type { Signal } from '@angular/core'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\n/**\n * An Angular function that creates a rate-limited value that updates at most a certain number of times within a time window.\n * Unlike injectRateLimitedSignal, this function automatically tracks changes to the input signal\n * and updates the rate-limited value accordingly.\n *\n * The rate-limited value will update according to the configured rate limit, blocking updates\n * once the limit is reached until the window resets.\n *\n * The function returns a rate-limited signal object containing:\n * - A Signal that provides the current rate-limited value\n * - The rate limiter instance with control methods\n *\n * ## State Management and Selector\n *\n * The function 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 signal 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 updates and gives you\n * full control over when your component tracks state changes.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const value = signal(0)\n * const rateLimited = injectRateLimitedValue(value, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * })\n *\n * // rateLimited() will update at most 5 times per 60 seconds\n * effect(() => {\n * updateUI(rateLimited())\n * })\n * ```\n */\nexport function injectRateLimitedValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n selector?: (state: RateLimiterState) => TSelected,\n): RateLimitedSignal<TValue, TSelected>\nexport function injectRateLimitedValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValue: TValue,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n selector?: (state: RateLimiterState) => TSelected,\n): RateLimitedSignal<TValue, TSelected>\nexport function injectRateLimitedValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValueOrOptions: TValue | RateLimiterOptions<Setter<TValue>>,\n initialOptionsOrSelector?:\n | RateLimiterOptions<Setter<TValue>>\n | ((state: RateLimiterState) => TSelected),\n maybeSelector?: (state: RateLimiterState) => TSelected,\n): RateLimitedSignal<TValue, TSelected> {\n const hasSelector = typeof initialOptionsOrSelector === 'function'\n\n const hasInitialValue =\n (initialOptionsOrSelector !== undefined && !hasSelector) ||\n maybeSelector !== undefined\n\n const initialValue = hasInitialValue\n ? (initialValueOrOptions as TValue)\n : (undefined as unknown as TValue)\n const initialOptions = hasInitialValue\n ? (initialOptionsOrSelector as RateLimiterOptions<Setter<TValue>>)\n : (initialValueOrOptions as RateLimiterOptions<Setter<TValue>>)\n const selector = hasInitialValue\n ? maybeSelector\n : (initialOptionsOrSelector as\n
|
|
1
|
+
{"version":3,"file":"injectRateLimitedValue.cjs","names":["injectRateLimitedSignal"],"sources":["../../src/rate-limiter/injectRateLimitedValue.ts"],"sourcesContent":["import { effect } from '@angular/core'\nimport { injectRateLimitedSignal } from './injectRateLimitedSignal'\nimport type { RateLimitedSignal } from './injectRateLimitedSignal'\nimport type { Signal } from '@angular/core'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\n/**\n * An Angular function that creates a rate-limited value that updates at most a certain number of times within a time window.\n * Unlike injectRateLimitedSignal, this function automatically tracks changes to the input signal\n * and updates the rate-limited value accordingly.\n *\n * The rate-limited value will update according to the configured rate limit, blocking updates\n * once the limit is reached until the window resets.\n *\n * The function returns a rate-limited signal object containing:\n * - A Signal that provides the current rate-limited value\n * - The rate limiter instance with control methods\n *\n * ## State Management and Selector\n *\n * The function 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 signal 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 updates and gives you\n * full control over when your component tracks state changes.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const value = signal(0)\n * const rateLimited = injectRateLimitedValue(value, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * })\n *\n * // rateLimited() will update at most 5 times per 60 seconds\n * effect(() => {\n * updateUI(rateLimited())\n * })\n * ```\n */\nexport function injectRateLimitedValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n selector?: (state: RateLimiterState) => TSelected,\n): RateLimitedSignal<TValue, TSelected>\nexport function injectRateLimitedValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValue: TValue,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n selector?: (state: RateLimiterState) => TSelected,\n): RateLimitedSignal<TValue, TSelected>\nexport function injectRateLimitedValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValueOrOptions: TValue | RateLimiterOptions<Setter<TValue>>,\n initialOptionsOrSelector?:\n | RateLimiterOptions<Setter<TValue>>\n | ((state: RateLimiterState) => TSelected),\n maybeSelector?: (state: RateLimiterState) => TSelected,\n): RateLimitedSignal<TValue, TSelected> {\n const hasSelector = typeof initialOptionsOrSelector === 'function'\n\n const hasInitialValue =\n (initialOptionsOrSelector !== undefined && !hasSelector) ||\n maybeSelector !== undefined\n\n const initialValue = hasInitialValue\n ? (initialValueOrOptions as TValue)\n : (undefined as unknown as TValue)\n const initialOptions = hasInitialValue\n ? (initialOptionsOrSelector as RateLimiterOptions<Setter<TValue>>)\n : (initialValueOrOptions as RateLimiterOptions<Setter<TValue>>)\n const selector = hasInitialValue\n ? maybeSelector\n : (initialOptionsOrSelector as\n ((state: RateLimiterState) => TSelected) | undefined)\n\n const rateLimited = injectRateLimitedSignal(\n initialValue,\n initialOptions,\n selector,\n )\n\n effect(() => {\n const latest = value()\n rateLimited.set(latest)\n })\n\n return rateLimited\n}\n"],"mappings":";;;;AA4DA,SAAgB,uBACd,OACA,uBACA,0BAGA,eACsC;CAGtC,MAAM,kBACH,6BAA6B,UAAa,EAHzB,OAAO,6BAA6B,eAItD,kBAAkB;CAapB,MAAM,cAAcA,wDAXC,kBAChB,wBACA,QACkB,kBAClB,2BACA,uBACY,kBACb,gBACC,wBAOL;CAEA,gCAAa;EACX,MAAM,SAAS,MAAM;EACrB,YAAY,IAAI,MAAM;CACxB,CAAC;CAED,OAAO;AACT"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { RateLimitedSignal } from "./injectRateLimitedSignal.cjs";
|
|
2
2
|
import { Signal } from "@angular/core";
|
|
3
3
|
import { RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
4
|
-
|
|
5
4
|
//#region src/rate-limiter/injectRateLimitedValue.d.ts
|
|
6
5
|
type Setter<T> = (value: T | ((prev: T) => T)) => void;
|
|
7
6
|
/**
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { RateLimitedSignal } from "./injectRateLimitedSignal.js";
|
|
2
2
|
import { Signal } from "@angular/core";
|
|
3
3
|
import { RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
4
|
-
|
|
5
4
|
//#region src/rate-limiter/injectRateLimitedValue.d.ts
|
|
6
5
|
type Setter<T> = (value: T | ((prev: T) => T)) => void;
|
|
7
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectRateLimitedValue.js","names":[],"sources":["../../src/rate-limiter/injectRateLimitedValue.ts"],"sourcesContent":["import { effect } from '@angular/core'\nimport { injectRateLimitedSignal } from './injectRateLimitedSignal'\nimport type { RateLimitedSignal } from './injectRateLimitedSignal'\nimport type { Signal } from '@angular/core'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\n/**\n * An Angular function that creates a rate-limited value that updates at most a certain number of times within a time window.\n * Unlike injectRateLimitedSignal, this function automatically tracks changes to the input signal\n * and updates the rate-limited value accordingly.\n *\n * The rate-limited value will update according to the configured rate limit, blocking updates\n * once the limit is reached until the window resets.\n *\n * The function returns a rate-limited signal object containing:\n * - A Signal that provides the current rate-limited value\n * - The rate limiter instance with control methods\n *\n * ## State Management and Selector\n *\n * The function 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 signal 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 updates and gives you\n * full control over when your component tracks state changes.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const value = signal(0)\n * const rateLimited = injectRateLimitedValue(value, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * })\n *\n * // rateLimited() will update at most 5 times per 60 seconds\n * effect(() => {\n * updateUI(rateLimited())\n * })\n * ```\n */\nexport function injectRateLimitedValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n selector?: (state: RateLimiterState) => TSelected,\n): RateLimitedSignal<TValue, TSelected>\nexport function injectRateLimitedValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValue: TValue,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n selector?: (state: RateLimiterState) => TSelected,\n): RateLimitedSignal<TValue, TSelected>\nexport function injectRateLimitedValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValueOrOptions: TValue | RateLimiterOptions<Setter<TValue>>,\n initialOptionsOrSelector?:\n | RateLimiterOptions<Setter<TValue>>\n | ((state: RateLimiterState) => TSelected),\n maybeSelector?: (state: RateLimiterState) => TSelected,\n): RateLimitedSignal<TValue, TSelected> {\n const hasSelector = typeof initialOptionsOrSelector === 'function'\n\n const hasInitialValue =\n (initialOptionsOrSelector !== undefined && !hasSelector) ||\n maybeSelector !== undefined\n\n const initialValue = hasInitialValue\n ? (initialValueOrOptions as TValue)\n : (undefined as unknown as TValue)\n const initialOptions = hasInitialValue\n ? (initialOptionsOrSelector as RateLimiterOptions<Setter<TValue>>)\n : (initialValueOrOptions as RateLimiterOptions<Setter<TValue>>)\n const selector = hasInitialValue\n ? maybeSelector\n : (initialOptionsOrSelector as\n
|
|
1
|
+
{"version":3,"file":"injectRateLimitedValue.js","names":[],"sources":["../../src/rate-limiter/injectRateLimitedValue.ts"],"sourcesContent":["import { effect } from '@angular/core'\nimport { injectRateLimitedSignal } from './injectRateLimitedSignal'\nimport type { RateLimitedSignal } from './injectRateLimitedSignal'\nimport type { Signal } from '@angular/core'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\n/**\n * An Angular function that creates a rate-limited value that updates at most a certain number of times within a time window.\n * Unlike injectRateLimitedSignal, this function automatically tracks changes to the input signal\n * and updates the rate-limited value accordingly.\n *\n * The rate-limited value will update according to the configured rate limit, blocking updates\n * once the limit is reached until the window resets.\n *\n * The function returns a rate-limited signal object containing:\n * - A Signal that provides the current rate-limited value\n * - The rate limiter instance with control methods\n *\n * ## State Management and Selector\n *\n * The function 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 signal 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 updates and gives you\n * full control over when your component tracks state changes.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const value = signal(0)\n * const rateLimited = injectRateLimitedValue(value, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * })\n *\n * // rateLimited() will update at most 5 times per 60 seconds\n * effect(() => {\n * updateUI(rateLimited())\n * })\n * ```\n */\nexport function injectRateLimitedValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n selector?: (state: RateLimiterState) => TSelected,\n): RateLimitedSignal<TValue, TSelected>\nexport function injectRateLimitedValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValue: TValue,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n selector?: (state: RateLimiterState) => TSelected,\n): RateLimitedSignal<TValue, TSelected>\nexport function injectRateLimitedValue<TValue, TSelected = {}>(\n value: Signal<TValue>,\n initialValueOrOptions: TValue | RateLimiterOptions<Setter<TValue>>,\n initialOptionsOrSelector?:\n | RateLimiterOptions<Setter<TValue>>\n | ((state: RateLimiterState) => TSelected),\n maybeSelector?: (state: RateLimiterState) => TSelected,\n): RateLimitedSignal<TValue, TSelected> {\n const hasSelector = typeof initialOptionsOrSelector === 'function'\n\n const hasInitialValue =\n (initialOptionsOrSelector !== undefined && !hasSelector) ||\n maybeSelector !== undefined\n\n const initialValue = hasInitialValue\n ? (initialValueOrOptions as TValue)\n : (undefined as unknown as TValue)\n const initialOptions = hasInitialValue\n ? (initialOptionsOrSelector as RateLimiterOptions<Setter<TValue>>)\n : (initialValueOrOptions as RateLimiterOptions<Setter<TValue>>)\n const selector = hasInitialValue\n ? maybeSelector\n : (initialOptionsOrSelector as\n ((state: RateLimiterState) => TSelected) | undefined)\n\n const rateLimited = injectRateLimitedSignal(\n initialValue,\n initialOptions,\n selector,\n )\n\n effect(() => {\n const latest = value()\n rateLimited.set(latest)\n })\n\n return rateLimited\n}\n"],"mappings":";;;;AA4DA,SAAgB,uBACd,OACA,uBACA,0BAGA,eACsC;CAGtC,MAAM,kBACH,6BAA6B,UAAa,EAHzB,OAAO,6BAA6B,eAItD,kBAAkB;CAapB,MAAM,cAAc,wBAXC,kBAChB,wBACA,QACkB,kBAClB,2BACA,uBACY,kBACb,gBACC,wBAOL;CAEA,aAAa;EACX,MAAM,SAAS,MAAM;EACrB,YAAY,IAAI,MAAM;CACxB,CAAC;CAED,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectRateLimiter.cjs","names":["injectPacerOptions","RateLimiter","DestroyRef"],"sources":["../../src/rate-limiter/injectRateLimiter.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } from '@tanstack/angular-store'\nimport { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\nexport interface AngularRateLimiterOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends RateLimiterOptions<TFn> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the rate limiter instance.\n */\n onUnmount?: (rateLimiter: AngularRateLimiter<TFn, TSelected>) => void\n}\n\nexport interface AngularRateLimiter<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<RateLimiter<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the rate limiter state changes\n *\n * Use this instead of `rateLimiter.store.state`\n */\n readonly state: Signal<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 in Angular signals.\n */\n readonly store: Store<Readonly<RateLimiterState>>\n}\n\n/**\n * An Angular function that creates and manages a RateLimiter instance.\n *\n * This is a lower-level function that provides direct access to the RateLimiter's functionality.\n * This allows you to integrate it with any state management solution you prefer.\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 function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates 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 updates and gives you\n * 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 * - `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 * ## Cleanup on Destroy\n *\n * Use the `onUnmount` option to run a callback when the component is destroyed.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const rateLimiter = injectRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * });\n *\n * // Opt-in to track execution count changes\n * const rateLimiter = injectRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ executionCount: state.executionCount })\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 injectRateLimiter<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: AngularRateLimiterOptions<TFn, TSelected>,\n selector: (state: RateLimiterState) => TSelected = () => ({}) as TSelected,\n): AngularRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().rateLimiter,\n ...options,\n } as AngularRateLimiterOptions<TFn, TSelected>\n\n const rateLimiter = new RateLimiter<TFn>(fn, mergedOptions)\n const state = injectSelector(rateLimiter.store, selector)\n\n const result = {\n ...rateLimiter,\n state,\n } as AngularRateLimiter<TFn, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiHA,SAAgB,kBACd,IACA,SACA,kBAA0D,
|
|
1
|
+
{"version":3,"file":"injectRateLimiter.cjs","names":["injectPacerOptions","RateLimiter","injectSelector","inject","DestroyRef"],"sources":["../../src/rate-limiter/injectRateLimiter.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } from '@tanstack/angular-store'\nimport { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\nexport interface AngularRateLimiterOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends RateLimiterOptions<TFn> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the rate limiter instance.\n */\n onUnmount?: (rateLimiter: AngularRateLimiter<TFn, TSelected>) => void\n}\n\nexport interface AngularRateLimiter<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<RateLimiter<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the rate limiter state changes\n *\n * Use this instead of `rateLimiter.store.state`\n */\n readonly state: Signal<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 in Angular signals.\n */\n readonly store: Store<Readonly<RateLimiterState>>\n}\n\n/**\n * An Angular function that creates and manages a RateLimiter instance.\n *\n * This is a lower-level function that provides direct access to the RateLimiter's functionality.\n * This allows you to integrate it with any state management solution you prefer.\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 function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates 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 updates and gives you\n * 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 * - `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 * ## Cleanup on Destroy\n *\n * Use the `onUnmount` option to run a callback when the component is destroyed.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const rateLimiter = injectRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * });\n *\n * // Opt-in to track execution count changes\n * const rateLimiter = injectRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ executionCount: state.executionCount })\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 injectRateLimiter<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: AngularRateLimiterOptions<TFn, TSelected>,\n selector: (state: RateLimiterState) => TSelected = () => ({}) as TSelected,\n): AngularRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().rateLimiter,\n ...options,\n } as AngularRateLimiterOptions<TFn, TSelected>\n\n const rateLimiter = new RateLimiter<TFn>(fn, mergedOptions)\n const state = injectSelector(rateLimiter.store, selector)\n\n const result = {\n ...rateLimiter,\n state,\n } as AngularRateLimiter<TFn, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiHA,SAAgB,kBACd,IACA,SACA,kBAA0D,CAAC,IACvB;CACpC,MAAM,gBAAgB;EACpB,GAAGA,yCAAmB,CAAC,CAAC;EACxB,GAAG;CACL;CAEA,MAAM,cAAc,IAAIC,yCAAiB,IAAI,aAAa;CAC1D,MAAM,YAAQC,wCAAe,YAAY,OAAO,QAAQ;CAExD,MAAM,SAAS;EACb,GAAG;EACH;CACF;CAGA,IADmBC,sBAAOC,0BAAY,EAAE,UAAU,KAAK,CAC9C,CAAC,EAAE,gBAAgB;EAC1B,IAAI,cAAc,WAChB,cAAc,UAAU,MAAM;CAElC,CAAC;CAED,OAAO;AACT"}
|
|
@@ -2,7 +2,6 @@ import { Signal } from "@angular/core";
|
|
|
2
2
|
import { Store } from "@tanstack/angular-store";
|
|
3
3
|
import { AnyFunction } from "@tanstack/pacer/types";
|
|
4
4
|
import { RateLimiter, RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
5
|
-
|
|
6
5
|
//#region src/rate-limiter/injectRateLimiter.d.ts
|
|
7
6
|
interface AngularRateLimiterOptions<TFn extends AnyFunction, TSelected = {}> extends RateLimiterOptions<TFn> {
|
|
8
7
|
/**
|
|
@@ -2,7 +2,6 @@ import { Signal } from "@angular/core";
|
|
|
2
2
|
import { Store } from "@tanstack/angular-store";
|
|
3
3
|
import { RateLimiter, RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
4
4
|
import { AnyFunction } from "@tanstack/pacer/types";
|
|
5
|
-
|
|
6
5
|
//#region src/rate-limiter/injectRateLimiter.d.ts
|
|
7
6
|
interface AngularRateLimiterOptions<TFn extends AnyFunction, TSelected = {}> extends RateLimiterOptions<TFn> {
|
|
8
7
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectRateLimiter.js","names":[],"sources":["../../src/rate-limiter/injectRateLimiter.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } from '@tanstack/angular-store'\nimport { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\nexport interface AngularRateLimiterOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends RateLimiterOptions<TFn> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the rate limiter instance.\n */\n onUnmount?: (rateLimiter: AngularRateLimiter<TFn, TSelected>) => void\n}\n\nexport interface AngularRateLimiter<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<RateLimiter<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the rate limiter state changes\n *\n * Use this instead of `rateLimiter.store.state`\n */\n readonly state: Signal<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 in Angular signals.\n */\n readonly store: Store<Readonly<RateLimiterState>>\n}\n\n/**\n * An Angular function that creates and manages a RateLimiter instance.\n *\n * This is a lower-level function that provides direct access to the RateLimiter's functionality.\n * This allows you to integrate it with any state management solution you prefer.\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 function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates 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 updates and gives you\n * 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 * - `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 * ## Cleanup on Destroy\n *\n * Use the `onUnmount` option to run a callback when the component is destroyed.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const rateLimiter = injectRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * });\n *\n * // Opt-in to track execution count changes\n * const rateLimiter = injectRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ executionCount: state.executionCount })\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 injectRateLimiter<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: AngularRateLimiterOptions<TFn, TSelected>,\n selector: (state: RateLimiterState) => TSelected = () => ({}) as TSelected,\n): AngularRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().rateLimiter,\n ...options,\n } as AngularRateLimiterOptions<TFn, TSelected>\n\n const rateLimiter = new RateLimiter<TFn>(fn, mergedOptions)\n const state = injectSelector(rateLimiter.store, selector)\n\n const result = {\n ...rateLimiter,\n state,\n } as AngularRateLimiter<TFn, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiHA,SAAgB,kBACd,IACA,SACA,kBAA0D,
|
|
1
|
+
{"version":3,"file":"injectRateLimiter.js","names":[],"sources":["../../src/rate-limiter/injectRateLimiter.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } from '@tanstack/angular-store'\nimport { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\nexport interface AngularRateLimiterOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends RateLimiterOptions<TFn> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the rate limiter instance.\n */\n onUnmount?: (rateLimiter: AngularRateLimiter<TFn, TSelected>) => void\n}\n\nexport interface AngularRateLimiter<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<RateLimiter<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the rate limiter state changes\n *\n * Use this instead of `rateLimiter.store.state`\n */\n readonly state: Signal<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 in Angular signals.\n */\n readonly store: Store<Readonly<RateLimiterState>>\n}\n\n/**\n * An Angular function that creates and manages a RateLimiter instance.\n *\n * This is a lower-level function that provides direct access to the RateLimiter's functionality.\n * This allows you to integrate it with any state management solution you prefer.\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 function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates 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 updates and gives you\n * 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 * - `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 * ## Cleanup on Destroy\n *\n * Use the `onUnmount` option to run a callback when the component is destroyed.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const rateLimiter = injectRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * });\n *\n * // Opt-in to track execution count changes\n * const rateLimiter = injectRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ executionCount: state.executionCount })\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 injectRateLimiter<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: AngularRateLimiterOptions<TFn, TSelected>,\n selector: (state: RateLimiterState) => TSelected = () => ({}) as TSelected,\n): AngularRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().rateLimiter,\n ...options,\n } as AngularRateLimiterOptions<TFn, TSelected>\n\n const rateLimiter = new RateLimiter<TFn>(fn, mergedOptions)\n const state = injectSelector(rateLimiter.store, selector)\n\n const result = {\n ...rateLimiter,\n state,\n } as AngularRateLimiter<TFn, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiHA,SAAgB,kBACd,IACA,SACA,kBAA0D,CAAC,IACvB;CACpC,MAAM,gBAAgB;EACpB,GAAG,mBAAmB,CAAC,CAAC;EACxB,GAAG;CACL;CAEA,MAAM,cAAc,IAAI,YAAiB,IAAI,aAAa;CAC1D,MAAM,QAAQ,eAAe,YAAY,OAAO,QAAQ;CAExD,MAAM,SAAS;EACb,GAAG;EACH;CACF;CAGA,AADmB,OAAO,YAAY,EAAE,UAAU,KAAK,CAC9C,CAAC,EAAE,gBAAgB;EAC1B,IAAI,cAAc,WAChB,cAAc,UAAU,MAAM;CAElC,CAAC;CAED,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectThrottledCallback.cjs","names":["injectThrottler"],"sources":["../../src/throttler/injectThrottledCallback.ts"],"sourcesContent":["import { injectThrottler } from './injectThrottler'\nimport type { ThrottlerOptions } from '@tanstack/pacer/throttler'\nimport type { AnyFunction } from '@tanstack/pacer/types'\n\n/**\n * An Angular function that creates a throttled version of a callback function.\n * This function is essentially a wrapper around `injectThrottler` that provides\n * a simplified API for basic throttling needs.\n *\n * The throttled function will execute at most once within the specified wait time.\n * If called multiple times within the wait period, only the first call (if leading is enabled)\n * or the last call (if trailing is enabled) will execute.\n *\n * This function provides a simpler API compared to `injectThrottler`, making it ideal for basic\n * throttling needs. However, it does not expose the underlying Throttler instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation\n * - Access to execution counts\n * - State tracking\n *\n * Consider using the `injectThrottler` function instead.\n *\n * @example\n * ```ts\n * // Throttle a scroll handler\n * const handleScroll = injectThrottledCallback((scrollY: number) => {\n * updateScrollPosition(scrollY);\n * }, {\n * wait: 100 // Execute at most once per 100ms\n * });\n *\n * // Use in an event listener\n * window.addEventListener('scroll', () => {\n * handleScroll(window.scrollY);\n * });\n * ```\n */\nexport function injectThrottledCallback<TFn extends AnyFunction>(\n fn: TFn,\n options: ThrottlerOptions<TFn>,\n): (...args: Parameters<TFn>) => void {\n const throttler = injectThrottler(fn, options)\n return (...args: Parameters<TFn>) => throttler.maybeExecute(...args)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,wBACd,IACA,SACoC;CACpC,MAAM,YAAYA,wCAAgB,IAAI,
|
|
1
|
+
{"version":3,"file":"injectThrottledCallback.cjs","names":["injectThrottler"],"sources":["../../src/throttler/injectThrottledCallback.ts"],"sourcesContent":["import { injectThrottler } from './injectThrottler'\nimport type { ThrottlerOptions } from '@tanstack/pacer/throttler'\nimport type { AnyFunction } from '@tanstack/pacer/types'\n\n/**\n * An Angular function that creates a throttled version of a callback function.\n * This function is essentially a wrapper around `injectThrottler` that provides\n * a simplified API for basic throttling needs.\n *\n * The throttled function will execute at most once within the specified wait time.\n * If called multiple times within the wait period, only the first call (if leading is enabled)\n * or the last call (if trailing is enabled) will execute.\n *\n * This function provides a simpler API compared to `injectThrottler`, making it ideal for basic\n * throttling needs. However, it does not expose the underlying Throttler instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation\n * - Access to execution counts\n * - State tracking\n *\n * Consider using the `injectThrottler` function instead.\n *\n * @example\n * ```ts\n * // Throttle a scroll handler\n * const handleScroll = injectThrottledCallback((scrollY: number) => {\n * updateScrollPosition(scrollY);\n * }, {\n * wait: 100 // Execute at most once per 100ms\n * });\n *\n * // Use in an event listener\n * window.addEventListener('scroll', () => {\n * handleScroll(window.scrollY);\n * });\n * ```\n */\nexport function injectThrottledCallback<TFn extends AnyFunction>(\n fn: TFn,\n options: ThrottlerOptions<TFn>,\n): (...args: Parameters<TFn>) => void {\n const throttler = injectThrottler(fn, options)\n return (...args: Parameters<TFn>) => throttler.maybeExecute(...args)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,wBACd,IACA,SACoC;CACpC,MAAM,YAAYA,wCAAgB,IAAI,OAAO;CAC7C,QAAQ,GAAG,SAA0B,UAAU,aAAa,GAAG,IAAI;AACrE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectThrottledCallback.js","names":[],"sources":["../../src/throttler/injectThrottledCallback.ts"],"sourcesContent":["import { injectThrottler } from './injectThrottler'\nimport type { ThrottlerOptions } from '@tanstack/pacer/throttler'\nimport type { AnyFunction } from '@tanstack/pacer/types'\n\n/**\n * An Angular function that creates a throttled version of a callback function.\n * This function is essentially a wrapper around `injectThrottler` that provides\n * a simplified API for basic throttling needs.\n *\n * The throttled function will execute at most once within the specified wait time.\n * If called multiple times within the wait period, only the first call (if leading is enabled)\n * or the last call (if trailing is enabled) will execute.\n *\n * This function provides a simpler API compared to `injectThrottler`, making it ideal for basic\n * throttling needs. However, it does not expose the underlying Throttler instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation\n * - Access to execution counts\n * - State tracking\n *\n * Consider using the `injectThrottler` function instead.\n *\n * @example\n * ```ts\n * // Throttle a scroll handler\n * const handleScroll = injectThrottledCallback((scrollY: number) => {\n * updateScrollPosition(scrollY);\n * }, {\n * wait: 100 // Execute at most once per 100ms\n * });\n *\n * // Use in an event listener\n * window.addEventListener('scroll', () => {\n * handleScroll(window.scrollY);\n * });\n * ```\n */\nexport function injectThrottledCallback<TFn extends AnyFunction>(\n fn: TFn,\n options: ThrottlerOptions<TFn>,\n): (...args: Parameters<TFn>) => void {\n const throttler = injectThrottler(fn, options)\n return (...args: Parameters<TFn>) => throttler.maybeExecute(...args)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,wBACd,IACA,SACoC;CACpC,MAAM,YAAY,gBAAgB,IAAI,
|
|
1
|
+
{"version":3,"file":"injectThrottledCallback.js","names":[],"sources":["../../src/throttler/injectThrottledCallback.ts"],"sourcesContent":["import { injectThrottler } from './injectThrottler'\nimport type { ThrottlerOptions } from '@tanstack/pacer/throttler'\nimport type { AnyFunction } from '@tanstack/pacer/types'\n\n/**\n * An Angular function that creates a throttled version of a callback function.\n * This function is essentially a wrapper around `injectThrottler` that provides\n * a simplified API for basic throttling needs.\n *\n * The throttled function will execute at most once within the specified wait time.\n * If called multiple times within the wait period, only the first call (if leading is enabled)\n * or the last call (if trailing is enabled) will execute.\n *\n * This function provides a simpler API compared to `injectThrottler`, making it ideal for basic\n * throttling needs. However, it does not expose the underlying Throttler instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation\n * - Access to execution counts\n * - State tracking\n *\n * Consider using the `injectThrottler` function instead.\n *\n * @example\n * ```ts\n * // Throttle a scroll handler\n * const handleScroll = injectThrottledCallback((scrollY: number) => {\n * updateScrollPosition(scrollY);\n * }, {\n * wait: 100 // Execute at most once per 100ms\n * });\n *\n * // Use in an event listener\n * window.addEventListener('scroll', () => {\n * handleScroll(window.scrollY);\n * });\n * ```\n */\nexport function injectThrottledCallback<TFn extends AnyFunction>(\n fn: TFn,\n options: ThrottlerOptions<TFn>,\n): (...args: Parameters<TFn>) => void {\n const throttler = injectThrottler(fn, options)\n return (...args: Parameters<TFn>) => throttler.maybeExecute(...args)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,wBACd,IACA,SACoC;CACpC,MAAM,YAAY,gBAAgB,IAAI,OAAO;CAC7C,QAAQ,GAAG,SAA0B,UAAU,aAAa,GAAG,IAAI;AACrE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectThrottledSignal.cjs","names":["injectThrottler"],"sources":["../../src/throttler/injectThrottledSignal.ts"],"sourcesContent":["import { signal } from '@angular/core'\nimport { injectThrottler } from './injectThrottler'\nimport type { AngularThrottler } from './injectThrottler'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\nexport interface ThrottledSignal<TValue, TSelected = {}> {\n (): TValue\n set: Setter<TValue>\n throttler: AngularThrottler<Setter<TValue>, TSelected>\n}\n\n/**\n * An Angular function that creates a throttled state signal, combining Angular's signal with throttling functionality.\n * This function provides both the current throttled value and methods to update it.\n *\n * The state value is updated at most once within the specified wait time.\n * This is useful for handling frequent state updates that should be rate-limited, like scroll positions\n * or mouse movements.\n *\n * The function returns a callable object:\n * - `throttled()`: Get the current throttled value\n * - `throttled.set(...)`: Set or update the throttled value (throttled via maybeExecute)\n * - `throttled.throttler`: The throttler instance with additional control methods and state signals\n *\n * ## State Management and Selector\n *\n * The function 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 signal 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 updates and gives you\n * full control over when your component tracks state changes.\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 execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```ts\n * const throttledScrollY = injectThrottledSignal(0, { wait: 100 })\n *\n * // Get value\n * console.log(throttledScrollY())\n *\n * // Set/update value (throttled)\n * throttledScrollY.set(window.scrollY)\n *\n * // Access throttler\n * console.log(throttledScrollY.throttler.state().isPending)\n * ```\n */\nexport function injectThrottledSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected> {\n const throttledValue = signal<TValue>(value)\n\n const throttler = injectThrottler(\n (newValue: TValue | ((prev: TValue) => TValue)) => {\n if (typeof newValue === 'function') {\n throttledValue.update(newValue as (prev: TValue) => TValue)\n } else {\n throttledValue.set(newValue)\n }\n },\n initialOptions,\n selector,\n )\n\n const set: Setter<TValue> = (\n newValue: TValue | ((prev: TValue) => TValue),\n ) => {\n throttler.maybeExecute(newValue)\n }\n\n const throttled = Object.assign(() => throttledValue(), {\n set,\n throttler,\n }) as ThrottledSignal<TValue, TSelected>\n\n return throttled\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,sBACd,OACA,gBACA,UACoC;CACpC,MAAM,
|
|
1
|
+
{"version":3,"file":"injectThrottledSignal.cjs","names":["signal","injectThrottler"],"sources":["../../src/throttler/injectThrottledSignal.ts"],"sourcesContent":["import { signal } from '@angular/core'\nimport { injectThrottler } from './injectThrottler'\nimport type { AngularThrottler } from './injectThrottler'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\nexport interface ThrottledSignal<TValue, TSelected = {}> {\n (): TValue\n set: Setter<TValue>\n throttler: AngularThrottler<Setter<TValue>, TSelected>\n}\n\n/**\n * An Angular function that creates a throttled state signal, combining Angular's signal with throttling functionality.\n * This function provides both the current throttled value and methods to update it.\n *\n * The state value is updated at most once within the specified wait time.\n * This is useful for handling frequent state updates that should be rate-limited, like scroll positions\n * or mouse movements.\n *\n * The function returns a callable object:\n * - `throttled()`: Get the current throttled value\n * - `throttled.set(...)`: Set or update the throttled value (throttled via maybeExecute)\n * - `throttled.throttler`: The throttler instance with additional control methods and state signals\n *\n * ## State Management and Selector\n *\n * The function 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 signal 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 updates and gives you\n * full control over when your component tracks state changes.\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 execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```ts\n * const throttledScrollY = injectThrottledSignal(0, { wait: 100 })\n *\n * // Get value\n * console.log(throttledScrollY())\n *\n * // Set/update value (throttled)\n * throttledScrollY.set(window.scrollY)\n *\n * // Access throttler\n * console.log(throttledScrollY.throttler.state().isPending)\n * ```\n */\nexport function injectThrottledSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected> {\n const throttledValue = signal<TValue>(value)\n\n const throttler = injectThrottler(\n (newValue: TValue | ((prev: TValue) => TValue)) => {\n if (typeof newValue === 'function') {\n throttledValue.update(newValue as (prev: TValue) => TValue)\n } else {\n throttledValue.set(newValue)\n }\n },\n initialOptions,\n selector,\n )\n\n const set: Setter<TValue> = (\n newValue: TValue | ((prev: TValue) => TValue),\n ) => {\n throttler.maybeExecute(newValue)\n }\n\n const throttled = Object.assign(() => throttledValue(), {\n set,\n throttler,\n }) as ThrottledSignal<TValue, TSelected>\n\n return throttled\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,sBACd,OACA,gBACA,UACoC;CACpC,MAAM,qBAAiBA,sBAAe,KAAK;CAE3C,MAAM,YAAYC,yCACf,aAAkD;EACjD,IAAI,OAAO,aAAa,YACtB,eAAe,OAAO,QAAoC;OAE1D,eAAe,IAAI,QAAQ;CAE/B,GACA,gBACA,QACF;CAEA,MAAM,OACJ,aACG;EACH,UAAU,aAAa,QAAQ;CACjC;CAOA,OALkB,OAAO,aAAa,eAAe,GAAG;EACtD;EACA;CACF,CAEe;AACjB"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AngularThrottler } from "./injectThrottler.cjs";
|
|
2
2
|
import { ThrottlerOptions, ThrottlerState } from "@tanstack/pacer/throttler";
|
|
3
|
-
|
|
4
3
|
//#region src/throttler/injectThrottledSignal.d.ts
|
|
5
4
|
type Setter<T> = (value: T | ((prev: T) => T)) => void;
|
|
6
5
|
interface ThrottledSignal<TValue, TSelected = {}> {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AngularThrottler } from "./injectThrottler.js";
|
|
2
2
|
import { ThrottlerOptions, ThrottlerState } from "@tanstack/pacer/throttler";
|
|
3
|
-
|
|
4
3
|
//#region src/throttler/injectThrottledSignal.d.ts
|
|
5
4
|
type Setter<T> = (value: T | ((prev: T) => T)) => void;
|
|
6
5
|
interface ThrottledSignal<TValue, TSelected = {}> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectThrottledSignal.js","names":[],"sources":["../../src/throttler/injectThrottledSignal.ts"],"sourcesContent":["import { signal } from '@angular/core'\nimport { injectThrottler } from './injectThrottler'\nimport type { AngularThrottler } from './injectThrottler'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\nexport interface ThrottledSignal<TValue, TSelected = {}> {\n (): TValue\n set: Setter<TValue>\n throttler: AngularThrottler<Setter<TValue>, TSelected>\n}\n\n/**\n * An Angular function that creates a throttled state signal, combining Angular's signal with throttling functionality.\n * This function provides both the current throttled value and methods to update it.\n *\n * The state value is updated at most once within the specified wait time.\n * This is useful for handling frequent state updates that should be rate-limited, like scroll positions\n * or mouse movements.\n *\n * The function returns a callable object:\n * - `throttled()`: Get the current throttled value\n * - `throttled.set(...)`: Set or update the throttled value (throttled via maybeExecute)\n * - `throttled.throttler`: The throttler instance with additional control methods and state signals\n *\n * ## State Management and Selector\n *\n * The function 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 signal 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 updates and gives you\n * full control over when your component tracks state changes.\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 execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```ts\n * const throttledScrollY = injectThrottledSignal(0, { wait: 100 })\n *\n * // Get value\n * console.log(throttledScrollY())\n *\n * // Set/update value (throttled)\n * throttledScrollY.set(window.scrollY)\n *\n * // Access throttler\n * console.log(throttledScrollY.throttler.state().isPending)\n * ```\n */\nexport function injectThrottledSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected> {\n const throttledValue = signal<TValue>(value)\n\n const throttler = injectThrottler(\n (newValue: TValue | ((prev: TValue) => TValue)) => {\n if (typeof newValue === 'function') {\n throttledValue.update(newValue as (prev: TValue) => TValue)\n } else {\n throttledValue.set(newValue)\n }\n },\n initialOptions,\n selector,\n )\n\n const set: Setter<TValue> = (\n newValue: TValue | ((prev: TValue) => TValue),\n ) => {\n throttler.maybeExecute(newValue)\n }\n\n const throttled = Object.assign(() => throttledValue(), {\n set,\n throttler,\n }) as ThrottledSignal<TValue, TSelected>\n\n return throttled\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,sBACd,OACA,gBACA,UACoC;CACpC,MAAM,iBAAiB,OAAe,
|
|
1
|
+
{"version":3,"file":"injectThrottledSignal.js","names":[],"sources":["../../src/throttler/injectThrottledSignal.ts"],"sourcesContent":["import { signal } from '@angular/core'\nimport { injectThrottler } from './injectThrottler'\nimport type { AngularThrottler } from './injectThrottler'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\ntype Setter<T> = (value: T | ((prev: T) => T)) => void\n\nexport interface ThrottledSignal<TValue, TSelected = {}> {\n (): TValue\n set: Setter<TValue>\n throttler: AngularThrottler<Setter<TValue>, TSelected>\n}\n\n/**\n * An Angular function that creates a throttled state signal, combining Angular's signal with throttling functionality.\n * This function provides both the current throttled value and methods to update it.\n *\n * The state value is updated at most once within the specified wait time.\n * This is useful for handling frequent state updates that should be rate-limited, like scroll positions\n * or mouse movements.\n *\n * The function returns a callable object:\n * - `throttled()`: Get the current throttled value\n * - `throttled.set(...)`: Set or update the throttled value (throttled via maybeExecute)\n * - `throttled.throttler`: The throttler instance with additional control methods and state signals\n *\n * ## State Management and Selector\n *\n * The function 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 signal 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 updates and gives you\n * full control over when your component tracks state changes.\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 execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```ts\n * const throttledScrollY = injectThrottledSignal(0, { wait: 100 })\n *\n * // Get value\n * console.log(throttledScrollY())\n *\n * // Set/update value (throttled)\n * throttledScrollY.set(window.scrollY)\n *\n * // Access throttler\n * console.log(throttledScrollY.throttler.state().isPending)\n * ```\n */\nexport function injectThrottledSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): ThrottledSignal<TValue, TSelected> {\n const throttledValue = signal<TValue>(value)\n\n const throttler = injectThrottler(\n (newValue: TValue | ((prev: TValue) => TValue)) => {\n if (typeof newValue === 'function') {\n throttledValue.update(newValue as (prev: TValue) => TValue)\n } else {\n throttledValue.set(newValue)\n }\n },\n initialOptions,\n selector,\n )\n\n const set: Setter<TValue> = (\n newValue: TValue | ((prev: TValue) => TValue),\n ) => {\n throttler.maybeExecute(newValue)\n }\n\n const throttled = Object.assign(() => throttledValue(), {\n set,\n throttler,\n }) as ThrottledSignal<TValue, TSelected>\n\n return throttled\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,sBACd,OACA,gBACA,UACoC;CACpC,MAAM,iBAAiB,OAAe,KAAK;CAE3C,MAAM,YAAY,iBACf,aAAkD;EACjD,IAAI,OAAO,aAAa,YACtB,eAAe,OAAO,QAAoC;OAE1D,eAAe,IAAI,QAAQ;CAE/B,GACA,gBACA,QACF;CAEA,MAAM,OACJ,aACG;EACH,UAAU,aAAa,QAAQ;CACjC;CAOA,OALkB,OAAO,aAAa,eAAe,GAAG;EACtD;EACA;CACF,CAEe;AACjB"}
|