-
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
Changed Notification raised even when the value is the same #5451
Comments
Yes, this is by design. The checking can be moved to the Realm side so you don't have to do it every time. But that may slow down other cases since for every setters Realm will do a equality check. I am not quite sure we will change the design. So for now, i think you still need to do the check in your setters manually. |
I understand that to make checks every time is expensive, but it is a bit "unnatural" to receive notifications when they are not expected. |
Having a custom setter doesn't effect Realm as long as the standard getter is still there. See https://medium.com/@nomanr/backing-field-in-kotlin-explained-9f903f27946c We have an issue discussing what to do about the situation as it isn't entirely trivial. Not receiving updates about overriding the same field makes sense for UI components, but might be relevant in other cases. If I can just remember where we had that discussion 🙄 |
See realm/realm-core#2787 for a discussion of this on Realm Core level. So this means that you get notification because a Which is why only the user knows if "not setting the value" is not necessary. |
Thanks for the insight about the current status. From that thread, It seems that the decision have been made more for a technical problem, as even in the discussion is stated that it strange to receive notifications even when there is not change made. Thank you for taking the time to find and post the thread discussion. |
It is indeed tricky unfortunately, personally I was wondering about the possibility of creating some kind of generated "merge" method that only calls the setter if it's not equal. But then you'd have another new method to save a RealmObject, there are already 3 of them :D |
I think any elegant solution will probably be implemented at Core level (to have old/new value) this requires stable ID work to be completed first realm/realm-core#1971 |
@nhachicha Row-level stable IDs? that'll take a while 😄 I'm not even sure if Realm-Java has stable ID support for table in non-sync mode |
We are using realm extensively in quite a number of projects both in java & swift. While swift object change has new/old value support. In android we would like something along those lines if possible. |
@softwarejoint you should bring that to #4366 |
+1 for a way to get notified of actual changes of the model. The update functionality is great because it saves a lot of code that is boilerplate, but if there is no way of knowing whether it modified the model, we can not use it to update views. In our case we query our server every second for a JSON of the model. I would love to just refresh the view in the on change notification but it will trigger every second regardless of changes to the JSON from the server. |
Here is my case of that problem with gif: |
You can use the new ImportFlags to change this behavior |
Does it have the analog in swift? |
All I know is that it was merged in Java here #6224 I don't see anything similar on realm-cocoa which is odd. |
I have a RealmObject with a private property with get / set accesor.
(Nothing fancy there).
I have a subscritor to a list of dogs:
As expected, anytime the name of any dog is changed the listener is hit, however what I didn't expect is that the listener is hit everytime I assign a name to the name field even if it is the same as it has, I don't know if this behavior is by design, so I had to add something like this:
I know that this is an easy solution, but I wonder why the listener is launched even if the underlined data is not changed.
Is this the expected behavior?
(I'm using Realm 4.1.0 on a 6.0 Android emulated device)
The text was updated successfully, but these errors were encountered: