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

BaseStrategy.md

96 lines2.0 KB

1---
2id: BaseStrategy
3title: BaseStrategy
4---
5​
6Defined in: [packages/db/src/strategies/types.ts:6](https://github.com/TanStack/db/blob/main/packages/db/src/strategies/types.ts#L6)
7​
8Base strategy interface that all strategy implementations must conform to
9​
10## Extended by
11​
12- [`DebounceStrategy`](DebounceStrategy.md)
13- [`QueueStrategy`](QueueStrategy.md)
14- [`ThrottleStrategy`](ThrottleStrategy.md)
15​
16## Type Parameters
17​
18### TName
19​
20`TName` *extends* `string` = `string`
21​
22## Properties
23​
24### \_type
25​
26```ts
27_type: TName;
28```
29​
30Defined in: [packages/db/src/strategies/types.ts:8](https://github.com/TanStack/db/blob/main/packages/db/src/strategies/types.ts#L8)
31​
32Type discriminator for strategy identification
33​
34***
35​
36### cleanup()
37​
38```ts
39cleanup: () => void;
40```
41​
42Defined in: [packages/db/src/strategies/types.ts:30](https://github.com/TanStack/db/blob/main/packages/db/src/strategies/types.ts#L30)
43​
44Clean up any resources held by the strategy
45Should be called when the strategy is no longer needed
46​
47#### Returns
48​
49`void`
50​
51***
52​
53### execute()
54​
55```ts
56execute: <T>(fn, onAdmit?, onCommit?) => boolean | void | Promise<void>;
57```
58​
59Defined in: [packages/db/src/strategies/types.ts:20](https://github.com/TanStack/db/blob/main/packages/db/src/strategies/types.ts#L20)
60​
61Execute a function according to the strategy's timing rules
62​
63#### Type Parameters
64​
65##### T
66​
67`T` *extends* `object` = `Record`\<`string`, `unknown`\>
68​
69#### Parameters
70​
71##### fn
72​
73() => [`Transaction`](Transaction.md)\<`T`\>
74​
75The function to execute
76​
77##### onAdmit?
78​
79() => `void` \| [`Transaction`](Transaction.md)\<`T`\>
80​
81Optional synchronous preparation for an admitted call.
82Built-in debounce/throttle strategies call it after reserving the current
83edge but before invoking fn, and do not call it when returning false.
84​
85##### onCommit?
86​
87() => `Promise`\<`unknown`\> \| `undefined`
88​
89Optional promise for the actual commit attempt. It can
90outlive the public persistence receipt after a manual rollback.
91​
92#### Returns
93​
94`boolean` \| `void` \| `Promise`\<`void`\>
95​
96The result of the function execution (if applicable)