Skip to content
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

Enable listeners on RealmList #4216

Merged
merged 12 commits into from
Feb 24, 2017
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
### Breaking changes

* `RealmResults.distinct()` returns a new `RealmResults` object instead of filtering on the original object (#2947).
* `RealmResults` is auto-updated continuously. Any transaction on the current thread which may have an impact on the order or elements of the `RealmResults` will change the `RealmResults` immediately instead of change it in the next event loop. The standard `RealmResults.iterator()` will continue to work as normal, which means that you can still delete or modify elements without impacting the iterator. The same is not true for simple for-loops. In some cases a simple for-loop will not work (https://realm.io/docs/java/2.3.1/api/io/realm/OrderedRealmCollection.html#loops), and you must use the new createSnapshot() method.
* `RealmResults` is auto-updated continuously. Any transaction on the current thread which may have an impact on the order or elements of the `RealmResults` will change the `RealmResults` immediately instead of change it in the next event loop. The standard `RealmResults.iterator()` will continue to work as normal, which means that you can still delete or modify elements without impacting the iterator. The same is not true for simple for-loops. In some cases a simple for-loop will not work (https://realm.io/docs/java/latest/api/io/realm/OrderedRealmCollection.html#loops), and you must use the new createSnapshot() method.

### Deprecated

* `RealmResults.removeChangeListeners()`. Use `RealmResults.removeAllChangeListeners()` instead.

### Enhancements

* Added support for sorting by link's field (#672).
* Added `OrderedRealmCollectionSnapshot` class and `OrderedRealmCollection.createSnapshot()` method. `OrderedRealmCollectionSnapshot` is useful when changing `RealmResults` or `RealmList` in simple loops.
* Added support for adding listeners on `RealmList`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens with the iterators?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RealmList's iterators stay the same. They have quite different meanings compared with RealmResults. e.g.: RealmList is actually mutable for users, but RealmResults is not.


### Internal

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ public void onChange(Realm object) {
@Override
public void onChange(Realm object) {
listenerBCalled.incrementAndGet();
if (listenerACalled.get() == 1) {
if (listenerBCalled.get() == 1) {
// 2. Reverse order.
realm.removeAllChangeListeners();
realm.addChangeListener(this);
Expand All @@ -476,6 +476,8 @@ public void onChange(Realm object) {
public void execute(Realm realm) {
}
});
} else if (listenerBCalled.get() == 2) {
assertEquals(1, listenerACalled.get());
}
}
};
Expand Down
Loading