Skip to content

Instantly share code, notes, and snippets.

@manuelleduc
Created February 15, 2018 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manuelleduc/09f8ab568f2d9fbb55fed628ad75d83b to your computer and use it in GitHub Desktop.
Save manuelleduc/09f8ab568f2d9fbb55fed628ad75d83b to your computer and use it in GitHub Desktop.
package scalm.counter
import org.scalajs.dom.document
import scalm.Html._
import scalm.{Html, Scalm}
object Counter {
type Model = Int
def start(): Unit = Scalm.start(document.body)(init, update, view)
def init: Model = 0
def update(msg: Msg, model: Model): Model =
msg match {
case Increment => model + 1
case Decrement => model - 1
}
def view(model: Model): Html[Msg] =
div()(
button(onClick(Decrement))(text("-")),
div()(text(model.toString)),
button(onClick(Increment))(text("+"))
)
sealed trait Msg
case object Increment extends Msg
case object Decrement extends Msg
}
object TestCounter extends App {
Counter.start()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment