u

    ursus

    3 years ago
    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

    3 years ago
    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

    3 years ago
    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

    3 years ago
    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

    3 years ago
    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