- Updated dependencies [
e478d53]:- @tanstack/db@0.0.16
-
Add localOnly collection type for in-memory collections with loopback sync. (#204)
-
Updated dependencies [
f5cf44b,f5cf44b]:- @tanstack/db@0.0.15
- Add localStorage collection with cross-tab sync and configurable storage APIs. (#203)
- Updated dependencies [
74c140d]:- @tanstack/db@0.0.14
-
feat: implement Collection Lifecycle Management (#198)
Adds automatic lifecycle management for collections to optimize resource usage.
New Features:
- Added
startSyncoption (defaults tofalse, set totrueto start syncing immediately) - Automatic garbage collection after
gcTime(default 5 minutes) of inactivity - Collection status tracking: "idle" | "loading" | "ready" | "error" | "cleaned-up"
- Manual
preload()andcleanup()methods for lifecycle control
Usage:
const collection = createCollection({ startSync: false, // Enable lazy loading gcTime: 300000, // Cleanup timeout (default: 5 minutes) }) console.log(collection.status) // Current state await collection.preload() // Ensure ready await collection.cleanup() // Manual cleanup
- Added
-
Updated dependencies [
945868e,0f8a008,57b5f5d]:- @tanstack/db@0.0.13
- Validate that the txId passed to awaitTxId is a string of numbers (#193)
-
If a schema is passed, use that for the collection type. (#186)
You now must either pass an explicit type or schema - passing both will conflict.
-
Updated dependencies [
f6abe9b]:- @tanstack/db@0.0.12
-
Export
ElectricCollectionUtils& allow passing generic tocreateTransaction(#179) -
Updated dependencies [
66ed58b,c5489ff]:- @tanstack/db@0.0.11
- Updated dependencies [
38d4505]:- @tanstack/db@0.0.10
- Updated dependencies [
2ae0b09]:- @tanstack/db@0.0.9
-
Type PendingMutation whenever possible (#163)
-
A large refactor of the core
Collectionwith: (#155)- a change to not use Store internally and emit fine grade changes with
subscribeChangesandsubscribeKeyChangesmethods. - changes to the
Collectionapi to be moreMaplike for reads, withget,has,size,entries,keys, andvalues. - renames
config.getIdtoconfig.getKeyfor consistency with theMaplike api.
- a change to not use Store internally and emit fine grade changes with
-
Updated dependencies [
5c538cf,9553366,b4602a0,02adc81,06d8ecc,c50cd51]:- @tanstack/db@0.0.8
-
Expose utilities on collection instances (#161)
Implemented a utility exposure pattern for TanStack DB collections that allows utility functions to be passed as part of collection options and exposes them under a
.utilsnamespace, with full TypeScript typing.- Refactored
createCollectionin packages/db/src/collection.ts to accept options with utilities directly - Added
utilsproperty to CollectionImpl - Added TypeScript types for utility functions and utility records
- Changed Collection from a class to a type, updating all usages to use createCollection() instead
- Updated Electric/Query implementations
- Utilities are now ergonomically accessible under
.utils - Full TypeScript typing is preserved for both collection data and utilities
- API is clean and straightforward - users can call
createCollection(optionsCreator(config))directly - Zero-boilerplate TypeScript pattern that infers utility types automatically
- Refactored
-
Updated dependencies [
8b43ad3]:- @tanstack/db@0.0.7
-
This change introduces a more streamlined and intuitive API for handling mutations by allowing
onInsert,onUpdate, andonDeletehandlers to be defined directly on the collection configuration. (#156)When
collection.insert(),.update(), or.delete()are called outside of an explicit transaction (i.e., not withinuseOptimisticMutation), the library now automatically creates a single-operation transaction and invokes the corresponding handler to persist the change.Key changes:
@tanstack/db: TheCollectionclass now supportsonInsert,onUpdate, andonDeletein its configuration. Direct calls to mutation methods will throw an error if the corresponding handler is not defined.@tanstack/db-collections:queryCollectionOptionsnow accepts the new handlers and will automaticallyrefetchthe collection's query after a handler successfully completes. This behavior can be disabled if the handler returns{ refetch: false }.electricCollectionOptionsalso accepts the new handlers. These handlers are now required to return an object with a transaction ID ({ txid: string }). The collection then automatically waits for thistxidto be synced back before resolving the mutation, ensuring consistency.
- Breaking Change: Calling
collection.insert(),.update(), or.delete()without being inside auseOptimisticMutationcallback and without a corresponding persistence handler (onInsert, etc.) configured on the collection will now throw an error.
This new pattern simplifies the most common use cases, making the code more declarative. The
useOptimisticMutationhook remains available for more complex scenarios, such as transactions involving multiple mutations across different collections.
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.
- The
README.mdanddocs/overview.mdfiles have been updated to de-emphasizeuseOptimisticMutationfor simple writes. They now showcase the much simpler API of callingcollection.insert()directly and defining persistence logic in the collection's configuration. - The React Todo example (
examples/react/todo/src/App.tsx) has been completely overhauled. All instances ofuseOptimisticMutationhave been removed and replaced with the newonInsert,onUpdate, andonDeletehandlers, resulting in cleaner and more concise code.
-
Updated dependencies [
856be72,0455e27,80fdac7]:- @tanstack/db@0.0.6
-
Collections must have a getId function & use an id for update/delete operators (#134)
-
Switch to Collection options factories instead of extending the Collection class (#145)
This refactors
ElectricCollectionandQueryCollectioninto factory functions (electricCollectionOptionsandqueryCollectionOptions) that return standardCollectionConfigobjects and utility functions. Also adds acreateCollectionfunction to standardize collection instantiation. -
Updated dependencies [
1fbb844,338efc2,ee5d026,e7b036c,e4feb0c]:- @tanstack/db@0.0.5
- Updated dependencies [
8ce449e]:- @tanstack/db@0.0.4
-
Replace
queryCollection.invalidate()withqueryCollection.refetch(). (#109)This means that we actually wait for the collection to be updated before discarding local optimistic state.
- Added staleTime support for QueryCollection (#104)
- Updated dependencies [
b29420b]:- @tanstack/db@0.0.3