-
Notifications
You must be signed in to change notification settings - Fork 108
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
Dealing with updates. Is it possible not to touch min index? #229
Comments
@priandsf I would split the discussion onto two parts: on items indexes shifting and on buffer borders shifting. For the first point, I would say that the indexes part of the game should be played on the data side, outside the ui-scroll. And the issue becomes a matter of proper data structuring and proper data flowing. We have one pretty complex demo related to discussed situation, link. The remove method on the frontend does almost nothing but return [] for a given index via For the second point, yes, currently we are limited by how the ui-scroll is implemented. When you remove an item via In addition, you mentioned server-side pagination, I'd like you to look at this sample which can be useful. It shows how we can implement a layer connecting index-count API of the ui-scroll and pages API of the external datasource. |
Thanks for your reply @dhilt , as ever! I agree that these are 2 different points, although they are somewhat related. Both deal with a datasource which is a mutable array of data, with a fixed first index (generally #0). I believe that this is quite a common use case when displaying data coming from a server. 1- I looked at the sample you mentioned and it makes sense, although the use case is a bit different: in the example case, an index is assigned to every single element and it is immutable. In our case, the element index depends on the position in the dataset, and can vary when elements are inserted or removed. Having an immutable index implies maintaining a map between the elements and the indexes, which is a bit complex. 2- For the second issue, updating |
@priandsf May I ask you to try immutable-top branch? It provides |
v1.7.6 had been released, I also added |
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:
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:
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?)
The text was updated successfully, but these errors were encountered: