Skip to content

Commit 54d2c21

Browse files
feat: new onUnmount option (#158)
* feat: new onUnmount option * ci: apply automated fixes * make onUnmount a framework specific option * clean up code * auto abort in async utils * make angular unmount behavior consistent * fix changeset --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 50846fa commit 54d2c21

File tree

261 files changed

+4621
-649
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

261 files changed

+4621
-649
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@tanstack/pacer': minor
3+
'@tanstack/react-pacer': minor
4+
'@tanstack/preact-pacer': minor
5+
'@tanstack/solid-pacer': minor
6+
'@tanstack/angular-pacer': minor
7+
---
8+
9+
feat: Add optional `onUnmount` callback to Debouncer, Throttler, Batcher, Queuer and async variants for custom cleanup.

docs/config.json

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,14 @@
207207
{
208208
"label": "react",
209209
"children": [
210+
{
211+
"label": "ReactDebouncerOptions",
212+
"to": "framework/react/reference/interfaces/ReactDebouncerOptions"
213+
},
214+
{
215+
"label": "ReactAsyncDebouncerOptions",
216+
"to": "framework/react/reference/interfaces/ReactAsyncDebouncerOptions"
217+
},
210218
{
211219
"label": "ReactDebouncer",
212220
"to": "framework/react/reference/interfaces/ReactDebouncer"
@@ -244,6 +252,14 @@
244252
{
245253
"label": "solid",
246254
"children": [
255+
{
256+
"label": "SolidDebouncerOptions",
257+
"to": "framework/solid/reference/interfaces/SolidDebouncerOptions"
258+
},
259+
{
260+
"label": "SolidAsyncDebouncerOptions",
261+
"to": "framework/solid/reference/interfaces/SolidAsyncDebouncerOptions"
262+
},
247263
{
248264
"label": "SolidDebouncer",
249265
"to": "framework/solid/reference/interfaces/SolidDebouncer"
@@ -273,6 +289,14 @@
273289
{
274290
"label": "preact",
275291
"children": [
292+
{
293+
"label": "PreactDebouncerOptions",
294+
"to": "framework/preact/reference/interfaces/PreactDebouncerOptions"
295+
},
296+
{
297+
"label": "PreactAsyncDebouncerOptions",
298+
"to": "framework/preact/reference/interfaces/PreactAsyncDebouncerOptions"
299+
},
276300
{
277301
"label": "PreactDebouncer",
278302
"to": "framework/preact/reference/interfaces/PreactDebouncer"
@@ -310,6 +334,14 @@
310334
{
311335
"label": "angular",
312336
"children": [
337+
{
338+
"label": "AngularDebouncerOptions",
339+
"to": "framework/angular/reference/interfaces/AngularDebouncerOptions"
340+
},
341+
{
342+
"label": "AngularAsyncDebouncerOptions",
343+
"to": "framework/angular/reference/interfaces/AngularAsyncDebouncerOptions"
344+
},
313345
{
314346
"label": "AngularDebouncer",
315347
"to": "framework/angular/reference/interfaces/AngularDebouncer"
@@ -388,6 +420,14 @@
388420
{
389421
"label": "react",
390422
"children": [
423+
{
424+
"label": "ReactThrottlerOptions",
425+
"to": "framework/react/reference/interfaces/ReactThrottlerOptions"
426+
},
427+
{
428+
"label": "ReactAsyncThrottlerOptions",
429+
"to": "framework/react/reference/interfaces/ReactAsyncThrottlerOptions"
430+
},
391431
{
392432
"label": "ReactThrottler",
393433
"to": "framework/react/reference/interfaces/ReactThrottler"
@@ -425,6 +465,14 @@
425465
{
426466
"label": "solid",
427467
"children": [
468+
{
469+
"label": "SolidThrottlerOptions",
470+
"to": "framework/solid/reference/interfaces/SolidThrottlerOptions"
471+
},
472+
{
473+
"label": "SolidAsyncThrottlerOptions",
474+
"to": "framework/solid/reference/interfaces/SolidAsyncThrottlerOptions"
475+
},
428476
{
429477
"label": "SolidThrottler",
430478
"to": "framework/solid/reference/interfaces/SolidThrottler"
@@ -454,6 +502,14 @@
454502
{
455503
"label": "preact",
456504
"children": [
505+
{
506+
"label": "PreactThrottlerOptions",
507+
"to": "framework/preact/reference/interfaces/PreactThrottlerOptions"
508+
},
509+
{
510+
"label": "PreactAsyncThrottlerOptions",
511+
"to": "framework/preact/reference/interfaces/PreactAsyncThrottlerOptions"
512+
},
457513
{
458514
"label": "PreactThrottler",
459515
"to": "framework/preact/reference/interfaces/PreactThrottler"
@@ -491,6 +547,14 @@
491547
{
492548
"label": "angular",
493549
"children": [
550+
{
551+
"label": "AngularThrottlerOptions",
552+
"to": "framework/angular/reference/interfaces/AngularThrottlerOptions"
553+
},
554+
{
555+
"label": "AngularAsyncThrottlerOptions",
556+
"to": "framework/angular/reference/interfaces/AngularAsyncThrottlerOptions"
557+
},
494558
{
495559
"label": "AngularThrottler",
496560
"to": "framework/angular/reference/interfaces/AngularThrottler"
@@ -672,6 +736,14 @@
672736
{
673737
"label": "angular",
674738
"children": [
739+
{
740+
"label": "AngularRateLimiterOptions",
741+
"to": "framework/angular/reference/interfaces/AngularRateLimiterOptions"
742+
},
743+
{
744+
"label": "AngularAsyncRateLimiterOptions",
745+
"to": "framework/angular/reference/interfaces/AngularAsyncRateLimiterOptions"
746+
},
675747
{
676748
"label": "AngularRateLimiter",
677749
"to": "framework/angular/reference/interfaces/AngularRateLimiter"
@@ -750,6 +822,14 @@
750822
{
751823
"label": "react",
752824
"children": [
825+
{
826+
"label": "ReactQueuerOptions",
827+
"to": "framework/react/reference/interfaces/ReactQueuerOptions"
828+
},
829+
{
830+
"label": "ReactAsyncQueuerOptions",
831+
"to": "framework/react/reference/interfaces/ReactAsyncQueuerOptions"
832+
},
753833
{
754834
"label": "ReactQueuer",
755835
"to": "framework/react/reference/interfaces/ReactQueuer"
@@ -783,6 +863,14 @@
783863
{
784864
"label": "solid",
785865
"children": [
866+
{
867+
"label": "SolidQueuerOptions",
868+
"to": "framework/solid/reference/interfaces/SolidQueuerOptions"
869+
},
870+
{
871+
"label": "SolidAsyncQueuerOptions",
872+
"to": "framework/solid/reference/interfaces/SolidAsyncQueuerOptions"
873+
},
786874
{
787875
"label": "SolidQueuer",
788876
"to": "framework/solid/reference/interfaces/SolidQueuer"
@@ -808,6 +896,14 @@
808896
{
809897
"label": "preact",
810898
"children": [
899+
{
900+
"label": "PreactQueuerOptions",
901+
"to": "framework/preact/reference/interfaces/PreactQueuerOptions"
902+
},
903+
{
904+
"label": "PreactAsyncQueuerOptions",
905+
"to": "framework/preact/reference/interfaces/PreactAsyncQueuerOptions"
906+
},
811907
{
812908
"label": "PreactQueuer",
813909
"to": "framework/preact/reference/interfaces/PreactQueuer"
@@ -841,6 +937,14 @@
841937
{
842938
"label": "angular",
843939
"children": [
940+
{
941+
"label": "AngularQueuerOptions",
942+
"to": "framework/angular/reference/interfaces/AngularQueuerOptions"
943+
},
944+
{
945+
"label": "AngularAsyncQueuerOptions",
946+
"to": "framework/angular/reference/interfaces/AngularAsyncQueuerOptions"
947+
},
844948
{
845949
"label": "AngularQueuer",
846950
"to": "framework/angular/reference/interfaces/AngularQueuer"
@@ -915,6 +1019,14 @@
9151019
{
9161020
"label": "react",
9171021
"children": [
1022+
{
1023+
"label": "ReactBatcherOptions",
1024+
"to": "framework/react/reference/interfaces/ReactBatcherOptions"
1025+
},
1026+
{
1027+
"label": "ReactAsyncBatcherOptions",
1028+
"to": "framework/react/reference/interfaces/ReactAsyncBatcherOptions"
1029+
},
9181030
{
9191031
"label": "ReactBatcher",
9201032
"to": "framework/react/reference/interfaces/ReactBatcher"
@@ -944,6 +1056,14 @@
9441056
{
9451057
"label": "solid",
9461058
"children": [
1059+
{
1060+
"label": "SolidBatcherOptions",
1061+
"to": "framework/solid/reference/interfaces/SolidBatcherOptions"
1062+
},
1063+
{
1064+
"label": "SolidAsyncBatcherOptions",
1065+
"to": "framework/solid/reference/interfaces/SolidAsyncBatcherOptions"
1066+
},
9471067
{
9481068
"label": "SolidBatcher",
9491069
"to": "framework/solid/reference/interfaces/SolidBatcher"
@@ -965,6 +1085,14 @@
9651085
{
9661086
"label": "preact",
9671087
"children": [
1088+
{
1089+
"label": "PreactBatcherOptions",
1090+
"to": "framework/preact/reference/interfaces/PreactBatcherOptions"
1091+
},
1092+
{
1093+
"label": "PreactAsyncBatcherOptions",
1094+
"to": "framework/preact/reference/interfaces/PreactAsyncBatcherOptions"
1095+
},
9681096
{
9691097
"label": "PreactBatcher",
9701098
"to": "framework/preact/reference/interfaces/PreactBatcher"
@@ -994,6 +1122,14 @@
9941122
{
9951123
"label": "angular",
9961124
"children": [
1125+
{
1126+
"label": "AngularBatcherOptions",
1127+
"to": "framework/angular/reference/interfaces/AngularBatcherOptions"
1128+
},
1129+
{
1130+
"label": "AngularAsyncBatcherOptions",
1131+
"to": "framework/angular/reference/interfaces/AngularAsyncBatcherOptions"
1132+
},
9971133
{
9981134
"label": "AngularBatcher",
9991135
"to": "framework/angular/reference/interfaces/AngularBatcher"

docs/framework/angular/reference/functions/injectAsyncBatcher.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function injectAsyncBatcher<TValue, TSelected>(
1212
selector): AngularAsyncBatcher<TValue, TSelected>;
1313
```
1414

15-
Defined in: [async-batcher/injectAsyncBatcher.ts:69](https://github.com/TanStack/pacer/blob/main/packages/angular-pacer/src/async-batcher/injectAsyncBatcher.ts#L69)
15+
Defined in: [async-batcher/injectAsyncBatcher.ts:96](https://github.com/TanStack/pacer/blob/main/packages/angular-pacer/src/async-batcher/injectAsyncBatcher.ts#L96)
1616

1717
An Angular function that creates and manages an AsyncBatcher instance.
1818

@@ -32,6 +32,20 @@ optimizing performance by preventing unnecessary updates when irrelevant state c
3232
tracking by providing a selector function. This prevents unnecessary updates and gives you
3333
full control over when your component tracks state changes.
3434

35+
## Cleanup on Destroy
36+
37+
By default, the function cancels any pending batch and aborts in-flight work when the component is destroyed.
38+
Use the `onUnmount` option to customize this. For example, to flush pending work instead:
39+
40+
```ts
41+
const batcher = injectAsyncBatcher(fn, {
42+
maxSize: 10,
43+
onUnmount: (b) => b.flush()
44+
});
45+
```
46+
47+
When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
48+
3549
## Type Parameters
3650

3751
### TValue
@@ -51,7 +65,7 @@ full control over when your component tracks state changes.
5165

5266
### options
5367

54-
`AsyncBatcherOptions`\<`TValue`\> = `{}`
68+
[`AngularAsyncBatcherOptions`](../interfaces/AngularAsyncBatcherOptions.md)\<`TValue`, `TSelected`\> = `{}`
5569

5670
### selector
5771

docs/framework/angular/reference/functions/injectAsyncDebouncer.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function injectAsyncDebouncer<TFn, TSelected>(
1212
selector): AngularAsyncDebouncer<TFn, TSelected>;
1313
```
1414

15-
Defined in: [async-debouncer/injectAsyncDebouncer.ts:92](https://github.com/TanStack/pacer/blob/main/packages/angular-pacer/src/async-debouncer/injectAsyncDebouncer.ts#L92)
15+
Defined in: [async-debouncer/injectAsyncDebouncer.ts:119](https://github.com/TanStack/pacer/blob/main/packages/angular-pacer/src/async-debouncer/injectAsyncDebouncer.ts#L119)
1616

1717
An Angular function that creates and manages an AsyncDebouncer instance.
1818

@@ -47,6 +47,20 @@ Available state properties:
4747
- `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing' | 'settled')
4848
- `successCount`: Number of function executions that have completed successfully
4949

50+
## Cleanup on Destroy
51+
52+
By default, the function cancels any pending execution and aborts in-flight work when the component is destroyed.
53+
Use the `onUnmount` option to customize this. For example, to flush pending work instead:
54+
55+
```ts
56+
const debouncer = injectAsyncDebouncer(fn, {
57+
wait: 500,
58+
onUnmount: (d) => d.flush()
59+
});
60+
```
61+
62+
When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
63+
5064
## Type Parameters
5165

5266
### TFn
@@ -66,7 +80,7 @@ Available state properties:
6680

6781
### options
6882

69-
`AsyncDebouncerOptions`\<`TFn`\>
83+
[`AngularAsyncDebouncerOptions`](../interfaces/AngularAsyncDebouncerOptions.md)\<`TFn`, `TSelected`\>
7084

7185
### selector
7286

docs/framework/angular/reference/functions/injectAsyncQueuer.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function injectAsyncQueuer<TValue, TSelected>(
1212
selector): AngularAsyncQueuer<TValue, TSelected>;
1313
```
1414

15-
Defined in: [async-queuer/injectAsyncQueuer.ts:69](https://github.com/TanStack/pacer/blob/main/packages/angular-pacer/src/async-queuer/injectAsyncQueuer.ts#L69)
15+
Defined in: [async-queuer/injectAsyncQueuer.ts:96](https://github.com/TanStack/pacer/blob/main/packages/angular-pacer/src/async-queuer/injectAsyncQueuer.ts#L96)
1616

1717
An Angular function that creates and manages an AsyncQueuer instance.
1818

@@ -32,6 +32,20 @@ optimizing performance by preventing unnecessary updates when irrelevant state c
3232
tracking by providing a selector function. This prevents unnecessary updates and gives you
3333
full control over when your component tracks state changes.
3434

35+
## Cleanup on Destroy
36+
37+
By default, the function stops the queuer and aborts in-flight work when the component is destroyed.
38+
Use the `onUnmount` option to customize this. For example, to flush pending items instead:
39+
40+
```ts
41+
const queuer = injectAsyncQueuer(fn, {
42+
concurrency: 2,
43+
onUnmount: (q) => q.flush()
44+
});
45+
```
46+
47+
When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
48+
3549
## Type Parameters
3650

3751
### TValue
@@ -51,7 +65,7 @@ full control over when your component tracks state changes.
5165

5266
### options
5367

54-
`AsyncQueuerOptions`\<`TValue`\> = `{}`
68+
[`AngularAsyncQueuerOptions`](../interfaces/AngularAsyncQueuerOptions.md)\<`TValue`, `TSelected`\> = `{}`
5569

5670
### selector
5771

0 commit comments

Comments
 (0)