Skip to content
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

Add support for keypath filtering for notifications #1398

Closed
tom-pratt opened this issue May 16, 2017 · 11 comments
Closed

Add support for keypath filtering for notifications #1398

tom-pratt opened this issue May 16, 2017 · 11 comments

Comments

@tom-pratt
Copy link

tom-pratt commented May 16, 2017

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
Copy link
Author

tom-pratt commented May 16, 2017

Related question from realm-cocoa

realm/realm-swift#3704

@tom-pratt
Copy link
Author

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.

@nirinchev
Copy link
Member

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.

@tom-pratt
Copy link
Author

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.

@UKDeveloper99
Copy link

I like this idea.

@SureshSc
Copy link

+1

1 similar comment
@kevin-ponce
Copy link

+1

@anysome
Copy link

anysome commented Apr 2, 2018

+11111111111111

@peterpaulis
Copy link

+1

@DominicFrei
Copy link
Contributor

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 DominicFrei self-assigned this Jun 2, 2021
@DominicFrei DominicFrei added the Blocked This issue is blocked by another issue label Jun 2, 2021
@DominicFrei DominicFrei removed their assignment Mar 28, 2022
@sync-by-unito sync-by-unito bot changed the title RealmCollection.SubscribeForNotifications() able to ignore child property changes Add support for keypath filtering for notifications Aug 14, 2023
@nirinchev nirinchev removed the Blocked This issue is blocked by another issue label Aug 22, 2023
@tele-bird
Copy link

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

@sync-by-unito sync-by-unito bot closed this as completed Feb 9, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests