Skip to content

Commit 456ae07

Browse files
authored
DOCSP-38015: Add new collection listener properties (#3252)
## Pull Request Info Jira ticket: https://jira.mongodb.org/browse/DOCSP-38015 - [React to Changes - Flutter SDK](https://preview-mongodbcbullinger.gatsbyjs.io/realm/docsp-38015-dart-react-to-changes-updates/sdk/flutter/realm-database/react-to-changes/): Add new `isCleared` and `isCollectionDeleted` properties to list, set, and map tabs ### Reminder Checklist Before merging your PR, make sure to check a few things. - [x] Did you tag pages appropriately? - genre - meta.keywords - meta.description - [x] Describe your PR's changes in the Release Notes section - [x] Create a Jira ticket for related docs-app-services work, if any ### Release Notes - **Flutter** SDK - Realm Database/React to Changes: Update "Register Collection Change Listeners" section to document the `isCollectionDeleted` property for list, set, and map collections and the `isCleared` property for map collections. ### Review Guidelines [REVIEWING.md](https://github.com/mongodb/docs-realm/blob/master/REVIEWING.md)
1 parent 0a3b18b commit 456ae07

6 files changed

+121
-90
lines changed

examples/dart/test/react_to_changes_test.dart

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import 'package:test/test.dart';
44
import 'package:realm_dart/realm.dart';
5-
import './utils.dart';
65
part 'react_to_changes_test.realm.dart';
76

87
// :snippet-start: sample-data-models
@@ -71,16 +70,16 @@ void main() {
7170
// Listen for changes on whole collection
7271
final characters = realm.all<Character>();
7372
final subscription = characters.changes.listen((changes) {
74-
changes.inserted; // indexes of inserted objects
75-
changes.modified; // indexes of modified objects
76-
changes.deleted; // indexes of deleted objects
77-
changes.newModified; // indexes of modified objects
78-
// after deletions and insertions are accounted for
79-
changes.moved; // indexes of moved objects
80-
changes.results; // the full List of objects
73+
changes.inserted; // Indexes of inserted objects.
74+
changes.modified; // Indexes of modified objects.
75+
changes.deleted; // Indexes of deleted objects.
76+
changes.newModified; // Indexes of modified objects after accounting for deletions & insertions.
77+
changes.moved; // Indexes of moved objects.
78+
changes.results; // The full List of objects.
79+
changes.isCleared; // `true` after call to characters.clear(); otherwise, `false`.
8180
});
8281

83-
// Listen for changes on RealmResults
82+
// Listen for changes on RealmResults.
8483
final hobbits = fellowshipOfTheRing.members.query('species == "Hobbit"');
8584
final hobbitsSubscription = hobbits.changes.listen((changes) {
8685
// ... all the same data as above
@@ -89,7 +88,7 @@ void main() {
8988
await Future<void>.delayed(Duration(milliseconds: 10));
9089
// :snippet-start: pause-resume-subscription
9190
subscription.pause();
92-
// the changes.listen() method won't fire until the subscription is resumed
91+
// The changes.listen() method won't fire until subscription is resumed.
9392
subscription.resume();
9493
// :snippet-end:
9594
await Future<void>.delayed(Duration(milliseconds: 10));
@@ -103,9 +102,9 @@ void main() {
103102
final frodo = globalFrodo;
104103
// :snippet-start: realm-object-change-listener
105104
final frodoSubscription = frodo.changes.listen((changes) {
106-
changes.isDeleted; // if the object has been deleted
107-
changes.object; // the RealmObject being listened to, `frodo`
108-
changes.properties; // the changed properties
105+
changes.isDeleted; // If the object has been deleted.
106+
changes.object; // The RealmObject being listened to, `frodo`.
107+
changes.properties; // The changed properties.
109108
});
110109
// :snippet-end:
111110
await Future<void>.delayed(Duration(milliseconds: 10));
@@ -117,16 +116,14 @@ void main() {
117116
// :snippet-start: realm-list-change-listener
118117
final fellowshipSubscription =
119118
fellowshipOfTheRing.members.changes.listen((changes) {
120-
changes.inserted; // indexes of inserted Realm objects
121-
changes.modified; // indexes of modified Realm objects
122-
changes.deleted; // indexes of deleted Realm objects
123-
changes.newModified; // indexes of modified Realm objects
124-
// after deletions and insertions are accounted for
125-
changes.moved; // indexes of moved Realm objects
126-
changes.list; // the full RealmList of Realm objects
127-
// `true` after call to fellowshipOfTheRing.members.clear().
128-
// Otherwise false.
129-
changes.isCleared;
119+
changes.inserted; // Indexes of inserted objects.
120+
changes.modified; // Indexes of modified objects.
121+
changes.deleted; // Indexes of deleted objects.
122+
changes.newModified; // Indexes of modified objects after accounting for deletions & insertions.
123+
changes.moved; // Indexes of moved objects.
124+
changes.list; // The full RealmList of objects.
125+
changes.isCleared; // `true` after call to fellowshipOfTheRing.members.clear(); otherwise, `false`.
126+
changes.isCollectionDeleted; // `true` if the collection is deleted; otherwise, `false`.
130127
});
131128
// :snippet-end:
132129
await Future<void>.delayed(Duration(milliseconds: 10));
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
subscription.pause();
2-
// the changes.listen() method won't fire until the subscription is resumed
2+
// The changes.listen() method won't fire until subscription is resumed.
33
subscription.resume();

source/examples/generated/flutter/react_to_changes_test.snippet.query-change-listener.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// Listen for changes on whole collection
22
final characters = realm.all<Character>();
33
final subscription = characters.changes.listen((changes) {
4-
changes.inserted; // indexes of inserted objects
5-
changes.modified; // indexes of modified objects
6-
changes.deleted; // indexes of deleted objects
7-
changes.newModified; // indexes of modified objects
8-
// after deletions and insertions are accounted for
9-
changes.moved; // indexes of moved objects
10-
changes.results; // the full List of objects
4+
changes.inserted; // Indexes of inserted objects.
5+
changes.modified; // Indexes of modified objects.
6+
changes.deleted; // Indexes of deleted objects.
7+
changes.newModified; // Indexes of modified objects after accounting for deletions & insertions.
8+
changes.moved; // Indexes of moved objects.
9+
changes.results; // The full List of objects.
10+
changes.isCleared; // `true` after call to characters.clear(); otherwise, `false`.
1111
});
1212

13-
// Listen for changes on RealmResults
13+
// Listen for changes on RealmResults.
1414
final hobbits = fellowshipOfTheRing.members.query('species == "Hobbit"');
1515
final hobbitsSubscription = hobbits.changes.listen((changes) {
1616
// ... all the same data as above
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
final fellowshipSubscription =
22
fellowshipOfTheRing.members.changes.listen((changes) {
3-
changes.inserted; // indexes of inserted Realm objects
4-
changes.modified; // indexes of modified Realm objects
5-
changes.deleted; // indexes of deleted Realm objects
6-
changes.newModified; // indexes of modified Realm objects
7-
// after deletions and insertions are accounted for
8-
changes.moved; // indexes of moved Realm objects
9-
changes.list; // the full RealmList of Realm objects
10-
// `true` after call to fellowshipOfTheRing.members.clear().
11-
// Otherwise false.
12-
changes.isCleared;
3+
changes.inserted; // Indexes of inserted objects.
4+
changes.modified; // Indexes of modified objects.
5+
changes.deleted; // Indexes of deleted objects.
6+
changes.newModified; // Indexes of modified objects after accounting for deletions & insertions.
7+
changes.moved; // Indexes of moved objects.
8+
changes.list; // The full RealmList of objects.
9+
changes.isCleared; // `true` after call to fellowshipOfTheRing.members.clear(); otherwise, `false`.
10+
changes.isCollectionDeleted; // `true` if the collection is deleted; otherwise, `false`.
1311
});
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
final frodoSubscription = frodo.changes.listen((changes) {
2-
changes.isDeleted; // if the object has been deleted
3-
changes.object; // the RealmObject being listened to, `frodo`
4-
changes.properties; // the changed properties
2+
changes.isDeleted; // If the object has been deleted.
3+
changes.object; // The RealmObject being listened to, `frodo`.
4+
changes.properties; // The changed properties.
55
});

0 commit comments

Comments
 (0)