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

SubscribeChangesOptions.md

152 lines2.8 KB

1---
2id: SubscribeChangesOptions
3title: SubscribeChangesOptions
4---
5​
6# Interface: SubscribeChangesOptions\<T\>
7​
8Defined in: [packages/db/src/types.ts:784](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L784)
9​
10Options for subscribing to collection changes
11​
12## Type Parameters
13​
14### T
15​
16`T` *extends* `object` = `Record`\<`string`, `unknown`\>
17​
18## Properties
19​
20### includeInitialState?
21​
22```ts
23optional includeInitialState: boolean;
24```
25​
26Defined in: [packages/db/src/types.ts:788](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L788)
27​
28Whether to include the current state as initial changes
29​
30***
31​
32### limit?
33​
34```ts
35optional limit: number;
36```
37​
38Defined in: [packages/db/src/types.ts:821](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L821)
39​
40**`Internal`**
41​
42Optional limit to include in loadSubset for query-specific cache keys.
43​
44***
45​
46### onLoadSubsetResult()?
47​
48```ts
49optional onLoadSubsetResult: (result) => void;
50```
51​
52Defined in: [packages/db/src/types.ts:827](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L827)
53​
54**`Internal`**
55​
56Callback that receives the loadSubset result (Promise or true) from requestSnapshot.
57Allows the caller to directly track the loading promise for isReady status.
58​
59#### Parameters
60​
61##### result
62​
63`true` | `Promise`\<`void`\>
64​
65#### Returns
66​
67`void`
68​
69***
70​
71### onStatusChange()?
72​
73```ts
74optional onStatusChange: (event) => void;
75```
76​
77Defined in: [packages/db/src/types.ts:811](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L811)
78​
79**`Internal`**
80​
81Listener for subscription status changes.
82Registered BEFORE any snapshot is requested, ensuring no status transitions are missed.
83​
84#### Parameters
85​
86##### event
87​
88[`SubscriptionStatusChangeEvent`](SubscriptionStatusChangeEvent.md)
89​
90#### Returns
91​
92`void`
93​
94***
95​
96### orderBy?
97​
98```ts
99optional orderBy: OrderBy;
100```
101​
102Defined in: [packages/db/src/types.ts:816](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L816)
103​
104**`Internal`**
105​
106Optional orderBy to include in loadSubset for query-specific cache keys.
107​
108***
109​
110### where()?
111​
112```ts
113optional where: (row) => any;
114```
115​
116Defined in: [packages/db/src/types.ts:803](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L803)
117​
118Callback function for filtering changes using a row proxy.
119The callback receives a proxy object that records property access,
120allowing you to use query builder functions like `eq`, `gt`, etc.
121​
122#### Parameters
123​
124##### row
125​
126`SingleRowRefProxy`\<`T`\>
127​
128#### Returns
129​
130`any`
131​
132#### Example
133​
134```ts
135import { eq } from "@tanstack/db"
136​
137collection.subscribeChanges(callback, {
138 where: (row) => eq(row.status, "active")
139})
140```
141​
142***
143​
144### whereExpression?
145​
146```ts
147optional whereExpression: BasicExpression<boolean>;
148```
149​
150Defined in: [packages/db/src/types.ts:805](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L805)
151​
152Pre-compiled expression for filtering changes