stevdza-san / Paging3JetpackComposeDemo

133 stars 34 forks source link

is a amazing project,could you please tell me how to delete or update element in datasource? #4

Closed est7 closed 1 year ago

est7 commented 1 year ago

I've been update item in the ui layer like this:

 collectArticleEvent.observe(viewLifecycleOwner) { event ->
            detailsAdapter.snapshot().run {
                val index = indexOfFirst { it is Article && it.id == event.id }
                if (index >= 0) {
                    (this[index] as? Article)?.collect = event.isCollected
                    index
                } else null
            }?.apply(detailsAdapter::notifyItemChanged)
        }

but clean arch tell me UDF should let data control ui elements,so i want known how to delete/update element in data layer. Of course, the list should only be updated with the deleted or modified elements,How?This is really stuck on me

stevdza-san commented 1 year ago

I suggest you to directly interact with the data source, and then invalidate the paging source. Haven't done it personally, but you should try it out. Also check this link as well: https://stackoverflow.com/questions/63305182/paging3-pagingdataadapter-how-to-remove-item

est7 commented 1 year ago

@stevdza-san thanks, finally find it in google guide ,use combine :https://developer.android.google.cn/topic/architecture/ui-layer/state-production#one-shot-and