Open History to see the last commit
1---
2id: SubscribeChangesOptions
3title: SubscribeChangesOptions
4---
5
6Defined in: [packages/db/src/types.ts:1238](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L1238)
7
8Options for subscribing to collection changes
9
10## Type Parameters
11
12### T
13
14`T` *extends* `object` = `Record`\<`string`, `unknown`\>
15
16### TKey
17
18`TKey` *extends* `string` \| `number` = `string` \| `number`
19
20## Properties
21
22### deferAcquisition?
23
24```ts
25optional deferAcquisition: boolean;
26```
27
28Defined in: [packages/db/src/types.ts:1269](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L1269)
29
30**`Internal`**
31
32Whether this subscription defers provider work. It keeps the Collection
33alive and reads its local rows, but starts no idle source sync run and no
34acquisition attempt until `subscription.resumeDeferredAcquisition()`. A
35live-query Collection defers its source subscriptions until it has a
36subscriber or a preload in its current sync run.
37
38***
39
40### includeInitialState?
41
42```ts
43optional includeInitialState: boolean;
44```
45
46Defined in: [packages/db/src/types.ts:1243](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L1243)
47
48Whether to include the current state as initial changes
49
50***
51
52### limit?
53
54```ts
55optional limit: number;
56```
57
58Defined in: [packages/db/src/types.ts:1291](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L1291)
59
60**`Internal`**
61
62Optional limit to include in loadSubset for query-specific cache keys.
63
64***
65
66### onLoadSubsetError()?
67
68```ts
69optional onLoadSubsetError: (event) => void;
70```
71
72Defined in: [packages/db/src/types.ts:1299](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L1299)
73
74**`Internal`**
75
76Receives subset-load failures scoped to this subscription.
77
78#### Parameters
79
80##### event
81
82[`SubscriptionLoadSubsetErrorEvent`](SubscriptionLoadSubsetErrorEvent.md)
83
84#### Returns
85
86`void`
87
88***
89
90### onLoadSubsetResult()?
91
92```ts
93optional onLoadSubsetResult: (result) => void;
94```
95
96Defined in: [packages/db/src/types.ts:1297](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L1297)
97
98**`Internal`**
99
100Callback that receives the loadSubset result (Promise or true) from requestSnapshot.
101Allows the caller to directly track the loading promise for isReady status.
102
103#### Parameters
104
105##### result
106
107[`LoadSubsetRequestResult`](../type-aliases/LoadSubsetRequestResult.md)
108
109#### Returns
110
111`void`
112
113***
114
115### onStatusChange()?
116
117```ts
118optional onStatusChange: (event) => void;
119```
120
121Defined in: [packages/db/src/types.ts:1281](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L1281)
122
123**`Internal`**
124
125Listener for subscription status changes.
126Registered BEFORE any snapshot is requested, ensuring no status transitions are missed.
127
128#### Parameters
129
130##### event
131
132[`SubscriptionStatusChangeEvent`](SubscriptionStatusChangeEvent.md)
133
134#### Returns
135
136`void`
137
138***
139
140### orderBy?
141
142```ts
143optional orderBy: OrderBy;
144```
145
146Defined in: [packages/db/src/types.ts:1286](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L1286)
147
148**`Internal`**
149
150Optional orderBy to include in loadSubset for query-specific cache keys.
151
152***
153
154### owner?
155
156```ts
157optional owner: CollectionDependent;
158```
159
160Defined in: [packages/db/src/types.ts:1275](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L1275)
161
162**`Internal`**
163
164The live query or Effect this subscription reads for, so
165`collection.subscribers` can name it.
166
167***
168
169### truncateReplayPublication?
170
171```ts
172optional truncateReplayPublication: object;
173```
174
175Defined in: [packages/db/src/types.ts:1301](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L1301)
176
177**`Internal`**
178
179Lets a live-query graph retain its last publication during replay.
180
181#### fail()?
182
183```ts
184readonly optional fail: (errors) => void;
185```
186
187The replay could not load every active demand again: its failures, in failure order.
188
189##### Parameters
190
191###### errors
192
193`Error`[]
194
195##### Returns
196
197`void`
198
199#### siblingReplays()
200
201```ts
202readonly siblingReplays: () => Promise<unknown> | undefined;
203```
204
205The replays of the graph's other subscriptions to this collection that
206still load. They share one barrier, so this replay waits for them.
207
208##### Returns
209
210`Promise`\<`unknown`\> \| `undefined`
211
212#### start()
213
214```ts
215readonly start: (retired) => void;
216```
217
218`retired`: a reload retired the sync run, and no truncate came.
219
220##### Parameters
221
222###### retired
223
224`boolean`
225
226##### Returns
227
228`void`
229
230#### succeed()
231
232```ts
233readonly succeed: () => void;
234```
235
236##### Returns
237
238`void`
239
240***
241
242### where()?
243
244```ts
245optional where: (row) => any;
246```
247
248Defined in: [packages/db/src/types.ts:1258](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L1258)
249
250Callback function for filtering changes using a row proxy.
251The callback receives a proxy object that records property access,
252allowing you to use query builder functions like `eq`, `gt`, etc.
253
254#### Parameters
255
256##### row
257
258`SingleRowRefProxy`\<[`WithVirtualProps`](../type-aliases/WithVirtualProps.md)\<`T`, `TKey`\>, `TKey`, `true`\>
259
260#### Returns
261
262`any`
263
264#### Example
265
266```ts
267import { eq } from "@tanstack/db"
268
269collection.subscribeChanges(callback, {
270 where: (row) => eq(row.status, "active")
271})
272```
273
274***
275
276### whereExpression?
277
278```ts
279optional whereExpression: BasicExpression<boolean>;
280```
281
282Defined in: [packages/db/src/types.ts:1260](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L1260)
283
284Pre-compiled expression for filtering changes