-
Notifications
You must be signed in to change notification settings - Fork 50
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
Get collectionChanges on setData #31
Comments
This has been a source of debate internally. The old way I had the API, it always called the delegate method and did not call the completion block. People hated this saying: "this doesn't make sense...I want it to call the completion block instead of the delegate". I agreed with this, so we changed it. However, I have thought about this and think that maybe it's good to offer this flexibility? But a few questions: In your network request code, you could just call the delegate yourself right? Would this solve your problem? |
@plivesey Oh! Now I understand. I figured there would be a single source of notification (the delegate). The current implementation makes sense too, though! To answer your questions:
I might be the only one that expected a notification, so I'd keep the current implementation for now. Maybe additional documentation would help clear this up for others in the future? Also, the library you linked looks promising! I have some array diffing code that I wrote, but might as well use this lib instead. 👍 Thanks @plivesey!! |
Actually now reading about it, initially I also thought that the delegate will be called after the first fetch. Having 2 places to get the same data seems redundant, but at the same time it might be useful to differentiate between an object that comes from a fetch and an object that comes from an update to the model. So one way to deal with this might be to have an enum
and include this enum in the delegate method as a parameter as well, and you wouldn't need to have a completion block for a Generally I vote for a single method to deliver all fetches and updates for a data provider (be it blocks or delegates), and a way to differentiate whether the data is coming from a fetch (ie cache) or an outside update to the model. |
This was similar to our original API, but it makes writing caching and networking code difficult. In theory it sounded great, but it was pretty unanimously disliked. For instance, this code gets really hard to write:
To do this fully correctly with a delegate method, you need to pass in a context and check that which is much uglier in code. If you want this functionality, you can subclass DataProvider yourself and provide your own delegate and implementation of these methods, but for the public API of this library, I prefer what we have now. |
Makes sense, thanks for the explanation! |
Let's say I have a network request that returns, and I call:
I expect
collectionDataProviderHasUpdatedData
to be called, but it isn't. How else should I get thecollectionChanges
?Right now, I'm updating my UI in three separate places instead of one:
fetchDataFromCache
(on view load),setData
(after network requests), andcollectionDataProviderHasUpdatedData
. 😵The text was updated successfully, but these errors were encountered: