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

Sorting CollectionDataProvider #48

Open
markkrenek opened this issue Nov 17, 2016 · 2 comments
Open

Sorting CollectionDataProvider #48

markkrenek opened this issue Nov 17, 2016 · 2 comments

Comments

@markkrenek
Copy link

What is the recommendation for sorting data when using a CollectionDataProvider? Do you have to use a different CollectionDataProvider or cache key for each possible sort order? Or maybe you maintain your own sorted list of objects that is updated whenever the CollectionDataProvider changes?

@plivesey
Copy link
Owner

If you use the same cacheKey, you'd end up overwriting your old versions of the data in the cache (and other data providers). I assume this isn't what you want. It sort of depends what you want here...is there 1 main order, and then you want to sort into multiple things on top of that?

If that's the case, I'd just write a wrapper on top of your data provider to provide a sort order (I think this is similar to your second idea).

Or, you could cache all the different sort orders with different keys. However, this means you won't get insertion/deletion updates because you no longer share the same cache key.

Hopefully that helps?

@markkrenek
Copy link
Author

Thanks. I ended up just sorting the data before calling setData. When the sort order needs to change, I just sort it and call setData again. My use case is pretty simple right now. I only have one view for displaying the data, so there are no conflicts with different data providers. I'm coming from Core Data, where you can have multiple NSFetchedResultsControllers each with different sorting, yet they all get notified when insertion/deletion/updates happen. When I need that functionality, I will need to revisit this. I'm trying RocketData to see if I can use it instead of Core Data or Realm. I like the lightweight nature of it and its immutable models. But I also realize it's not a real database like Core Data, so I might run into use cases that are difficult.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants