Skip to content

Instantly share code, notes, and snippets.

@tunjid
Created January 7, 2022 12:04
Show Gist options
  • Save tunjid/937352728fbcb96901447b293958fecb to your computer and use it in GitHub Desktop.
Save tunjid/937352728fbcb96901447b293958fecb to your computer and use it in GitHub Desktop.
internal class CalculatorStoreFactory(private val storeFactory: StoreFactory) {
fun create(): CalculatorStore =
object : CalculatorStore, Store<Intent, State, Nothing> by storeFactory.create(
name = "CounterStore",
initialState = State(),
reducer = ReducerImpl
) {
}
private object ReducerImpl : Reducer<State, Intent> {
override fun State.reduce(msg: Intent): State =
when (msg) {
is Intent.Increment -> copy(value = value + 1L)
is Intent.Decrement -> copy(value = value - 1L)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment