Skip to content
Source
Sign inSign up
TanStack/db

feat(svelte-db): implement useLiveInfiniteQuery for svelte 5 #1447

Closeddevcsrj(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/1447/headopened

Showing 5 changed files with 60 additions and 0 deletions (loading 3).

x
0 of 5 viewed, 5 left
59 additions and 0 deletions.changeset/spicy-roses-hide.mdAdded
View file
@@ -0,0 +1,59 @@
+---
+'@tanstack/svelte-db': minor
+---
+​
+Add `useLiveInfiniteQuery` rune for infinite scrolling with live updates.
+​
+The new `useLiveInfiniteQuery` provides an infinite query pattern similar to TanStack Query's `useInfiniteQuery`, but integrated with TanStack DB's reactive local collections. It maintains a reactive window into your data, allowing for efficient pagination and automatic updates as data changes.
+​
+**Key features:**
+​
+- **Automatic Live Updates**: Reactive integration with local collections using Svelte runes.
+- **Efficient Pagination**: Uses a dynamic window mechanism to track visible data without re-executing complex queries.
+- **Automatic Page Detection**: Includes a built-in peek-ahead strategy to detect if more pages are available without manual `getNextPageParam` logic.
+- **Flexible Rendering**: Provides both a flattened `data` array and a structured `pages` array.
+​
+**Example usage:**
+​
+```svelte
+<script lang="ts">
+ import { useLiveInfiniteQuery } from "@tanstack/svelte-db";
+ import { postsCollection } from "./db";
+​
+ const query = useLiveInfiniteQuery(
+ (q) =>
+ q
+ .from({ posts: postsCollection })
+ .orderBy(({ posts }) => posts.createdAt, "desc"),