Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Atry committed Nov 6, 2021
1 parent defbb2b commit fa58187
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 2 additions & 0 deletions js/js.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ enablePlugins(Example)

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

libraryDependencies += "org.lrng.binding" %%% "html" % "1.0.3" % Optional

addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.10.3")

requireJsDomEnv in Test := true
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,57 @@ package bindable {

}

/** 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]`.
*
* @example This type class is internally used in the [[org.lrng.binding.html]] annotation, automatically converting
* any compatible values into [[com.thoughtworks.binding.Binding.BindingSeq]], injecting into a HTML template.
* {{{
* import org.lrng.binding.html
* import org.scalajs.dom._
* @html
* def myBinding = <span>Single Element</span>
*
* @html
* def myBindingSeq = <span>Element 1</span><span>Element 2</span>
*
* @html
* def myBindingOrBindingSeq(singleElement: Boolean) = {
* if (singleElement) {
* <span>Single Element</span>
* } else {
* <span>Element 1</span><span>Element 2</span>
* }
* }
*
* @html
* def mySection = <section>
* {myBinding.bind}
* {myBinding}
* {myBindingSeq}
* {Binding{myBindingSeq.all.bind.toSeq}}
* {myBindingSeq.all.bind.toSeq}
* {myBindingOrBindingSeq(true)}
* {myBindingOrBindingSeq(false)}
* </section>
*
* val root = document.createElement("span")
* html.render(root, mySection)
*
* root.innerHTML should be(
* """<section>
* <span>Single Element</span>
* <span>Single Element</span>
* <span>Element 1</span><span>Element 2</span>
* <span>Element 1</span><span>Element 2</span>
* <span>Element 1</span><span>Element 2</span>
* <span>Single Element</span>
* <span>Element 1</span><span>Element 2</span>
* </section>"""
* )
* }}}
*
*
*/
@typeclass
trait BindableSeq[-From] {
type Value
Expand Down

0 comments on commit fa58187

Please sign in to comment.