Skip to content

Commit 4acdcc1

Browse files
Breaking changes to signature of snapshots and setData in cloud_firestore (flutter#536)
These changes are required to support the metadata argument to snapshots and other future API changes.
1 parent fe87149 commit 4acdcc1

File tree

9 files changed

+30
-49
lines changed

9 files changed

+30
-49
lines changed

packages/cloud_firestore/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.7.0
2+
3+
* **Breaking change**. `snapshots` is now a method instead of a getter.
4+
* **Breaking change**. `setData` uses named arguments instead of `SetOptions`.
5+
16
## 0.6.3
27

38
* Updated Google Play Services dependencies to version 15.0.0.

packages/cloud_firestore/example/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class MessageList extends StatelessWidget {
3232
@override
3333
Widget build(BuildContext context) {
3434
return new StreamBuilder<QuerySnapshot>(
35-
stream: firestore.collection('messages').snapshots,
35+
stream: firestore.collection('messages').snapshots(),
3636
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
3737
if (!snapshot.hasData) return const Text('Loading...');
3838
final int messageCount = snapshot.data.documents.length;

packages/cloud_firestore/lib/cloud_firestore.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ part 'src/firestore.dart';
2626
part 'src/geo_point.dart';
2727
part 'src/query.dart';
2828
part 'src/query_snapshot.dart';
29-
part 'src/set_options.dart';
3029
part 'src/firestore_message_codec.dart';
3130
part 'src/snapshot_metadata.dart';
3231
part 'src/transaction.dart';

packages/cloud_firestore/lib/src/document_reference.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,20 @@ class DocumentReference {
3333
/// This document's given or generated ID in the collection.
3434
String get documentID => _pathComponents.last;
3535

36-
/// Writes to the document referred to by this [DocumentReference]. If the
37-
/// document does not yet exist, it will be created. If you pass [SetOptions],
38-
/// the provided data will be merged into an existing document.
39-
Future<void> setData(Map<String, dynamic> data, [SetOptions options]) {
36+
/// Writes to the document referred to by this [DocumentReference].
37+
///
38+
/// If the document does not yet exist, it will be created.
39+
///
40+
/// If [merge] is true, the provided data will be merged into an
41+
/// existing document instead of overwriting.
42+
Future<void> setData(Map<String, dynamic> data, {bool merge: false}) {
4043
return Firestore.channel.invokeMethod(
4144
'DocumentReference#setData',
4245
<String, dynamic>{
4346
'app': firestore.app.name,
4447
'path': path,
4548
'data': data,
46-
'options': options?._data,
49+
'options': <String, bool>{'merge': merge},
4750
},
4851
);
4952
}
@@ -95,7 +98,7 @@ class DocumentReference {
9598

9699
/// Notifies of documents at this location
97100
// TODO(jackson): Reduce code duplication with [Query]
98-
Stream<DocumentSnapshot> get snapshots {
101+
Stream<DocumentSnapshot> snapshots() {
99102
Future<int> _handle;
100103
// It's fine to let the StreamController be garbage collected once all the
101104
// subscribers have cancelled; this analyzer warning is safe to ignore.

packages/cloud_firestore/lib/src/query.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Query {
4747

4848
/// Notifies of query results at this location
4949
// TODO(jackson): Reduce code duplication with [DocumentReference]
50-
Stream<QuerySnapshot> get snapshots {
50+
Stream<QuerySnapshot> snapshots() {
5151
Future<int> _handle;
5252
// It's fine to let the StreamController be garbage collected once all the
5353
// subscribers have cancelled; this analyzer warning is safe to ignore.

packages/cloud_firestore/lib/src/set_options.dart

Lines changed: 0 additions & 24 deletions
This file was deleted.

packages/cloud_firestore/lib/src/write_batch.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ class WriteBatch {
6161
///
6262
/// If the document does not yet exist, it will be created.
6363
///
64-
/// If you pass [SetOptions], the provided data will be merged into an
65-
/// existing document.
64+
/// If [merge] is true, the provided data will be merged into an
65+
/// existing document instead of overwriting.
6666
void setData(DocumentReference document, Map<String, dynamic> data,
67-
[SetOptions options]) {
67+
{bool merge: false}) {
6868
if (!_committed) {
6969
_handle.then((dynamic handle) {
7070
_actions.add(
@@ -75,7 +75,7 @@ class WriteBatch {
7575
'handle': handle,
7676
'path': document.path,
7777
'data': data,
78-
'options': options?._data,
78+
'options': <String, bool>{'merge': merge},
7979
},
8080
),
8181
);

packages/cloud_firestore/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for Cloud Firestore, a cloud-hosted, noSQL database
33
live synchronization and offline support on Android and iOS.
44
author: Flutter Team <flutter-dev@googlegroups.com>
55
homepage: https://github.com/flutter/plugins/tree/master/packages/cloud_firestore
6-
version: 0.6.3
6+
version: 0.7.0
77

88
flutter:
99
plugin:

packages/cloud_firestore/test/cloud_firestore_test.dart

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ void main() {
246246
});
247247
test('listen', () async {
248248
final QuerySnapshot snapshot =
249-
await collectionReference.snapshots.first;
249+
await collectionReference.snapshots().first;
250250
final DocumentSnapshot document = snapshot.documents[0];
251251
expect(document.documentID, equals('0'));
252252
expect(document.reference.path, equals('foo/0'));
@@ -275,7 +275,7 @@ void main() {
275275
final StreamSubscription<QuerySnapshot> subscription =
276276
collectionReference
277277
.where('createdAt', isLessThan: 100)
278-
.snapshots
278+
.snapshots()
279279
.listen((QuerySnapshot querySnapshot) {});
280280
subscription.cancel();
281281
await new Future<Null>.delayed(Duration.zero);
@@ -306,7 +306,7 @@ void main() {
306306
final StreamSubscription<QuerySnapshot> subscription =
307307
collectionReference
308308
.where('profile', isNull: true)
309-
.snapshots
309+
.snapshots()
310310
.listen((QuerySnapshot querySnapshot) {});
311311
subscription.cancel();
312312
await new Future<Null>.delayed(Duration.zero);
@@ -337,7 +337,7 @@ void main() {
337337
final StreamSubscription<QuerySnapshot> subscription =
338338
collectionReference
339339
.orderBy('createdAt')
340-
.snapshots
340+
.snapshots()
341341
.listen((QuerySnapshot querySnapshot) {});
342342
subscription.cancel();
343343
await new Future<Null>.delayed(Duration.zero);
@@ -369,7 +369,7 @@ void main() {
369369
group('DocumentReference', () {
370370
test('listen', () async {
371371
final DocumentSnapshot snapshot =
372-
await firestore.document('path/to/foo').snapshots.first;
372+
await firestore.document('path/to/foo').snapshots().first;
373373
expect(snapshot.documentID, equals('foo'));
374374
expect(snapshot.reference.path, equals('path/to/foo'));
375375
expect(snapshot.data, equals(kMockDocumentSnapshotData));
@@ -405,7 +405,7 @@ void main() {
405405
'app': app.name,
406406
'path': 'foo/bar',
407407
'data': <String, String>{'bazKey': 'quxValue'},
408-
'options': null,
408+
'options': <String, bool>{'merge': false},
409409
},
410410
),
411411
],
@@ -414,8 +414,7 @@ void main() {
414414
test('merge set', () async {
415415
await collectionReference
416416
.document('bar')
417-
.setData(<String, String>{'bazKey': 'quxValue'}, SetOptions.merge);
418-
expect(SetOptions.merge, isNotNull);
417+
.setData(<String, String>{'bazKey': 'quxValue'}, merge: true);
419418
expect(
420419
log,
421420
<Matcher>[
@@ -576,7 +575,7 @@ void main() {
576575
'handle': 1,
577576
'path': 'foo/bar',
578577
'data': <String, String>{'bazKey': 'quxValue'},
579-
'options': null,
578+
'options': <String, bool>{'merge': false},
580579
},
581580
),
582581
isMethodCall(
@@ -593,10 +592,9 @@ void main() {
593592
batch.setData(
594593
collectionReference.document('bar'),
595594
<String, String>{'bazKey': 'quxValue'},
596-
SetOptions.merge,
595+
merge: true,
597596
);
598597
await batch.commit();
599-
expect(SetOptions.merge, isNotNull);
600598
expect(
601599
log,
602600
<Matcher>[

0 commit comments

Comments
 (0)