Skip to content

Commit

Permalink
Using StateMachine transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
ubiratansoares committed Jul 21, 2019
1 parent c9dc26e commit d71cc16
Showing 1 changed file with 5 additions and 5 deletions.
@@ -1,6 +1,7 @@
package io.dotanuki.norris.onboarding

import io.dotanuki.norris.architecture.StateMachine
import io.dotanuki.norris.architecture.StateTransition
import io.dotanuki.norris.architecture.UnsupportedUserInteraction
import io.dotanuki.norris.architecture.UserInteraction
import io.dotanuki.norris.architecture.UserInteraction.OpenedScreen
Expand All @@ -14,14 +15,13 @@ class OnboardingViewModel(
fun bind() = machine.states()

fun handle(interaction: UserInteraction) =
interpret(interaction)
.let { task ->
machine.forward(task)
}
interpret(interaction).let {
machine.consume(it)
}

private fun interpret(interaction: UserInteraction) =
when (interaction) {
is OpenedScreen -> ::fetchCategories
is OpenedScreen -> StateTransition(::fetchCategories)
else -> throw UnsupportedUserInteraction
}

Expand Down

0 comments on commit d71cc16

Please sign in to comment.