https://kotlinlang.org logo
#android-architecture
Title
# android-architecture
u

ursus

05/07/2019, 9:07 PM
When in MVI what would you do a thing that has no diff? Like lets say some list of dynamically added buttons in a horizontal scroll view and you want to select one (and show border around it for example) by mvi it should be a click routed to viewmodel or wherever, where it copy mutates the state and emits a new tuple of list + selected index for example but now what, what about the list? only the index basically changed. Do you teardown the whole buttons list and recreate?
b

BMG

05/09/2019, 4:25 AM
Model would be like,
data class Model(val list: List<Item>, val selectedIndex: Int)
. So, here, I would just update the
selectedIndex
and return the model without touching the list.
And in my render methods, I would check for list diffs and issue appropriate
notify*
methods if there is any change in list from the model. (In the above case, it would not touch the list)
u

ursus

05/09/2019, 6:19 AM
Yes but in this case its not a recycler view but some linear layout with dynamically added views. Would you diff it manually?
b

BMG

05/09/2019, 6:54 AM
Yeah. Since I always have access to previous model in my
render(oldModel: Model, newModel: Model)
, I will diff it manually for those cases.
u

ursus

05/09/2019, 7:03 AM
Btw similar issue is edit text.. every char typed is new State(val text) emitted..and then edittext.text = state.text.. it spams edit text too much and typing lags
2 Views