Thread
#compose
    amar_1995

    amar_1995

    2 years ago
    I am using
    +onCommit
    and it is working perfectly fine. But I am unable to understand when
    onDispose
    is called.
    var user : User? = null
            // Active type use-case
            +onCommit(1) {
                user = UserAPI.getUserData()
                onDispose {
                    UserAPI.letDiscompose() // It contains only println line
                }
            }
    Manuel Wrage

    Manuel Wrage

    2 years ago
    onDispose is called whenever the composable leaves the composition or the inputs have changed
    amar_1995

    amar_1995

    2 years ago
    Is there any working example? I am still unable to figure it out.
    Zsolt

    Zsolt

    2 years ago
    Composables methods that haven't changed are not re-run (recomposed) for efficiency. But once input values to the Composable method have changed, or stuff that you keep inside +state changed, or any other thing currently marked with the unary plus ("effect") has changed, then you really want to update to reflect new values, and invoke the Composable again (recompose). When that happens, you need to "clean up" the previous rendering, that's when onDispose gets called. (Also when the Composable is not updated but removed for good). In my understanding onCommit gets called on every recomposition, while onActive only gets called on the first one (please correct me if I'm wrong).
    amar_1995

    amar_1995

    2 years ago
    onActive is similar to onCommit when
    +onCommit(anyConst)
    or
    +onCommit(true)
    is used. I read somewhere onActive will be removed in future.
    I am this error while using onCommit
    java.lang.IllegalStateException: no stage finishing is allowed while read is disabled
    Any one know why ?