Skip to content

Commit 9b7356d

Browse files
committed
Merge commit '63956394cab9ff2f884ffb7bdb61dfd30cf06e4f' into template
# Conflicts: # project/plugins.sbt
2 parents 76f6cd8 + 6395639 commit 9b7356d

File tree

10 files changed

+408
-0
lines changed

10 files changed

+408
-0
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ addons:
77

88
language: scala
99

10+
scala:
11+
- 2.10.7
12+
- 2.11.12
13+
- 2.12.8
14+
1015
jdk:
1116
- oraclejdk8
1217

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 ThoughtWorks Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# bindable.scala
2+
[![Latest version](https://index.scala-lang.org/thoughtworksinc/bindable.scala/bindable/latest.svg)](https://index.scala-lang.org/thoughtworksinc/bindable.scala/bindable)
3+
[![Scaladoc](https://javadoc.io/badge/com.thoughtworks.binding/bindable_sjs0.6_2.12.svg?label=scaladoc)](https://javadoc.io/page/com.thoughtworks.binding/bindable_sjs0.6_2.12/latest/com/thoughtworks/binding/bindable/index.html)
4+
[![Build Status](https://travis-ci.org/ThoughtWorksInc/bindable.scala.svg)](https://travis-ci.org/ThoughtWorksInc/bindable.scala)
5+
6+
**bindable.scala** is a library of type classes for creating user-friendly [Binding.scala](https://github.com/ThoughtWorksInc/Binding.scala) components.
7+
8+
## Motivation
9+
10+
When creating a component that accepts parameters or “holes”, it is difficult to determine the types of those parameters.
11+
12+
For example, the following component accepts two `Binding` as parameters:
13+
14+
```scala
15+
@dom def myComponent1(title: Binding[String], children: Binding[BindingSeq[Node]]) = {
16+
<div title={title.bind}>
17+
{children.bind}
18+
</div>
19+
}
20+
```
21+
22+
By typing parameters as `Binding`s, `myComponent1` allows partial rendering whenever the value of `title` or `children` is changed. Unfortunately, it is too verbose to use `myComponent1` for simple use cases when the parameters are constants.
23+
24+
```scala
25+
// Does not compile
26+
@dom def myUseCases1 = myComponent1("My Title", <img/>).bind
27+
28+
// Compiles, but too verbose
29+
@dom def myUseCases2 = myComponent1(Constant("My Title"), Constant(Constants(<img/>))).bind
30+
```
31+
32+
In this library, we introduced two type classes, `Bindable` and `BindableSeq`, to allow heterogeneous types of parameters for a component.
33+
34+
## Usage
35+
36+
### Step 1: adding the following settings into your `build.sbt`
37+
38+
```sbt
39+
addCompilerPlugin("org.spire-math" %% "kind-projector" % "latest.release")
40+
41+
libraryDependencies += "com.thoughtworks.binding" %%% "bindable" % "latest.release"
42+
```
43+
44+
### Step 2: creating a component that accepts bindable parameters
45+
46+
```scala
47+
import com.thoughtworks.binding.bindable._
48+
import org.scalajs.dom.raw._
49+
@dom def myComponent2[Title: Bindable.Lt[?, String], Children: BindableSeq.Lt[?, Node]](title: Title, children: Children) = {
50+
<div title={title.bind}>
51+
{children.bindSeq}
52+
</div>
53+
}
54+
```
55+
56+
### Step 3: using the component with any parameters that can be converted to `Binding` or `BindingSeq`
57+
58+
59+
```scala
60+
import com.thoughtworks.binding._, Binding._
61+
@dom def myUseCases3 = myComponent2("My Title", <img/>).bind
62+
@dom def myUseCases4 = myComponent2(Constant("My Title"), Constant(Constants(<img/>))).bind
63+
@dom def myUseCases5 = myComponent2("My Title", <img/><img/>).bind
64+
@dom def myUseCases6 = myComponent2("My Title", Binding(<img/><img/>)).bind
65+
```
66+
67+
Unlike use cases of `myComponent1`, all the above use cases of `myComponent2` compile now, with the help of the `Bindable` and `BindableSeq` type classes.
68+
69+
## Links
70+
71+
* [Documentation](https://javadoc.io/page/com.thoughtworks.binding/bindable_sjs0.6_2.12/latest/com/thoughtworks/binding/bindable/index.html)
72+
* [Binding.scala](https://github.com/ThoughtWorksInc/Binding.scala)
73+
* [Limitations of the component model](https://github.com/ThoughtWorksInc/Binding.scala/issues/128)

build.sbt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Global / parallelExecution := false
2+
3+
publish / skip := true
4+
5+
organization in ThisBuild := "com.thoughtworks.binding"
6+
7+
lazy val bindable = crossProject in file(".")
8+
lazy val bindableJVM = bindable.jvm
9+
lazy val bindableJS = bindable.js

js/build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../shared/build.sbt

js/js.sbt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
enablePlugins(Example)
2+
3+
libraryDependencies += "com.thoughtworks.binding" %%% "dom" % "11.7.0" % Test
4+
5+
addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.9.10")
6+
7+
jsDependencies in Test += RuntimeDOM
8+
9+
inConfig(Test) {
10+
jsEnv := RhinoJSEnv().value
11+
}

jvm/build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../shared/build.sbt

project/plugins.sbt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@ addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2")
88

99
addSbtPlugin("org.lyranthe.sbt" % "partial-unification" % "1.1.2")
1010

11+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.27")
12+
13+
addSbtPlugin("com.thoughtworks.sbt-scala-js-map" % "sbt-scala-js-map" % "3.0.0")
14+
1115
addSbtPlugin("com.thoughtworks.example" % "sbt-example" % "6.0.1")
16+

shared/build.sbt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
libraryDependencies += "org.scalatest" %%% "scalatest" % "3.0.7" % Test
2+
3+
libraryDependencies += "com.thoughtworks.binding" %%% "binding" % "11.7.0"
4+
5+
libraryDependencies += "com.github.mpilquist" %%% "simulacrum" % "0.15.0"
6+
7+
libraryDependencies += "com.thoughtworks.enableIf" %% "enableif" % "1.1.6"
8+
9+
addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full)

0 commit comments

Comments
 (0)