A dependent type class that witnesses a type that can be converted to a Binding[Value]
.
A dependent type class that witnesses a type that can be converted to a Binding[Value]
.
The implicit conversion to Binding
can be enabled by the following import
statement:
import com.thoughtworks.binding.bindable._
Then, a @dom
XHTML template can establish data-binding on any parameter
as long as a Bindable type class for the parameter
type is available.
@dom def mySection[A: Bindable.Lt[?, String]](parameter: A) = { <img class={parameter.bind}/> }
Note that the ?
syntax requires the Scala plug-in
kind-projector,
which can be enabled by adding the following setting into your build.sbt
:
addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.9.10")The
mySection
method accepts any parameter who is a subtype of Binding[String]
.import com.thoughtworks.binding._, Binding._ Binding { mySection(Binding("my-class-1")).bind.className should be("my-class-1") mySection(Constant("my-class-2")).bind.className should be("my-class-2") }.watch()
And the mySection
method also accepts String parameter.
Binding { mySection("my-class-3").bind.className should be("my-class-3") }.watch()
mySection
should not accept irrelevant parameter types like scala.List or scala.Int.
"mySection(List.empty)" shouldNot compile "mySection(42)" shouldNot compile
A dependent type class that witnesses a type that can be converted to a BindingSeq[Value]
.
A dependent type class that witnesses a type that can be converted to a BindingSeq[Value]
.
The bindSeq
can be enabled by the following import
statement:
import com.thoughtworks.binding.bindable._
Then, a @dom
XHTML template can establish data-binding on any parameter
as long as a BindableSeq type class for the parameter
type is available.
import org.scalajs.dom.raw._ @dom def mySection[A: BindableSeq.Lt[?, Node]](parameter: A) = { <section>{parameter.bindSeq}</section> }
Note that the ?
syntax requires the Scala plug-in
kind-projector,
which can be enabled by adding the following setting into your build.sbt
:
addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.9.10")The
mySection
method accepts any parameter who is a subtype of Binding[Node]
or Binding[BindingSeq[Node]]
.import com.thoughtworks.binding._, Binding._ @dom def myButton: Binding[HTMLButtonElement] = <button type="button">My Button 0</button> @dom def myButtons: Binding[BindingSeq[Node]] = <button type="button">My Button 1</button><button type="button">My Button 2</button> Binding { mySection(myButton).bind.innerHTML should be("") mySection(myButtons).bind.innerHTML should be("") }.watch()
And the mySection
method also accepts Node
, BindingSeq[Node]
, List[Node]
, Array[Node]
, js.Array[Node]
, or Binding[js.Array[Node]]
parameter.
import scala.scalajs.js @dom def test = { mySection(<button type="button">My Button 3</button>).bind.innerHTML should be("") mySection(<button type="button">My Button 4</button><button type="button">My Button 5</button>).bind.innerHTML should be( "" ) mySection(List(<button type="button">My Button 6</button>, <button type="button">My Button 7</button>)).bind.innerHTML should be("") mySection(Array(<button type="button">My Button 8</button>, <button type="button">My Button 9</button>)).bind.innerHTML should be("") mySection(js.Array(<button type="button">My Button 10</button>, <button type="button">My Button 11</button>)).bind.innerHTML should be("") mySection(Constant(js.Array(<button type="button">My Button 12</button>, <button type="button">My Button 13</button>))).bind.innerHTML should be("") } test.watch()
mySection
should not accept irrelevant parameter types like scala.collection.immutable.Set or scala.Int.
"mySection(Set.empty)" shouldNot compile "mySection(42)" shouldNot compile