Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Add Firestore transaction example #442

Merged
merged 6 commits into from
May 7, 2018

Conversation

kroikie
Copy link
Contributor

@kroikie kroikie commented Mar 27, 2018

fixes: flutter/flutter#14655

Adding a transaction example to README.

final DocumentReference postRef = Firestore.instance.document('posts/123');
final TransactionHandler transactionHandler = (Transaction tx) async {
DocumentSnapshot postSnapshot = await tx.get(postRef);
if (postSnapshot.exist) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you mean exists

@@ -60,6 +60,19 @@ class BookList extends StatelessWidget {
}
```

Running a transaction
Copy link
Contributor

Choose a reason for hiding this comment

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

I would put a colon here for consistency with the other examples in this section


```dart
final DocumentReference postRef = Firestore.instance.document('posts/123');
final TransactionHandler transactionHandler = (Transaction tx) async {
Copy link

Choose a reason for hiding this comment

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

Assigning functions to variables this way is against the Dart style guide (not sure about Flutter)
Any reason why this is not passed as a closure or at least a nested function?
See also this linter rule http://dart-lang.github.io/linter/lints/prefer_function_declarations_over_variables.html

Copy link
Contributor

Choose a reason for hiding this comment

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

With sound dart or dart 2 on the horizon, the goal is to express the intent of the type, so with function expressions it is good to express the consumed type on the left side. So with that said, it seems reasonable to to express clearly the expressed type, so the reader can clearly read the story with in moments of landing.
https://www.dartlang.org/guides/language/effective-dart/design#avoid-annotating-types-on-function-expressions

Copy link
Contributor

@collinjackson collinjackson Apr 5, 2018

Choose a reason for hiding this comment

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

In this particular case I think it would be concise and readable to define a closure at the point of invoking runTransaction(), like we do for setState(). @kroikie, do you agree? i.e.

Firestore.instance.runTransaction((Transaction tx) async { ... });

@Hixie
Copy link
Contributor

Hixie commented Apr 25, 2018

What is your plan with this PR? (No particular rush, I'm just cleaning out the review queue.)

@collinjackson collinjackson merged commit 060d603 into flutter:master May 7, 2018
slightfoot pushed a commit to slightfoot/plugins that referenced this pull request Jun 5, 2018
julianscheel pushed a commit to jusst-engineering/plugins that referenced this pull request Mar 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
6 participants