Skip to content

Return query collection from useLiveQuery#74

Merged
KyleAMathews merged 3 commits into
mainfrom
return-collection
May 13, 2025
Merged

Return query collection from useLiveQuery#74
KyleAMathews merged 3 commits into
mainfrom
return-collection

Conversation

@KyleAMathews
Copy link
Copy Markdown
Collaborator

Fixes #67

@samwillis I started working on this and ran into this issue when trying to add a test where I query the QueryCollection.

 FAIL   @tanstack/react-optimistic  tests/useLiveQuery.test.tsx > Query Collections > should be able to query a colle
ction
TypeError: object is not iterable (cannot read property Symbol(Symbol.iterator))
 ❯ ../optimistic/src/query/compiled-query.ts:84:30
     82|             data.collection
     83|               .getInner()
     84|               .reduce((acc, [[key, value], multiplicity]) => {
       |                              ^
     85|                 console.log({ acc, key, value, multiplicity })
     86|                 const changes = acc.get(key) || {
 ❯ OutputOperator.<anonymous> ../optimistic/src/query/compiled-query.ts:84:16
 ❯ OutputOperator.run ../../node_modules/.pnpm/@electric-sql+d2ts@0.1.4_@electric-sql+client@1.0.0/node_modules/@elec
tric-sql/d2ts/src/operators/output.ts:35:15
 ❯ D2.step ../../node_modules/.pnpm/@electric-sql+d2ts@0.1.4_@electric-sql+client@1.0.0/node_modules/@electric-sql/d2
ts/src/d2.ts:78:10
 ❯ D2.run ../../node_modules/.pnpm/@electric-sql+d2ts@0.1.4_@electric-sql+client@1.0.0/node_modules/@electric-sql/d2t
s/src/d2.ts:88:12
 ❯ CompiledQuery.runGraph ../optimistic/src/query/compiled-query.ts:177:16
 ❯ ../optimistic/src/query/compiled-query.ts:193:12
 ❯ batch ../../node_modules/.pnpm/@tanstack+store@0.7.0/node_modules/@tanstack/store/src/scheduler.ts:143:8
 ❯ CompiledQuery.start ../optimistic/src/query/compiled-query.ts:187:5

I quickly got lost in the mirror world of multisets so thought you should look at it 😂

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 12, 2025

⚠️ No Changeset found

Latest commit: bf2b272

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 12, 2025

examples/react/todo

npm i https://pkg.pr.new/@tanstack/db@74
npm i https://pkg.pr.new/@tanstack/db-collections@74
npm i https://pkg.pr.new/@tanstack/react-db@74

commit: bf2b272

@samwillis
Copy link
Copy Markdown
Collaborator

I'll pick this up tomorrow.

@samwillis
Copy link
Copy Markdown
Collaborator

@KyleAMathews fixed, you were very close on this - it was the missing keyBy (need to get rid of that!)

added it all as a new test at the end, with a bonus test go groupBy for a count by team.

@samwillis samwillis self-requested a review May 13, 2025 11:36
Copy link
Copy Markdown
Collaborator

@samwillis samwillis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@KyleAMathews
Copy link
Copy Markdown
Collaborator Author

haha oops, thanks! And nice test 💥

@KyleAMathews KyleAMathews merged commit eb149c0 into main May 13, 2025
4 checks passed
@KyleAMathews KyleAMathews deleted the return-collection branch May 13, 2025 11:51
cursor Bot pushed a commit that referenced this pull request Jul 16, 2025
Co-authored-by: Sam Willis <sam.willis@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Return collection from useLiveQuery (the query's new collection)

2 participants