react-native-realm icon indicating copy to clipboard operation
react-native-realm copied to clipboard

Support listener for specific collection using filtered and sort

Open ferrannp opened this issue 7 years ago • 1 comments

Hi! Thanks for this little wrapper, very useful! What do you think of supporting:

realm.objects('Dog').filtered('age < 2').addListener((puppies, changes) => {
  ...
});

This is explained here https://realm.io/docs/javascript/latest/#collection-notifications. I have been trying it and the main problem I encountered is that I could not remove the listeners at all (thus, my component was trying to update even when it was unmounted).

ferrannp avatar Aug 03 '17 20:08 ferrannp

Hey @ferrannp that's a great idea. I've actually been mulling this over as a nice optimization for the project I'm working on. For the most part I don't really care about getting all the data in the realm for a certain schema. Most of my components end up filtering the results in the mapToProps function, but I'm sure things could be better optimized if we could add filtering earlier up the chain, like when defining the schemas which you wanted to listen to.

I assume that you are wanting to react to the changes argument in your code sample above? Do you have any ideas for changes to the libraries API so that this functionality could be cleanly added?

jasonmerino avatar Aug 08 '17 03:08 jasonmerino