-
Notifications
You must be signed in to change notification settings - Fork 55
localOnlyCollectionOptions collection for ephemeral local state #204
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
localOnlyCollectionOptions collection for ephemeral local state #204
Conversation
🦋 Changeset detectedLatest commit: 72c3e17 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 |
@tanstack/db-example-react-todo
commit: |
Size Change: 0 B Total Size: 29.2 kB ℹ️ View Unchanged
|
Size Change: 0 B Total Size: 561 B ℹ️ View Unchanged
|
Implement true loopback sync for local-only collections Add initial data support for local-only collections Refactor local-only collection with optimistic updates and custom callbacks Checkpoint before follow-up message Update local-only sync to support custom key types Update local-only collection tests with extended generic types Refactor local-only sync function signature for improved readability Add explicit key type parameter to localOnlyCollectionOptions Checkpoint before follow-up message Checkpoint before follow-up message Add localOnly collection type for in-memory collections Add localOnly collection type for in-memory collections Refactor local-only collection handlers to call user handlers before confirming transactions fix changeset
36bd9c4
to
7b2d15b
Compare
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.
Love it!
Co-authored-by: Cursor Agent <[email protected]>
Stacked on #230 - merge that first!
This just loops back on the sync interface applying all changes immediately.
There is a failing tests, I'm suspicious it is exposing something else going on that we need to look at.(edit: fixed in #230)A
localOnly
collection type was implemented in@tanstack/db-collections
.Key changes include:
packages/db-collections/src/local-only.ts
was created, exportinglocalOnlyCollectionOptions
and related types.localOnlyCollectionOptions
function now configures an in-memory collection with a "loopback" sync.createLocalOnlySync
function captures the collection's internalbegin
,write
, andcommit
functions.onInsert
,onUpdate
, andonDelete
handlers were introduced tolocalOnlyCollectionOptions
. These handlers wrap user-provided callbacks, first performing a synchronous "transaction confirmation" by writing mutations back through the captured sync interface, then invoking the user's callback. This ensures optimistic changes are immediately reflected.initialData
array was added toLocalOnlyCollectionConfig
, allowing the collection to be pre-populated during its initial sync.getKey
was refined acrossLocalOnlyCollectionConfig
,localOnlyCollectionOptions
, andcreateLocalOnlySync
to correctly propagate specific key types (e.g.,number
instead ofstring | number
).packages/db-collections/tests/local-only.test-d.ts
file was added to verify type compatibility withcreateCollection
.async
) were resolved.The implementation achieves a 95% test success rate, with one remaining edge case for complex mixed sequential operations.