Skip to content

Commit fa58187

Browse files
committed
Add tests
1 parent defbb2b commit fa58187

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

js/js.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ enablePlugins(Example)
44

55
libraryDependencies += "com.thoughtworks.binding" %%% "jspromisebinding" % "12.0.0"
66

7+
libraryDependencies += "org.lrng.binding" %%% "html" % "1.0.3" % Optional
8+
79
addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.10.3")
810

911
requireJsDomEnv in Test := true

shared/src/main/scala/com/thoughtworks/binding/bindable/package.scala

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,57 @@ package bindable {
193193

194194
}
195195

196-
/** A dependent type class that witnesses a type that can be converted to a `BindingSeq[Value]`. */
196+
/** A dependent type class that witnesses a type that can be converted to a `BindingSeq[Value]`.
197+
*
198+
* @example This type class is internally used in the [[org.lrng.binding.html]] annotation, automatically converting
199+
* any compatible values into [[com.thoughtworks.binding.Binding.BindingSeq]], injecting into a HTML template.
200+
* {{{
201+
* import org.lrng.binding.html
202+
* import org.scalajs.dom._
203+
* @html
204+
* def myBinding = <span>Single Element</span>
205+
*
206+
* @html
207+
* def myBindingSeq = <span>Element 1</span><span>Element 2</span>
208+
*
209+
* @html
210+
* def myBindingOrBindingSeq(singleElement: Boolean) = {
211+
* if (singleElement) {
212+
* <span>Single Element</span>
213+
* } else {
214+
* <span>Element 1</span><span>Element 2</span>
215+
* }
216+
* }
217+
*
218+
* @html
219+
* def mySection = <section>
220+
* {myBinding.bind}
221+
* {myBinding}
222+
* {myBindingSeq}
223+
* {Binding{myBindingSeq.all.bind.toSeq}}
224+
* {myBindingSeq.all.bind.toSeq}
225+
* {myBindingOrBindingSeq(true)}
226+
* {myBindingOrBindingSeq(false)}
227+
* </section>
228+
*
229+
* val root = document.createElement("span")
230+
* html.render(root, mySection)
231+
*
232+
* root.innerHTML should be(
233+
* """<section>
234+
* <span>Single Element</span>
235+
* <span>Single Element</span>
236+
* <span>Element 1</span><span>Element 2</span>
237+
* <span>Element 1</span><span>Element 2</span>
238+
* <span>Element 1</span><span>Element 2</span>
239+
* <span>Single Element</span>
240+
* <span>Element 1</span><span>Element 2</span>
241+
* </section>"""
242+
* )
243+
* }}}
244+
*
245+
*
246+
*/
197247
@typeclass
198248
trait BindableSeq[-From] {
199249
type Value

0 commit comments

Comments
 (0)