Skip to content
Source
Sign inSign up
TanStack/pacer
Open History to see the last commit

UseRateLimitedValue.md

136 lines3.6 KB

1---
2id: UseRateLimitedValue
3title: UseRateLimitedValue
4---
5​
6Defined in: [packages/ember-pacer/src/rate-limiter/useRateLimitedValue.ts:55](https://github.com/TanStack/pacer/blob/main/packages/ember-pacer/src/rate-limiter/useRateLimitedValue.ts#L55)
7​
8Derives a rate-limited value from its current source.
9​
10Accepts updates while the configured limit has capacity in its fixed or sliding window. Rejected updates are discarded instead of delayed.
11​
12## Return value
13​
14Yields an object with value, setValue, and utility. Read value in the template; utility exposes controls and selected state. Pass the current tracked value as the first positional argument. The initial value is available immediately. Source changes schedule updates on the existing utility.
15​
16## State and ownership
17​
18The value updates independently of the utility selector. The default utility selection is {}. Pass a selector to subscribe to fields such as executionCount, isPending, or status where the underlying utility exposes them.
19​
20Invoke in a Glimmer template. Positional arguments provide the callback or value and optional selector. Named arguments provide options. Removing the invocation runs cleanup.
21Tracked named arguments refresh options after rendering. Local options override provider defaults without replacing the utility or its pending work.
22onUnmount replaces default cleanup and receives the utility instance. A custom callback must perform every needed cancel, stop, or abort action.
23​
24## Example
25​
26```gts
27import { useRateLimitedValue } from '@tanstack/ember-pacer'
28​
29// Inside a component template:
30<template>
31{{#let (useRateLimitedValue @source limit=3 window=1000) as |result|}}
32 <output>{{result.value}}</output>
33{{/let}}
34</template>
35```
36​
37## See
38​
39useRateLimiter
40​
41## Extends
42​
43- `default`\<\{
44 `Args`: \{
45 `Named`: [`EmberRateLimiterOptions`](../interfaces/EmberRateLimiterOptions.md)\<(`value`) => `void`, `TSelected`\>;
46 `Positional`: \[`TValue`\] \| \[`TValue`, (`state`) => `TSelected`\];
47 \};
48 `Return`: [`EmberRateLimitedValue`](../interfaces/EmberRateLimitedValue.md)\<`TValue`, `TSelected`\>;
49\}\>
50​
51## Type Parameters
52​
53### TValue
54​
55`TValue`
56​
57### TSelected
58​
59`TSelected` = \{
60\}
61​
62## Constructors
63​
64### Constructor
65​
66```ts
67new UseRateLimitedValue<TValue, TSelected>(owner?): UseRateLimitedValue;
68```
69​
70Defined in: node\_modules/.pnpm/ember-source@7.3.0\_@glimmer+component@2.1.1\_supports-color@7.2.0\_\_supports-color@7.2.0/node\_modules/ember-source/types/stable/@ember/object/index.d.ts:28
71​
72#### Parameters
73​
74##### owner?
75​
76`Owner`
77​
78#### Returns
79​
80`UseRateLimitedValue`
81​
82#### Inherited from
83​
84```ts
85Helper<{
86 Args: {
87 Positional:
88 | [value: TValue]
89 | [value: TValue, selector: (state: RateLimiterState) => TSelected]
90 Named: EmberRateLimiterOptions<(value: TValue) => void, TSelected>
91 }
92 Return: EmberRateLimitedValue<TValue, TSelected>
93}>.constructor
94```
95​
96## Methods
97​
98### compute()
99​
100```ts
101compute(positional, options): EmberRateLimitedValue<TValue, TSelected>;
102```
103​
104Defined in: [packages/ember-pacer/src/rate-limiter/useRateLimitedValue.ts:73](https://github.com/TanStack/pacer/blob/main/packages/ember-pacer/src/rate-limiter/useRateLimitedValue.ts#L73)
105​
106Override this function when writing a class-based helper.
107​
108#### Parameters
109​
110##### positional
111​
112\[`TValue`, (`state`) => `TSelected`?\]
113​
114The positional arguments to the helper
115​
116##### options
117​
118[`EmberRateLimiterOptions`](../interfaces/EmberRateLimiterOptions.md)\<(`value`) => `void`, `TSelected`\>
119​
120#### Returns
121​
122[`EmberRateLimitedValue`](../interfaces/EmberRateLimitedValue.md)\<`TValue`, `TSelected`\>
123​
124#### Method
125​
126compute
127​
128#### Since
129​
1301.13.0
131​
132#### Overrides
133​
134```ts
135Helper.compute
136```