Skip to content

Instantly share code, notes, and snippets.

@manuelleduc

manuelleduc/Counter.scala Secret

Created Feb 15, 2018
Embed
What would you like to do?
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