Skip to content
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

Adds query to transaction and refactor transaction to reuse the get etc functions #102

Open
wants to merge 14 commits into
base: v8
Choose a base branch
from

Conversation

ftzi
Copy link

@ftzi ftzi commented Nov 11, 2021

Queries can be used in transactions if running on server, as I read and tried (haven't tried on client yet but working on server). #6 #95

Also, as you mentioned in the code, you rewrote the get etc functions inside the transaction.

// ^ above
// TODO: Refactor code above and below because is all the same as in the regular get function
const firestoreSnap = await t.get(firestoreDoc)
// v below

I have made a quick workaround so both get() and transaction's get() uses the same common function. Done the same for query(). It can also be done for the other transaction functions but won't do it until you think it's a good idea.

This branch is working but leaving as a Draft until further discussion and maybe improvements.

@@ -426,7 +392,10 @@ export async function transaction<
t.delete(firebaseDoc)
}

return readFunction({ get }).then((data) =>
return readFunction({
get: (...props) => (getCommon as any)(props[0], props[1], props[2], {a, t}),
Copy link
Author

Choose a reason for hiding this comment

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

I had to as any because all those generics and overloads of get weren't matching, but it's the same params order. Tried to get it working without the type cast but hadn't success.

Also, I props[0], props[1], props[2] instead of ...props because some of them are optional and would make {a, t} be in the wrong param instead of the forth one.

@ftzi ftzi marked this pull request as ready for review January 7, 2022 03:25
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.

1 participant