Binding.scala • TodoMVC
See the codeBinding.scala is a data-binding framework for Scala, running on both JVM and Scala.js.
When combining with html.scala, Binding.scala can be used as a reactive web framework. It enables you use native XML literal syntax to create reactive DOM nodes, which are able to automatically change whenever the data source changes.
Binding.scala's TodoMVC application has the tiniest code size among all the TodoMVC implementations, only one source file, 154 lines of code!
/**
* Returns a bindable HTML DOM tree.
*
* The `html"""..."""` interpolation enables two magics:
* 1. HTML literals to create DOM nodes
* 2. `xxx.bind` syntax, which makes this DOM tree keep updated whenever `xxx` changes.
*/
def rootView = {
val value = Var("")
html"""<div>
<input onchange=${ (event: Event) => event.currentTarget.asInstanceOf[HTMLInputElement].value }/>
Your input value is ${ value.bind }
</div>"""
}
/**
* Renders a bindable HTML DOM node into the body of current web page.
*/
@JSExport def main(): Unit = {
render(document.body, rootView)
}
git clone https://github.com/ThoughtWorksInc/todo.gitsbt indexHtml at the base directory of this code base.index.html in your browser. Enjoy it! 😋Scala
100.0%
Binding.scala • TodoMVC
See the codeBinding.scala is a data-binding framework for Scala, running on both JVM and Scala.js.
When combining with html.scala, Binding.scala can be used as a reactive web framework. It enables you use native XML literal syntax to create reactive DOM nodes, which are able to automatically change whenever the data source changes.
Binding.scala's TodoMVC application has the tiniest code size among all the TodoMVC implementations, only one source file, 154 lines of code!
/**
* Returns a bindable HTML DOM tree.
*
* The `html"""..."""` interpolation enables two magics:
* 1. HTML literals to create DOM nodes
* 2. `xxx.bind` syntax, which makes this DOM tree keep updated whenever `xxx` changes.
*/
def rootView = {
val value = Var("")
html"""<div>
<input onchange=${ (event: Event) => event.currentTarget.asInstanceOf[HTMLInputElement].value }/>
Your input value is ${ value.bind }
</div>"""
}
/**
* Renders a bindable HTML DOM node into the body of current web page.
*/
@JSExport def main(): Unit = {
render(document.body, rootView)
}
git clone https://github.com/ThoughtWorksInc/todo.gitsbt indexHtml at the base directory of this code base.index.html in your browser. Enjoy it! 😋Scala
100.0%