realm-dotnet icon indicating copy to clipboard operation
realm-dotnet copied to clipboard

RealmCollection.SubscribeForNotifications() able to ignore child property changes

Open tom-pratt opened this issue 8 years ago • 10 comments

Goals

To be able to subscribe to a RealmCollection for updates but not trigger a notification if only some linked object is changed.

Say I have a RealmCollection of Things. I don't always want a notification if only one of the SubThings properties gets updated.

public class Thing : RealmObject
{
        public string Name { get; set; }
        public IList<SubThing> SubThings { get; }
}

Expected Results

The reason is that I might have recyclerview of Things. If a SubThing changes then a partial cell update should happen using normal data binding within the cell to the SubThing. If a Thing actually changes then I want to call adapter.NotifyDataSetChanged() or some variation on that. What I would consider an actual change would be either a Thing property changing, or the RealmList SubThings being modified (add, remove).

it would be nice to have the subscribe method something like.

RealmCollection.SubscribeForNotifications(Callback, notifyLinkedObjectUpdated: false)

tom-pratt avatar May 16 '17 13:05 tom-pratt

Related question from realm-cocoa

https://github.com/realm/realm-cocoa/issues/3704

tom-pratt avatar May 16 '17 14:05 tom-pratt

That cocoa issue highlights the issue a lot better than I did. Ignoring certain properties is the key.

My issue is that I would like it if you call also ignore properties on Linked objects.

tom-pratt avatar May 17 '17 09:05 tom-pratt

The idiosyncratic .NET approach would be to use INotifyCollectionChanged with combination of INotifyPropertyChanged - your adapter is concerned only with added/removed objects, and the cells themselves subscribe for object notifications and update their content.

While there's value in extending the SubscribeForNotifications API and allow skipping certain properties, to me it seems that adopting the XAML data binding approach would be a better long term solution.

I'll leave this issue open as a way to measure community interest and if we get enough requests/upvotes, we'll prioritize it.

nirinchev avatar May 23 '17 11:05 nirinchev

Hi thanks for the reply. Yes being able to bind to changing properties within a cell using INotifyPropertyChanged is very useful.

However a full cell update is more frequently the desired visual effect, both iOS and Android allow you to notify specific cells to be refreshed resulting in a short fade out and then fade back in with the new data.

Just updating view properties via normal data binding generally occurs with no animation and doesn't really look right for cells in most cases.

SubscribeForNotifications and ChangeSet seem to be better suited to dispatching cell updates in iOS and Android than INotifyCollectionChanged if you're not using Xamarin Forms.

tom-pratt avatar May 23 '17 14:05 tom-pratt

I like this idea.

UKDeveloper99 avatar May 30 '17 08:05 UKDeveloper99

+1

SureshSc avatar Nov 20 '17 09:11 SureshSc

+1

kevin-ponce avatar Nov 27 '17 03:11 kevin-ponce

+11111111111111

anysome avatar Apr 02 '18 08:04 anysome

+1

peterpaulis avatar Oct 13 '20 13:10 peterpaulis

The idiosyncratic .NET approach would be to use INotifyCollectionChanged with combination of INotifyPropertyChanged - your adapter is concerned only with added/removed objects, and the cells themselves subscribe for object notifications and update their content.

While there's value in extending the SubscribeForNotifications API and allow skipping certain properties, to me it seems that adopting the XAML data binding approach would be a better long term solution.

I'll leave this issue open as a way to measure community interest and if we get enough requests/upvotes, we'll prioritize it.

@nirinchev The Key Path Filtering for Change Notifications PR in Core could probably offer an alternative for this as soon as it is accepted and merged.

DominicFrei avatar Jun 01 '21 10:06 DominicFrei

+1 !!

I have found that changes to child (RealmObject) collections within a parent (RealmObject) cause our query subscription delegate to be invoked with ChangeSet.ModifiedIndices. This was unexpected by us, and it causes our layouts to re-initialize needlessly. We'd like to be able to selectively filter out these change notifications on a per-property basis, and it was confirmed to us that this feature would allow us to do that.

tele-bird avatar Aug 28 '23 19:08 tele-bird