Open History to see the last commit
1---
2id: SubscribeChangesOptions
3title: SubscribeChangesOptions
4---
5
6Defined in: [packages/db/src/types.ts:1207](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L1207)
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:1238](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L1238)
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:1212](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L1212)
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:1260](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L1260)
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:1268](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L1268)
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:1266](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L1266)
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:1250](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L1250)
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:1255](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L1255)
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:1244](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L1244)
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:1270](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L1270)
176
177**`Internal`**
178
179Lets a live-query graph retain its last publication during replay.
180
181#### fail()?
182
183```ts
184readonly optional fail: (error) => void;
185```
186
187The replay could not load every active demand again.
188
189##### Parameters
190
191###### error
192
193`Error`
194
195##### Returns
196
197`void`
198
199#### holdsDemand()?
200
201```ts
202readonly optional holdsDemand: () => boolean;
203```
204
205The live query still holds logical demand.
206
207##### Returns
208
209`boolean`
210
211#### start()
212
213```ts
214readonly start: () => void;
215```
216
217##### Returns
218
219`void`
220
221#### succeed()
222
223```ts
224readonly succeed: () => void;
225```
226
227##### Returns
228
229`void`
230
231***
232
233### where()?
234
235```ts
236optional where: (row) => any;
237```
238
239Defined in: [packages/db/src/types.ts:1227](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L1227)
240
241Callback function for filtering changes using a row proxy.
242The callback receives a proxy object that records property access,
243allowing you to use query builder functions like `eq`, `gt`, etc.
244
245#### Parameters
246
247##### row
248
249`SingleRowRefProxy`\<[`WithVirtualProps`](../type-aliases/WithVirtualProps.md)\<`T`, `TKey`\>, `TKey`, `true`\>
250
251#### Returns
252
253`any`
254
255#### Example
256
257```ts
258import { eq } from "@tanstack/db"
259
260collection.subscribeChanges(callback, {
261 where: (row) => eq(row.status, "active")
262})
263```
264
265***
266
267### whereExpression?
268
269```ts
270optional whereExpression: BasicExpression<boolean>;
271```
272
273Defined in: [packages/db/src/types.ts:1229](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L1229)
274
275Pre-compiled expression for filtering changes