Last active
June 26, 2020 20:51
-
-
Save fponticelli/9e611614663a28297e8440e641231c47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kempo.Reducer | |
import kempo.el | |
data class State( | |
val name: String, | |
val counter: Int = 0 | |
) { | |
fun withName(name: String) = State(name, counter) | |
fun withCounter(counter: Int) = State(name, counter) | |
} | |
val template = el<State, State, Unit> { | |
className("my-class") | |
+"Hello " | |
el("button") { | |
onClick { state: State -> state.withCounter(state.counter + 1) } | |
text { it.name } | |
} | |
+" " | |
text { it.counter.toString() } | |
} | |
fun main() { | |
kempo.run(template, State( | |
name = "Franco Small" | |
)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kempo.Reducer | |
import kempo.el | |
data class State( | |
val name: String, | |
val counter: Int = 0 | |
) { | |
fun withName(name: String) = State(name, counter) | |
fun withCounter(counter: Int) = State(name, counter) | |
} | |
sealed class Action { | |
object Increment : Action() | |
} | |
val template = el<State, Action, Unit> { | |
className("my-class") | |
+"Hello " | |
el("button") { | |
onClick { -> Action.Increment } | |
text { it.name } | |
} | |
+" " | |
text { it.counter.toString() } | |
} | |
val reducer: Reducer<State, Action> = { state, action -> | |
when (action) { | |
is Action.Increment -> state.withCounter(state.counter + 1) | |
} | |
} | |
fun main() { | |
kempo.run(template, reducer, State( | |
name = "Franco Small" | |
)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment