Skip to content

Improve working with sealed class states #197

@Rosomack

Description

@Rosomack

Currently, working with states that are sealed classes requires lots of casting. Investigate if we can create a DSL that would help this.

Primary things to figure out:

  • What happens if the state does not match the expected type?
    • Crash or fail silently
    • What should be the default here
    • Should this behaviour be controllable?

Some random thoughts of how we could help by adding new DSL methods

private fun setExampleDataIntent() = intentForState<ExampleState.Success> {
    reduce {
        state.copy(
            firstName = "John",
            lastName = "Doe",
            age = 18
        )
    }
    println(state.age) // 18
}

OR

private fun setExampleDataIntent() = intent {

    withSubstate<ExampleState.Success>(throwOnMismatch=true) {
         reduce {
             state.copy(
                  firstName = "John",
                  lastName = "Doe",
                  age = 18
             )
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions