Skip to content

Commit 266bd29

Browse files
authored
Update inline docs + small fixes (#243)
1 parent 410cc09 commit 266bd29

26 files changed

Lines changed: 3439 additions & 1785 deletions

.changeset/full-chicken-lick.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@tanstack/db-collections": patch
3+
"@tanstack/react-db": patch
4+
"@tanstack/vue-db": patch
5+
"@tanstack/db": patch
6+
---
7+
8+
Improve jsdocs

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Sync data into collections:
5050
```ts
5151
import { createQueryCollection } from "@tanstack/db-collections"
5252

53-
const todoCollection = createQueryCollection<Todo>({
53+
const todoCollection = createQueryCollection({
5454
queryKey: ["todos"],
5555
queryFn: async () => fetch("/api/todos"),
5656
getKey: (item) => item.id,
@@ -62,10 +62,13 @@ Use live queries in your components:
6262

6363
```tsx
6464
import { useLiveQuery } from "@tanstack/react-db"
65+
import { eq } from "@tanstack/db"
6566

6667
const Todos = () => {
6768
const { data: todos } = useLiveQuery((query) =>
68-
query.from({ todoCollection }).where("@completed", "=", false)
69+
query
70+
.from({ todos: todoCollection })
71+
.where(({ todos }) => eq(todos.completed, false))
6972
)
7073

7174
return <List items={todos} />

docs/overview.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,12 @@ You can also use:
163163

164164
#### Collection schemas
165165

166-
All collections optionally support a `schema`.
166+
All collections optionally (though strongly recommended) support adding a `schema`.
167167

168168
If provided, this must be a [Standard Schema](https://standardschema.dev) compatible schema instance, such as a [Zod](https://zod.dev) or [Effect](https://effect.website/docs/schema/introduction/) schema.
169169

170+
The collection will use the schema to do client-side validation of optimistic mutations.
171+
170172
The collection will use the schema for its type so if you provide a schema, you can't also pass in an explicit
171173
type (e.g. `createCollection<Todo>()`).
172174

@@ -639,7 +641,7 @@ import { queryCollectionOptions } from "@tanstack/db-collections"
639641
640642
// Load data into collections using TanStack Query.
641643
// It's common to define these in a `collections` module.
642-
const todoCollection = createCollection<Todo>(queryCollectionOptions({
644+
const todoCollection = createCollection(queryCollectionOptions({
643645
queryKey: ["todos"],
644646
queryFn: async () => fetch("/api/todos"),
645647
getKey: (item) => item.id,
@@ -652,7 +654,7 @@ const todoCollection = createCollection<Todo>(queryCollectionOptions({
652654
}
653655
// also add onUpdate, onDelete as needed.
654656
}))
655-
const listCollection = createCollection<TodoList>(queryCollectionOptions({
657+
const listCollection = createCollection(queryCollectionOptions({
656658
queryKey: ["todo-lists"],
657659
queryFn: async () => fetch("/api/todo-lists"),
658660
getKey: (item) => item.id,
@@ -704,7 +706,7 @@ import type { Collection } from '@tanstack/db'
704706
import type { MutationFn, PendingMutation, createCollection } from '@tanstack/react-db'
705707
import { electricCollectionOptions } from '@tanstack/db-collections'
706708
707-
export const todoCollection = createCollection(electricCollectionOptions<Todo>({
709+
export const todoCollection = createCollection(electricCollectionOptions({
708710
id: 'todos',
709711
schema: todoSchema,
710712
// Electric syncs data using "shapes". These are filtered views

examples/react/todo/CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@
115115
When `collection.insert()`, `.update()`, or `.delete()` are called outside of an explicit transaction (i.e., not within `useOptimisticMutation`), the library now automatically creates a single-operation transaction and invokes the corresponding handler to persist the change.
116116

117117
Key changes:
118-
119118
- **`@tanstack/db`**: The `Collection` class now supports `onInsert`, `onUpdate`, and `onDelete` in its configuration. Direct calls to mutation methods will throw an error if the corresponding handler is not defined.
120119
- **`@tanstack/db-collections`**:
121120
- `queryCollectionOptions` now accepts the new handlers and will automatically `refetch` the collection's query after a handler successfully completes. This behavior can be disabled if the handler returns `{ refetch: false }`.
@@ -127,7 +126,6 @@
127126
***
128127

129128
The documentation and the React Todo example application have been significantly refactored to adopt the new direct persistence handler pattern as the primary way to perform mutations.
130-
131129
- The `README.md` and `docs/overview.md` files have been updated to de-emphasize `useOptimisticMutation` for simple writes. They now showcase the much simpler API of calling `collection.insert()` directly and defining persistence logic in the collection's configuration.
132130
- The React Todo example (`examples/react/todo/src/App.tsx`) has been completely overhauled. All instances of `useOptimisticMutation` have been removed and replaced with the new `onInsert`, `onUpdate`, and `onDelete` handlers, resulting in cleaner and more concise code.
133131

examples/react/todo/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
## How to run
44

55
- Go to the root of the repository and run:
6-
76
- `pnpm install`
87
- `pnpm build`
98

examples/react/todo/package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44
"version": "0.0.23",
55
"dependencies": {
66
"@tanstack/db-collections": "^0.0.21",
7-
"@tanstack/query-core": "^5.75.7",
7+
"@tanstack/query-core": "^5.81.5",
88
"@tanstack/react-db": "^0.0.17",
99
"cors": "^2.8.5",
1010
"drizzle-orm": "^0.40.1",
1111
"drizzle-zod": "^0.7.0",
1212
"express": "^4.19.2",
13-
"postgres": "^3.4.5",
14-
"react": "^19.0.0",
15-
"react-dom": "^19.0.0",
16-
"tailwindcss": "^4.0.17",
17-
"zod": "^3.24.2"
13+
"postgres": "^3.4.7",
14+
"react": "^19.1.0",
15+
"react-dom": "^19.1.0",
16+
"tailwindcss": "^4.1.11"
1817
},
1918
"devDependencies": {
2019
"@eslint/js": "^9.22.0",
@@ -27,8 +26,8 @@
2726
"@types/react-dom": "^19.0.0",
2827
"@typescript-eslint/eslint-plugin": "^8.26.1",
2928
"@typescript-eslint/parser": "^8.26.1",
30-
"@vitejs/plugin-react": "^4.3.4",
31-
"concurrently": "^9.1.2",
29+
"@vitejs/plugin-react": "^4.6.0",
30+
"concurrently": "^9.2.0",
3231
"dotenv": "^16.3.1",
3332
"drizzle-kit": "^0.30.5",
3433
"eslint": "^9.22.0",

examples/react/todo/src/DevTools.tsx

Lines changed: 0 additions & 232 deletions
This file was deleted.

examples/react/todo/src/DiffView.tsx

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)