-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
addChangeListener is always triggered on update, even when no result found for query #4196
Comments
The current behavior of |
My understanding of how this would work was this:
What I got was:
I checked #4101 and it does indeed look very good and would satisfy my needs. But I still don't understand why currently the falsy query result ends up calling changeListener... |
For:
There is a misunderstanding here: The current behavior for your example:
For your case, i think you should just use the |
I think a lot of these misunderstandings would be solved if we adopted the semantics described here: #2748 i.e. instead of now where we stop evaluating the query once a match is found, it should keep evaluating the query, possibly returning different objects (which is fine IMO). |
It makes the implementation impossible:
I think it is either we keep current implementation or remove the For the use case described in this issue, user should use |
|
Wait, Are you sure? |
Aha, got it. I did start using It is extremely weird, in my humble opinion, that changeListener keeps on being called on object update that was not described by query the listener was attached to. |
@Zhuinden Just found there is no test to ensure that. But from the code, it should be called when the object gets deleted. the listener should be called with |
I don't think it is called when an object is deleted. It is being tracked here: #3138 |
With Realm Java 3.0.0 being released (https://realm.io/news/realm-java-3-0-collection-notifications/), the change listeners have changed. @NeverwinterMoon it might be a good idea to upgrade to 3.0.0 and tell us if you think we have improved the API :-) |
I agree that right now the semantics do seem kinda weird. It is a mix between a live query and a live object. It should probably: A) Only evaluate the query once and return the matching live object. Which would be invalid if the query didn't find any objects B) Be a live query all the time, which means that the object returned would be a sort of wrapper around Thinking about this a bit more, I probably lean toward A) ... It would keep the semantics around I can see why you would like a convenience method around |
Don't you already have a firstOrDefault? |
@kneth Will try to check out 3.0.0 today-tomorrow and report back on my experience this week. Thanks. |
I move the issue to our "Ideas backlog" as it has spawned a lot of discussion. @NeverwinterMoon Thank you for getting us to think :-) |
I have the following query:
Trip
is updated constantly and, at first, it doesn't have any notifications (empty RealmList is default value), so theblaListener
is triggered. Inside the listener callback notifications are fetched from BE, saved to Realm and linked toTrip
. All fine, except that the listener continues calling theblaListener
continously even though `isEmpty(Trip::notifications.name) is already not true... Am I missing something?Oh, when I use findAllAsync() or findAll() instead, it works as expected.
The text was updated successfully, but these errors were encountered: