Last active
August 29, 2015 14:21
-
-
Save zlangbert/7093e2f70c9e62e877b9 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
case class State(color: String) | |
class Backend($: BackendScope[Unit, State]) { | |
val ref = Ref[Input]("input") | |
def onChange(): Unit = { | |
changeColor() | |
} | |
def onClick(): Unit = { | |
changeColor() | |
ref($).get.getDOMNode().value += "hi" | |
} | |
def changeColor(): Unit = { | |
val newColor = $.state.color match { | |
case "blue" => "red" | |
case _ => "blue" | |
} | |
$.modState(_.copy(color = newColor)) | |
} | |
} | |
val TopLevel = ReactComponentB[Unit]("Top level component") | |
.initialState(State("blue")) | |
.backend(new Backend(_)) | |
.render((_, state, backend) => | |
div( | |
svg(width := 800, height := 100, | |
mcircle.circ(mcircle.Props(state.color, backend.onClick)) | |
), | |
input(ref := backend.ref, onChange --> backend.onChange) | |
) | |
) | |
.build |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment