-
Notifications
You must be signed in to change notification settings - Fork 4.1k
[WIP] Federated cloud firestore platform interface #1568
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
Changes from all commits
51101c9
bbf60ed
4254aef
4487365
0f505c5
fe72775
3f124b9
85a4073
0cfd3d7
32fa7ee
d0663ce
6fd3a00
6610d18
69906ee
75ab8e9
5bf190e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"cloud_firestore","dependencies":["firebase_core"]},{"name":"firebase_core","dependencies":[]}]} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,28 +10,6 @@ part of cloud_firestore; | |
| class Firestore { | ||
| Firestore({FirebaseApp app}) : app = app ?? FirebaseApp.instance { | ||
| if (_initialized) return; | ||
|
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. This can be removed now. |
||
| 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; | ||
|
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. This can be removed now. |
||
| } | ||
|
|
||
|
|
@@ -46,20 +24,7 @@ class Firestore { | |
| static bool _initialized = false; | ||
|
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. This can be removed now. |
||
|
|
||
| @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; | ||
| static CloudFirestorePlatform platform = CloudFirestorePlatform.instance; | ||
|
|
||
| @override | ||
| bool operator ==(dynamic o) => o is Firestore && o.app == app; | ||
|
|
@@ -123,39 +88,42 @@ 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 incoming [TransactionHandler] into something that can be passed | ||
| // to the Platform implementation. | ||
| final PlatformTransactionHandler handler = (int transactionId) async { | ||
| Transaction transaction = Transaction(transactionId, this); | ||
| final dynamic result = await transactionHandler(transaction); | ||
| await transaction._finish(); | ||
| return result; | ||
| }; | ||
|
|
||
| final Map<String, dynamic> result = await platform.runTransaction( | ||
| app.name, | ||
| transactionHandler: handler, | ||
| transactionTimeout: timeout.inMilliseconds, | ||
| ); | ||
| return result ?? <String, dynamic>{}; | ||
| } | ||
|
|
||
| @deprecated | ||
| Future<void> enablePersistence(bool enable) async { | ||
| assert(enable != null); | ||
| await channel | ||
| .invokeMethod<void>('Firestore#enablePersistence', <String, dynamic>{ | ||
| 'app': app.name, | ||
| 'enable': enable, | ||
| }); | ||
| await 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, | ||
| }); | ||
| await platform.settings(app.name, | ||
| persistenceEnabled: persistenceEnabled, | ||
| host: host, | ||
| sslEnabled: sslEnabled, | ||
| cacheSizeBytes: cacheSizeBytes); | ||
|
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. readability nit: my preference would be a trailing comma and give each argument its own line here, assuming the formatter agrees.
Contributor
Author
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. Absolutely, I was trying to convince dartfmt to do it automatically for me (that's why I left the trailing comma at the end), but it didn't take my hint. I'll format all of these manually :'( |
||
| } | ||
| } | ||
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.
Should not be checked in to version control
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 have no idea where this is coming from; I'll remove it from the PR, and add it to .gitignore