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.

Object changelisteners does not trigger if a linked object changes

See original GitHub issue

Goal

Detect changes of nested objects of a single RealmObject using RealmChangeListener . Understand the differences between RealmChangeListener on RealmObject and RealmResults.

Expected Results

RealmChangeListener of a single RealmObject would listen to changes of its nested objects. RealmChangeListener of a single RealmObject would listen to more changes than the RealmChangeListener of RealmResults.

Actual Results

RealmChangeListener of a single RealmObject doesn’t listen to changes of its nested objects. RealmChangeListener of RealmResults listens to changes of its children’s nested objects.

Steps & Code to Reproduce

I created a simple Android project to reproduce my use case: https://github.com/jpmcosta/RealmTestProject/tree/262ee9099b47852c2b26bc2f7e3874c8670e6264

Schema:

  • App object contains a RealmColor property. That’s just a (bad) pattern to illustrate the issue.

How to reproduce the issue:

  • there’s a list with a single App object
  • click on that object to randomly change the value of its RealmColor property
  • when RealmColor.value changes we want to:
    • change the App text color
    • change the FAB color

To change the App text color we add RealmChangeListener to RealmResults<App> and call notifyDatasetChanged when a change is detected. To change the FAB color we add a RealmChangeListener to the App object and update its color when a change is detected.

Issue:

  • The FAB color is not updated properly.

Version of Realm and tooling

Realm version: 3.3.2

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:11
  • Comments:39 (18 by maintainers)

github_iconTop GitHub Comments

2reactions
jpmcostacommented, Jun 14, 2017

@Zhuinden yes, that would work. I understand that App itself has not changed. But then, why does the RealmChangeListener in RealmResults<App> detect a change? Also, if I have 10 nested objects, should I need to add 10 different listeners?

1reaction
jpmcostacommented, Nov 16, 2018

we’re not sure why it worked for me but it did

You probably were updating the parent object in the same transaction, without really thinking about it.

I want to get notified, when a nested object changes. Is this possible?

My ugly solution is to update the parent object “manually”. Usually, I have an updatedAt: Long property in the parent, which the child object is responsible to update whenever it is updated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ChangeListener not fired unless source of ObjectProperty ...
My Question is: How can I achieve to be notified if the KeyStore gets updated even if the referenced object does not change?...
Read more >
Selection change event not fired - Oracle Communities
Here is my attempt at this, which doesn't actually work. The issue with it is that if you select the first item in...
Read more >
Untitled
Changes made to the object in either document are reflected in the other. Oddities about linking and embedding. If the path name of...
Read more >
IlvSimpleLink (Rogue Wave JViews 9.1 API)
Fires a boolean property change event if the input boolean values are not equal. protected void, firePropertyChange(String propertyName, float oldValue, float ...
Read more >
Property value change listeners - Undocumented Matlab
Therefore, if we wish to do something when some property value is changed ... a schema.prop class object hListener = handle.listener(hAxes, ...
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