question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Changed Notification raised even when the value is the same

See original GitHub issue

I have a RealmObject with a private property with get / set accesor.

public class Dog extends RealmObject
{
	private String name;
	public String getName()
	{
		return name;
	}
	
	public void setName(String name)
	{
		this.name = name;
	}
}

(Nothing fancy there). I have a subscritor to a list of dogs:

RealmResults<Dog> mydogs = realm.where(Dog.class).findAll();
mydogs.addChangeListener((dogs, changeSet) -> //any update stuff);

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:

       public void setName(String name)
	{
                if (!this.name.equals(name)
		     this.name = name;
	}

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)

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
digitalhoaxcommented, Sep 26, 2018

+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.

2reactions
Zhuindencommented, Oct 23, 2017

See https://github.com/realm/realm-core/issues/2787 for a discussion of this on Realm Core level.

So this means that you get notification because a set operation is logged by Core which is indeed a requirement not to miss changes in a synchronized setting.

Which is why only the user knows if “not setting the value” is not necessary.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to: Implement Property Change Notification - WPF .NET ...
Enable your properties to automatically notify a binding source when the property value changes in Windows Presentation Foundation (WPF).
Read more >
c# - How to trigger event when a variable's value is changed?
This allows you to run some code any time the property value changes. You could raise an event here, if you wanted.
Read more >
Notifications - System experiences - Human Interface Guidelines
A notification gives people timely, high-value information they can understand at a glance.
Read more >
Customize Support Settings - Salesforce Help
Support settings can help you automate case management. Choose email templates, default case owner, case notifications, and more.
Read more >
If You're Going to Raise Prices, Tell Customers Why
Many companies, and even entire industries, routinely raise ... Call the action a price increase, not a price adjustment, a price change, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found