-
Notifications
You must be signed in to change notification settings - Fork 4.1k
[WIP] Firestore platform interface (v2) #1633
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
Closed
Closed
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
1fb5e9c
[firestore_platform_interface] Add package scaffolding.
ditman 8b80635
[firestore_platform_interface] Add first pass of split interfaces and
ditman cd3c1c8
[firestore_platform_interface] Add SetOptions type.
ditman f91c6fb
[firestore_platform_interface] Tighten types, reshuffle exports.
ditman cc03bd7
[firestore] [WIP] Use new platform interface, port transactions to ne…
ditman 46f0759
[firestore_platform_interface] Tighten types around Write Batches.
ditman 795b287
[firestore] Migrate Write Batch to the platform interface.
ditman 6421625
[firestore_platform_interface] Some more types, and reshuffling of ex…
ditman e4424d5
[firestore] Finish porting the plugin to the platform interface, and
ditman 4331bb0
[firestore_platform_interface] Fix signature of callHandler methods.
ditman 2a711a4
[firestore_platform_interface] Add MethodChannel implementation for W…
ditman 6a19d71
[firestore_platform_interface] Make _tokens final, not const.
ditman 27610a3
[firestore_platform_interface] MethodChannel implementations now require
ditman 55fa17a
[firestore] Inject the FirestoreMessageCodec into the
ditman 058ed75
[firestore_platform_interface] Cleanup imports
ditman 732baed
[firestore_platform_interface] Rename `PlatformWriteBatch` to
ditman daccabc
[firestore] Rename `PlatformWriteBatch` to `PlatformWriteBatchHandle`
ditman c65a7dd
[firestore_platform_interface] Add MethodChannelTransaction
ditman 5c5f713
[firestore] Remove superfluous cast.
ditman 843a36f
[firestore_platform_interface] Implement Query:getDocuments
ditman 5779f2d
[firestore] Move Source to the platform interface.
ditman 6c568dc
[firestore_platform_interface] Add, and use MultiMethodChannel.
ditman 7967d41
[firestore] Export Source from platform interface.
ditman 831ee19
[firestore_platform_interface] Add implementation for DocumentReference.
ditman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8,32 +8,11 @@ part of cloud_firestore; | |||||
| /// | ||||||
| /// You can get an instance by calling [Firestore.instance]. | ||||||
| class Firestore { | ||||||
| Firestore({FirebaseApp app}) : app = app ?? FirebaseApp.instance { | ||||||
| if (_initialized) return; | ||||||
| channel.setMethodCallHandler((MethodCall call) async { | ||||||
| if (call.method == 'QuerySnapshot') { | ||||||
| final QuerySnapshot snapshot = QuerySnapshot._(call.arguments, this); | ||||||
| _queryObservers[call.arguments['handle']].add(snapshot); | ||||||
| } else if (call.method == 'DocumentSnapshot') { | ||||||
| final DocumentSnapshot snapshot = DocumentSnapshot._( | ||||||
| call.arguments['path'], | ||||||
| _asStringKeyedMap(call.arguments['data']), | ||||||
| SnapshotMetadata._(call.arguments['metadata']['hasPendingWrites'], | ||||||
| call.arguments['metadata']['isFromCache']), | ||||||
| this, | ||||||
| ); | ||||||
| _documentObservers[call.arguments['handle']].add(snapshot); | ||||||
| } else if (call.method == 'DoTransaction') { | ||||||
| final int transactionId = call.arguments['transactionId']; | ||||||
| final Transaction transaction = Transaction(transactionId, this); | ||||||
| final dynamic result = | ||||||
| await _transactionHandlers[transactionId](transaction); | ||||||
| await transaction._finish(); | ||||||
| return result; | ||||||
| } | ||||||
| }); | ||||||
| _initialized = true; | ||||||
| } | ||||||
| Firestore({FirebaseApp app}) : app = app ?? FirebaseApp.instance; | ||||||
|
|
||||||
| /// The platform instance that talks to the native side of the plugin. | ||||||
| @visibleForTesting | ||||||
| static final FirestorePlatform platform = FirestorePlatform.instance ?? (FirestorePlatform.instance = MethodChannelFirestore(FirestoreMessageCodec())); | ||||||
|
|
||||||
| /// Gets the instance of Firestore for the default Firebase app. | ||||||
| static final Firestore instance = Firestore(); | ||||||
|
|
@@ -43,24 +22,6 @@ class Firestore { | |||||
| /// If null, the default [FirebaseApp] is used. | ||||||
| final FirebaseApp app; | ||||||
|
|
||||||
| static bool _initialized = false; | ||||||
|
|
||||||
| @visibleForTesting | ||||||
| static const MethodChannel channel = MethodChannel( | ||||||
| 'plugins.flutter.io/cloud_firestore', | ||||||
| StandardMethodCodec(FirestoreMessageCodec()), | ||||||
| ); | ||||||
|
|
||||||
| static final Map<int, StreamController<QuerySnapshot>> _queryObservers = | ||||||
| <int, StreamController<QuerySnapshot>>{}; | ||||||
|
|
||||||
| static final Map<int, StreamController<DocumentSnapshot>> _documentObservers = | ||||||
| <int, StreamController<DocumentSnapshot>>{}; | ||||||
|
|
||||||
| static final Map<int, TransactionHandler> _transactionHandlers = | ||||||
| <int, TransactionHandler>{}; | ||||||
| static int _transactionHandlerId = 0; | ||||||
|
|
||||||
| @override | ||||||
| bool operator ==(dynamic o) => o is Firestore && o.app == app; | ||||||
|
|
||||||
|
|
@@ -123,39 +84,41 @@ class Firestore { | |||||
| {Duration timeout = const Duration(seconds: 5)}) async { | ||||||
| assert(timeout.inMilliseconds > 0, | ||||||
| 'Transaction timeout must be more than 0 milliseconds'); | ||||||
| final int transactionId = _transactionHandlerId++; | ||||||
| _transactionHandlers[transactionId] = transactionHandler; | ||||||
| final Map<String, dynamic> result = await channel | ||||||
| .invokeMapMethod<String, dynamic>( | ||||||
| 'Firestore#runTransaction', <String, dynamic>{ | ||||||
| 'app': app.name, | ||||||
| 'transactionId': transactionId, | ||||||
| 'transactionTimeout': timeout.inMilliseconds | ||||||
| }); | ||||||
|
|
||||||
| // Wrap the user-supplied [TransactionHandler] into something that can be passed to the Platform implementation. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| final PlatformTransactionHandler handler = (PlatformTransaction platformTransaction) async { | ||||||
| Transaction transaction = Transaction(platformTransaction.transactionId, this); | ||||||
| final dynamic result = await transactionHandler(transaction); | ||||||
| await transaction._finish(); | ||||||
| return result; | ||||||
| }; | ||||||
|
|
||||||
| final Map<String, dynamic> result = await Firestore.platform.transaction.run( | ||||||
| app.name, | ||||||
| updateFunction: handler, | ||||||
| transactionTimeout: timeout.inMilliseconds, | ||||||
| ); | ||||||
|
|
||||||
| return result ?? <String, dynamic>{}; | ||||||
| } | ||||||
|
|
||||||
| @deprecated | ||||||
| Future<void> enablePersistence(bool enable) async { | ||||||
| Future<void> enablePersistence(bool enable) { | ||||||
| assert(enable != null); | ||||||
| await channel | ||||||
| .invokeMethod<void>('Firestore#enablePersistence', <String, dynamic>{ | ||||||
| 'app': app.name, | ||||||
| 'enable': enable, | ||||||
| }); | ||||||
| return Firestore.platform.enablePersistence(app.name, enable: enable); | ||||||
| } | ||||||
|
|
||||||
| Future<void> settings( | ||||||
| {bool persistenceEnabled, | ||||||
| String host, | ||||||
| bool sslEnabled, | ||||||
| int cacheSizeBytes}) async { | ||||||
| await channel.invokeMethod<void>('Firestore#settings', <String, dynamic>{ | ||||||
| 'app': app.name, | ||||||
| 'persistenceEnabled': persistenceEnabled, | ||||||
| 'host': host, | ||||||
| 'sslEnabled': sslEnabled, | ||||||
| 'cacheSizeBytes': cacheSizeBytes, | ||||||
| }); | ||||||
| int cacheSizeBytes}) { | ||||||
|
|
||||||
| return Firestore.platform.settings(app.name, | ||||||
| persistenceEnabled: persistenceEnabled, | ||||||
| host: host, | ||||||
| sslEnabled: sslEnabled, | ||||||
| cacheSizeBytes: cacheSizeBytes, | ||||||
| ); | ||||||
| } | ||||||
| } | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It seems a bit unintuitive to be doing the assignment like this.