Thread
#compose
    n

    nglauber

    1 year ago
    Having in mind a form with 10 fields (for instance) of different types (text, radio button, checkbox, combobox, … ). What do you folks think is the best approach?1️⃣ Expose one Flow/LiveData for each field in ViewModel and collect/observe them individually in the screen.2️⃣ Expose one
    State
    for each field in ViewModel and simply access them from the screen.3️⃣ Encapsulate these 10 fields in a data class, expose one single Flow/LiveData and each “setter” create a
    copy
    of this data class instance to update the state.4️⃣ Encapsulate these 10 fields in a data class, each field is a state, ViewModel has an instance of this class and you simply access it from the screen.5️⃣ Other (please explain)
    I’m currently using 3️⃣ because I don’t want my viewmodel depends on Compose classes (State).
    Colton Idle

    Colton Idle

    1 year ago
    A single state class with multiple mutable state ofs
    t

    tad

    1 year ago
    Been migrating from Flow to snapshot state (^), this is the way to go for sure
    Oleg Khotskin

    Oleg Khotskin

    1 year ago
    Flow/StateFlow are not great as observable properties, their asynchrony can lead to unexpected behavior. See https://github.com/Kotlin/kotlinx.coroutines/issues/2280 for more information.
    gildor

    gildor

    1 year ago
    Flow/StateFlow are not great as observable properties
    It’s completely fine behaviour for observable property, otherwise you will get all those “unexpected behavior” not when you do this syncronously, but when you do this asyncronously