-
Notifications
You must be signed in to change notification settings - Fork 101
Add mutations guide #614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add mutations guide #614
Conversation
|
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
Size Change: 0 B Total Size: 74.1 kB ℹ️ View Unchanged
|
Size Change: 0 B Total Size: 1.44 kB ℹ️ View Unchanged
|
3f77e7f
to
63e884a
Compare
- Pull mutation off mutations array for cleaner code - Add comment explaining collection handlers only receive one mutation at a time - Apply pattern consistently across all handler examples 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Remove incorrect comment about single mutations - Update handlers to use Promise.all for multiple mutations - Fix collection.refetch() -> collection.utils.refetch() - Update Electric collection pattern to return txids - Add note about automatic refetch in collection handlers 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Parenthesize the offset to ensure negative IDs: -(Math.floor(...) + 1) Previously could produce positive 1 when Math.random() returns 0
Use 'Immer-like pattern' instead of 'uses Immer under the hood'
- Correct handler params to { transaction, collection } - Remove incorrect metadata parameter from signature - Add metadata to mutation object properties list - Fix return type to Promise<any> | any
Replace QueryCollection-specific note with general requirement that handlers must wait for server changes to sync back before resolving
Collection handlers automatically handle refetch, only custom actions need it
- Make mutationFn required (not optional) - Add missing id and metadata options - Mark autoCommit as optional
Note that rollback is automatic on error, manual rollback only needed for user actions like canceling a form
- Replace opening paragraph with bullet points - Remove worked examples, keep truth table only - Remove redundant benefits list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. One thought: will this automatically be added to the Guides section of the left-hand-side nav, or does that need to be configured?
|
||
```tsx | ||
// Intent: "like this post" | ||
const likePost = createOptimisticAction<string>({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth showing how to use this, i.e.:
likePost(postId)
Add new mutations guide consolidating material & docs & examples.
Fixes #547