Description
We have a data source that serves the data from an actual server implementing some sort of pagination. It means that we can access the data using an offset and count, which maps the ui-scroll data source requirements.
The problem arises with updates. Suppose that we want to delete the element №3. From the database standpoint, all the elements accessed with a 3+ index should now be accessed with that index minus one (the №4 now becomes №3)
From a ui-scroll standpoint, we do 2 things:
- we call applyUpdate(3,[]) to get the element removed
- we call applyUpdate( updater() ) to reload all the elements currently in the buffer, because what is at index n is now what was at index n+1, so the buffer does not hold the proper items
But this is not enough as buffer.first is not decremented when the removed element is < buffer.first. Thus, if we remove multiple rows, this can lead to a situation where buffer.first > number of elements, which confuses ui-scroll (it displays blank data)
Also, if we remove the first element, maxIndex stays the same while minIndex is incremented, which is obviously not what is desired in our use case.
We finally got it work, but I consider our solution 'fragile', as it can break if some implementation details change. What would be your advise to support our use case?
We can add new methods to the adapter like:
- insertItems(index,n)
- removeItems(index,n)
These methods will update the buffer accordingly (first, maxIndex) and will update the items in the buffer by calling the datasource (or through an updater function?)