yousuf-haque / TodoMvi

An Mvi implementation of a TODO app that focuses on asynchronous operations that have high potentials of failure
34 stars 5 forks source link

How would you handle pagination? #1

Open JolandaVerhoef opened 6 years ago

JolandaVerhoef commented 6 years ago

I love you Droidcon NYC presentation! Now I'm trying to slowly move towards your MVI implementation. But I'm stuck trying to implement pagination in one of the data calls. It's hard to keep track of the current page in the stream-way of thinking. Do you have any suggestion on how this would be done in your sample code?

yousuf-haque commented 6 years ago

Hi @JolandaVerhoef !

That's a really good question! I'd make an intent for loadNextPage, and a property of loadedPages on the state. I would then have the view layer send the intent into the model layer. The Model layer would read that intent, check which pages have already been loaded according to the current state, and I would issue a new call to get the next page and mutate oldState to include adding the new page of results.

As you page, the data on the state itself would grow, and the state would contain the union of all loaded pages. At that point, it would be the view layer's responsibility to show a subset of the loaded pages.