package bindable
- Source
- package.scala
- Alphabetic
- By Inheritance
- bindable
- ToBindableSeqOps
- ToBindableOps
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
trait
Bindable[-From] extends Serializable
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 followingimport
statement:import com.thoughtworks.binding.bindable._
Then, a
@dom
XHTML template can establish data-binding on anyparameter
as long as a Bindable type class for theparameter
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 yourbuild.sbt
:addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.10.3")
ThemySection
method accepts any parameter who is a subtype ofBinding[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
Example: -
trait
BindableSeq[-From] extends Serializable
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 anyparameter
as long as a BindableSeq type class for theparameter
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 yourbuild.sbt
:addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.10.3")
ThemySection
method accepts any parameter who is a subtype ofBinding[Node]
orBinding[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 acceptsNode
,BindingSeq[Node]
,List[Node]
,Array[Node]
,js.Array[Node]
, orBinding[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
Example:
Value Members
- implicit def bindableToBinding[From, Value](from: From)(implicit bindable: Lt[From, Value]): Binding[Value]
-
implicit
def
toBindableOps[From](target: From)(implicit tc: Bindable[From]): Ops[From] { type TypeClassType = com.thoughtworks.binding.bindable.Bindable[From]{type Value = tc.Value} }
- Definition Classes
- ToBindableOps
- Annotations
- @SuppressWarnings()
-
implicit
def
toBindableSeqOps[From](target: From)(implicit tc: BindableSeq[From]): Ops[From] { type TypeClassType = com.thoughtworks.binding.bindable.BindableSeq[From]{type Value = tc.Value} }
- Definition Classes
- ToBindableSeqOps
- Annotations
- @SuppressWarnings()
- object Bindable extends LowPriorityBindable0 with Serializable
- object BindableSeq extends LowPriorityJsBindableSeq0 with Serializable