-
Notifications
You must be signed in to change notification settings - Fork 77
feat: improve writeBatch API to use callback pattern #378
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
Conversation
- Changed writeBatch from accepting an array of operations to accepting a callback function - Write operations called within the callback are automatically batched together - This provides a more intuitive API similar to database transactions - Added comprehensive documentation for Query Collections including direct writes feature - Documented meta support feature from PR #363 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
🦋 Changeset detectedLatest commit: 8ce177a The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
More templates
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
Size Change: 0 B Total Size: 58.2 kB ℹ️ View Unchanged
|
- Document how to merge incremental data with existing cache data - Show example of handling additions, updates, and deletions - Explain benefits of this approach vs full refetches 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Size Change: 0 B Total Size: 1.05 kB ℹ️ View Unchanged
|
- Add comprehensive JSDoc comments to QueryCollectionConfig interface - Clarify that direct writes bypass optimistic updates and write to synced data store - Document the two data stores (synced vs optimistic mutations) - Explain what direct write operations do and don't do 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Fix cross-collection contamination by using WeakMap instead of global state - Add proper error handling for async callbacks in writeBatch - Prevent nested writeBatch calls with clear error messages - Preserve type safety in batch context - Change to minor version bump (breaking change) - Add comprehensive tests for edge cases Addresses all feedback from code review to ensure robust batch operations. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Add multiple eslint-disable-next-line directives to suppress warnings for runtime async detection. The callback is typed as () => void but users might pass async functions, so we need runtime validation. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
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.
This looks great, very clear api design. Great update to the docs too
Overview
This PR improves the writeBatch API in @tanstack/query-db-collection by changing it from accepting an array of operations to accepting a callback function. This provides a more intuitive API similar to database transactions.
Changes
API Improvement
writeBatch
to accept a callback function instead of an array of operationsgetActiveTransaction()
in the core DB packageBefore
After
Documentation
Related Issues
🤖 Generated with Claude Code