-
Notifications
You must be signed in to change notification settings - Fork 4k
[cloud_firestore] Created firestore platform interface #1686
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
[cloud_firestore] Created firestore platform interface #1686
Conversation
@ditman That's the first one to get |
@collinjackson, this is the real deal. Most of the work has happened here, but this is what we want to land. PTAL when you have a chance! |
(I'll also be taking another look) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks great, there's a bunch of double quotes across the code, but those can be added later, alongside tightening the lint rules. Only one general comment, the structure of the package under src is a little bit too flat, I think it'd be cool to have a few directories to separate interfaces from implementations (and maybe types). Since everything is part'd in, it should be easy to add afterwards.
Let's wait for Collin's review, but other than the minor nitpicks in this review, I can't find anything that is immediately problematic.
Again, thanks for all this code!
packages/cloud_firestore/cloud_firestore_platform_interface/analysis_options.yaml
Outdated
Show resolved
Hide resolved
...oud_firestore/cloud_firestore_platform_interface/lib/cloud_firestore_platform_interface.dart
Show resolved
Hide resolved
...oud_firestore/cloud_firestore_platform_interface/lib/cloud_firestore_platform_interface.dart
Outdated
Show resolved
Hide resolved
...oud_firestore/cloud_firestore_platform_interface/lib/src/method_channel_document_change.dart
Outdated
Show resolved
Hide resolved
...ud_firestore_platform_interface/lib/src/platform_interface/document_reference_interface.dart
Outdated
Show resolved
Hide resolved
packages/cloud_firestore/cloud_firestore_platform_interface/test/field_value_test.dart
Outdated
Show resolved
Hide resolved
...ages/cloud_firestore/cloud_firestore_platform_interface/lib/src/firestore_message_codec.dart
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
88 ,ad8888ba, 888888888888 88b d88
88 d8"' `"8b 88 888b d888
88 d8' 88 88`8b d8'88
88 88 88 88 `8b d8' 88
88 88 88888 88 88 `8b d8' 88
88 Y8, 88 88 88 `8b d8' 88
88 Y8a. .a88 88 88 `888' 88
88888888888 `"Y88888P" 88 88 `8' 88
Analyzer is complaining about this extra carriage return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for contributing this change! A web implementation of Firestore in FlutterFire is a top requested feature and I'm sure this will help a lot of people.
Here's my initial round of comments; I'm expect I may have a few more once these are addressed.
Please make sure to follow the Effective Dart guide for Dart throughout. In particular please follow these guidelines:
- have a blank line after the first sentence
- put a period at the end of the first line
- avoid redundancy with the surrounding context (e.g. no need to repeat the class name in the constructor's documentation)
Thanks!!
...oud_firestore/cloud_firestore_platform_interface/lib/cloud_firestore_platform_interface.dart
Outdated
Show resolved
Hide resolved
...oud_firestore/cloud_firestore_platform_interface/lib/cloud_firestore_platform_interface.dart
Outdated
Show resolved
Hide resolved
...oud_firestore/cloud_firestore_platform_interface/lib/cloud_firestore_platform_interface.dart
Outdated
Show resolved
Hide resolved
packages/cloud_firestore/cloud_firestore_platform_interface/lib/src/document_snapshot.dart
Outdated
Show resolved
Hide resolved
packages/cloud_firestore/cloud_firestore_platform_interface/lib/src/document_snapshot.dart
Outdated
Show resolved
Hide resolved
...loud_firestore/cloud_firestore_platform_interface/lib/src/method_channel_query_snapshot.dart
Outdated
Show resolved
Hide resolved
...oud_firestore/cloud_firestore_platform_interface/lib/cloud_firestore_platform_interface.dart
Outdated
Show resolved
Hide resolved
throw UnimplementedError("withApp() not implemented"); | ||
} | ||
|
||
/// Firebase app name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to expose a FirebaseApp
here instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FirebaseApp
is already exposed to avoid breaking changes. This is just a convenience used in few places in here
static int _transactionHandlerId = 0; | ||
|
||
@override | ||
FirestorePlatform withApp(FirebaseApp app) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if we can call this instanceFor({ FirebaseApp app })
to match #1377
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point we already have a factory method of the FirestorePlatform
called instanceFor
. We won't be able to rename this as well to instanceFor
. Also this is only made public so FirestoreWeb
(in the web plugin) is able to override it and provide a web-specific implementation.
...oud_firestore/cloud_firestore_platform_interface/lib/cloud_firestore_platform_interface.dart
Outdated
Show resolved
Hide resolved
A small suggestion here: can we have a flutter independent API for firestore? As this package mainly consists of interfaces it would be great to move them into a new package that is pure dart and then depend on it. There are already many attempts to create platform independent APIs for firestore. We ourself also created one (https://github.com/dartclub/firestore_dart). |
@grundid that's a great suggestion, but for now we're focusing on merging this, so people can use Firestore on their Flutter apps. Further abstraction sounds possible (but it also sounds as a v2 project for this change) |
Co-Authored-By: Collin Jackson <[email protected]>
…' into firestore_web/platform_interface
Co-Authored-By: Collin Jackson <[email protected]>
…' into firestore_web/platform_interface
@amrfarid140 I was just finishing testing this on my new test app. Great stuff! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should ship this. What do you think @collinjackson?
@collinjackson any updates or feedback on this PR? Really want to merge to move on with other parts of the web implementation as well. |
Hey @amrfarid140! Apologies for the radio silence! We're about to send you a PR with a few little changes to the platform interface (and things that depend on them). Most of them are some moving around of files (so files regarding platform interfaces live together, same with files regarding the method channel), and some renaming so everything is consistent. The only (big-ish) issue that was found was that the Web versions of the platform interfaces are using I'm currently adding the Bear in mind that this PR is going to be used by many as an "example" on how to build their own plugins, so we need to make sure there's nothing very dangerous here (at least, that we know of now). So by EOD today I'll cut a PR to your repo with the changes to the platform interface and method channel code, and maybe some changes to the Web implementation (just to keep the branch functional!) I'll get back to you ASAP. If you want to privately message me, feel free to do so at: (first half of my github username) at google dot com ;) |
Thanks for this update, I am happy that things are moving along. I will
keep an eye for your PR and aim to get it merge and everything update ASAP.
…On Wed, 29 Jan 2020, 8:26 pm David Iglesias, ***@***.***> wrote:
Hey @amrfarid140 <https://github.com/amrfarid140>! Apologies for the
radio silence!
We're about to send you a PR with a few little changes to the platform
interface (and things that depend on them). Most of them are some moving
around of files (so files regarding platform interfaces live together, same
with files regarding the method channel), and some renaming so everything
is consistent.
The only (big-ish) issue that was found was that the Web versions of the
platform interfaces are using implements, and that basically means that
we cannot change the interface, or it'll break the web implementation.
I'm currently adding the extends PlatformInterface to all the
PlatformInterface objects, so we can prevent the implements from
happening, and it is intentional.
Bear in mind that this PR is going to be used by many as an "example" on
how to build their own plugins, so we need to make sure there's nothing
very dangerous here (at least, that we know of now).
So by EOD today I'll cut a PR to your repo with the changes to the
platform interface and method channel code, and maybe some changes to the
Web implementation (just to keep the branch functional!)
I'll get back to you ASAP. If you want to privately message me, feel free
to do so at: (first half of my github username) at google dot com ;)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1686>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABGFK4NNX7E24JZIC5IYJKLRAHQ6VANCNFSM4J57OA7Q>
.
|
Hey @amrfarid140, it seems I can't create a pull request on your fork. Do you mind giving me permissions to do that? Thanks! |
Hey @amrfarid140, I still can't create PRs on your fork (maybe some weird github issue?) but I've pushed my changes here: https://github.com/amrfarid140/flutterfire/commits/amr-master-pr This is prepared on top of your I think @collinjackson still wants to propose some changes, but I can help with those pretty quickly, once the PR(s) are updated with the above. The bulk of the changes was to remove the API surface exposed to the world through the different packages of the plugin (MethodChannel implementation, Web implementation), and ensure the Platform classes all extended PlatformInterface so they are extended vs implemented. I'd say by "size":
I ran tests and they seem to pass. |
Yeah that's weird @ditman , I've added you as a collaborator and made sure that "allow edits from maintainers" is checked. Anyways, Thanks so much for those changes. I will get all the packages sorted and all those changes to the master branch to update the PRs ASAP. I will also do some testing as well to ensure that we are all good. Thanks @ditman |
@amrfarid140 @collinjackson and I've been working on some extra changes to the branch throughout the day. There's one big change that we want to get in, though, which should simplify the FieldValues a little bit. It is late here, but I'll get some stuff done tomorrow (I can prepare another branch/PR if you don't want to wait for that change) |
@ditman Maybe it makes sense then to wait for you guys to finish all the changes before merging them to |
@amrfarid140 I think we're done! Take a look at the changes! I've tested on my end and it seems to be working; but the more we test, the merrier. Thanks for your patience! |
@amrfarid140 Thank you SO much for the time you've put into this patch. I've been pairing with @ditman on this, and what our changes are doing is reducing fragility -- hiding classes and methods from the app-facing package if they're only useful to platform implementers, minimizing the platform interface surface area (making A few changes of note:
Let us know if there's anything that seems off or confusing! I'm excited to see this landed. |
@ditman @collinjackson Thanks so much for improving this PR. I've gone through the changes and all makes sense to me. Everything is merged now to |
Tests are failing on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're working off an outdated version of the FlutterFire repo. You'll need to merge the upstream master before we can land this. Besides changelog there was one minor conflict (you had a different solution than @kroikie for #1859 and I think we should go with his version). I resolved it in a way that made sense to me; here is a branch showing that: https://github.com/collinjackson/flutterfire/tree/amr-master-merge
Merging this commit will resolve the iOS simulator failures: 16ed623#diff-0f7067c31caedf7df2739c9b07efa122
(The below comments were pending comments that I had on earlier versions of your patch, but I've left them here for posterity.)
/// | ||
/// Once committed, no further operations can be performed on the [WriteBatch], | ||
/// nor can it be committed again. | ||
class WriteBatch extends WriteBatchPlatform { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noting this for posterity since you pushed back on my comment here earlier. What I was trying to suggest was following the same pattern established by Query
, QuerySnapshot
, separating the public API and method channel implementations. This enables the app-facing class to be extended in the future.
|
||
/// An interface for a factory that is used to build [FieldValue] according to | ||
/// Platform (web or mobile) | ||
abstract class FieldValueFactory { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case anyone is wondering why we do verifyExtends
... previously this class didn't extend PlatformInterface
, making it possible to use implements
rather than extends
on this class. This could lead to a situation where no new methods could be added to FieldValueFactory
without breaking platform implementations. And this wasn't just a hypothetical concern, it happened in the web implementation.
It's fixed now.
/// A CollectionReference object can be used for adding documents, getting | ||
/// document references, and querying for documents (using the methods | ||
/// inherited from [Query]). | ||
abstract class CollectionReference extends Query { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I was trying to say here was that this class is tempting to implement using implements
(and in fact the original PR https://github.com/FirebaseExtended/flutterfire/pull/1670/files#diff-167cff67d9c16a4fbee5de8f8a9cd33aR4) did so.
… firestore_web/platform_interface
@collinjackson Merged that latest of Also not sure what's the issue with Android builds. Seems CI related rather than changes related. Would be great if you or @ditman can have a look. Thanks. |
@amrfarid140 I'm relaunching the tests, they seemed to be temporary failures, unrelated to the branch. (Update: Everything is green now.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tagged v1.0.0, and published to pub.dev: https://pub.dev/packages/cloud_firestore_platform_interface/versions/1.0.0 |
@ditman @amrfarid140 May I ask why there is still a platform channel implementation in the Is it to maintain backward compatibility until all platforms use the platform interface? |
@IchordeDionysos the MethodChannel implementation is the one used by the "native" platforms (ios/macos/android). Notice how that implementation Check the doc about plugin federation for much much more info! |
Description
This PR is the first of a set of 3 PRs to enable Flutter Web support for Cloud Firestore.
All the discussion around approach and logic are being actively discussed here.
Related Issues
flutter/flutter#45293
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze
) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?