Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions .changeset/collection-lifecycle-management.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/gold-friends-pull.md

This file was deleted.

55 changes: 0 additions & 55 deletions .changeset/solid-pandas-draw.md

This file was deleted.

8 changes: 8 additions & 0 deletions examples/react/todo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# examples/react/todo

## 0.0.18

### Patch Changes

- Updated dependencies [[`945868e`](https://github.com/TanStack/db/commit/945868e95944543ccf5d778409548679a952e249), [`57b5f5d`](https://github.com/TanStack/db/commit/57b5f5de6297326a57ef205a400428af0697b48b)]:
- @tanstack/[email protected]
- @tanstack/[email protected]

## 0.0.17

### Patch Changes
Expand Down
6 changes: 3 additions & 3 deletions examples/react/todo/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "@tanstack/db-example-react-todo",
"private": true,
"version": "0.0.17",
"version": "0.0.18",
"dependencies": {
"@tanstack/db-collections": "^0.0.15",
"@tanstack/db-collections": "^0.0.16",
"@tanstack/query-core": "^5.75.7",
"@tanstack/react-db": "^0.0.12",
"@tanstack/react-db": "^0.0.13",
"cors": "^2.8.5",
"drizzle-orm": "^0.40.1",
"drizzle-zod": "^0.7.0",
Expand Down
31 changes: 31 additions & 0 deletions packages/db-collections/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# @tanstack/db-collections

## 0.0.16

### Patch Changes

- feat: implement Collection Lifecycle Management ([#198](https://github.com/TanStack/db/pull/198))

Adds automatic lifecycle management for collections to optimize resource usage.

**New Features:**

- Added `startSync` option (defaults to `false`, set to `true` to start syncing immediately)
- Automatic garbage collection after `gcTime` (default 5 minutes) of inactivity
- Collection status tracking: "idle" | "loading" | "ready" | "error" | "cleaned-up"
- Manual `preload()` and `cleanup()` methods for lifecycle control

**Usage:**

```typescript
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
```

- Updated dependencies [[`945868e`](https://github.com/TanStack/db/commit/945868e95944543ccf5d778409548679a952e249), [`0f8a008`](https://github.com/TanStack/db/commit/0f8a008be8b368f231c8518ad1adfcac08132da2), [`57b5f5d`](https://github.com/TanStack/db/commit/57b5f5de6297326a57ef205a400428af0697b48b)]:
- @tanstack/[email protected]

## 0.0.15

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/db-collections/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tanstack/db-collections",
"description": "A collection for (aspirationally) every way of loading your data",
"version": "0.0.15",
"version": "0.0.16",
"dependencies": {
"@tanstack/db": "workspace:*",
"@tanstack/query-core": "^5.75.7",
Expand Down
80 changes: 80 additions & 0 deletions packages/db/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,85 @@
# @tanstack/db

## 0.0.13

### Patch Changes

- feat: implement Collection Lifecycle Management ([#198](https://github.com/TanStack/db/pull/198))

Adds automatic lifecycle management for collections to optimize resource usage.

**New Features:**

- Added `startSync` option (defaults to `false`, set to `true` to start syncing immediately)
- Automatic garbage collection after `gcTime` (default 5 minutes) of inactivity
- Collection status tracking: "idle" | "loading" | "ready" | "error" | "cleaned-up"
- Manual `preload()` and `cleanup()` methods for lifecycle control

**Usage:**

```typescript
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
```

- Refactored the way we compute change events over the synced state and the optimistic changes. This fixes a couple of issues where the change events were not being emitted correctly. ([#206](https://github.com/TanStack/db/pull/206))

- Add createOptimisticAction helper that replaces useOptimisticMutation ([#210](https://github.com/TanStack/db/pull/210))

An example of converting a `useOptimisticMutation` hook to `createOptimisticAction`. Now all optimistic & server mutation logic are consolidated.

```diff
-import { useOptimisticMutation } from '@tanstack/react-db'
+import { createOptimisticAction } from '@tanstack/react-db'
+
+// Create the `addTodo` action, passing in your `mutationFn` and `onMutate`.
+const addTodo = createOptimisticAction<string>({
+ onMutate: (text) => {
+ // Instantly applies the local optimistic state.
+ todoCollection.insert({
+ id: uuid(),
+ text,
+ completed: false
+ })
+ },
+ mutationFn: async (text) => {
+ // Persist the todo to your backend
+ const response = await fetch('/api/todos', {
+ method: 'POST',
+ body: JSON.stringify({ text, completed: false }),
+ })
+ return response.json()
+ }
+})

const Todo = () => {
- // Create the `addTodo` mutator, passing in your `mutationFn`.
- const addTodo = useOptimisticMutation({ mutationFn })
-
const handleClick = () => {
- // Triggers the mutationFn
- addTodo.mutate(() =>
- // Instantly applies the local optimistic state.
- todoCollection.insert({
- id: uuid(),
- text: '🔥 Make app faster',
- completed: false
- })
- )
+ // Triggers the onMutate and then the mutationFn
+ addTodo('🔥 Make app faster')
}

return <Button onClick={ handleClick } />
}
```

## 0.0.12

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/db/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tanstack/db",
"description": "A reactive client store for building super fast apps on sync",
"version": "0.0.12",
"version": "0.0.13",
"dependencies": {
"@electric-sql/d2mini": "^0.1.2",
"@standard-schema/spec": "^1.0.0",
Expand Down
81 changes: 81 additions & 0 deletions packages/react-db/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,86 @@
# @tanstack/react-db

## 0.0.13

### Patch Changes

- feat: implement Collection Lifecycle Management ([#198](https://github.com/TanStack/db/pull/198))

Adds automatic lifecycle management for collections to optimize resource usage.

**New Features:**

- Added `startSync` option (defaults to `false`, set to `true` to start syncing immediately)
- Automatic garbage collection after `gcTime` (default 5 minutes) of inactivity
- Collection status tracking: "idle" | "loading" | "ready" | "error" | "cleaned-up"
- Manual `preload()` and `cleanup()` methods for lifecycle control

**Usage:**

```typescript
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
```

- Add createOptimisticAction helper that replaces useOptimisticMutation ([#210](https://github.com/TanStack/db/pull/210))

An example of converting a `useOptimisticMutation` hook to `createOptimisticAction`. Now all optimistic & server mutation logic are consolidated.

```diff
-import { useOptimisticMutation } from '@tanstack/react-db'
+import { createOptimisticAction } from '@tanstack/react-db'
+
+// Create the `addTodo` action, passing in your `mutationFn` and `onMutate`.
+const addTodo = createOptimisticAction<string>({
+ onMutate: (text) => {
+ // Instantly applies the local optimistic state.
+ todoCollection.insert({
+ id: uuid(),
+ text,
+ completed: false
+ })
+ },
+ mutationFn: async (text) => {
+ // Persist the todo to your backend
+ const response = await fetch('/api/todos', {
+ method: 'POST',
+ body: JSON.stringify({ text, completed: false }),
+ })
+ return response.json()
+ }
+})

const Todo = () => {
- // Create the `addTodo` mutator, passing in your `mutationFn`.
- const addTodo = useOptimisticMutation({ mutationFn })
-
const handleClick = () => {
- // Triggers the mutationFn
- addTodo.mutate(() =>
- // Instantly applies the local optimistic state.
- todoCollection.insert({
- id: uuid(),
- text: '🔥 Make app faster',
- completed: false
- })
- )
+ // Triggers the onMutate and then the mutationFn
+ addTodo('🔥 Make app faster')
}

return <Button onClick={ handleClick } />
}
```

- Updated dependencies [[`945868e`](https://github.com/TanStack/db/commit/945868e95944543ccf5d778409548679a952e249), [`0f8a008`](https://github.com/TanStack/db/commit/0f8a008be8b368f231c8518ad1adfcac08132da2), [`57b5f5d`](https://github.com/TanStack/db/commit/57b5f5de6297326a57ef205a400428af0697b48b)]:
- @tanstack/[email protected]

## 0.0.12

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/react-db/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tanstack/react-db",
"description": "React integration for @tanstack/db",
"version": "0.0.12",
"version": "0.0.13",
"author": "Kyle Mathews",
"license": "MIT",
"repository": {
Expand Down
Loading