From fa581878ae4dbcd850c570cfa97b881234b40a8f Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Sat, 6 Nov 2021 09:50:00 -0700 Subject: [PATCH] Add tests --- js/js.sbt | 2 + .../binding/bindable/package.scala | 52 ++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/js/js.sbt b/js/js.sbt index 0ee79b9..5602d83 100644 --- a/js/js.sbt +++ b/js/js.sbt @@ -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 diff --git a/shared/src/main/scala/com/thoughtworks/binding/bindable/package.scala b/shared/src/main/scala/com/thoughtworks/binding/bindable/package.scala index 0321a0d..8a09a7a 100644 --- a/shared/src/main/scala/com/thoughtworks/binding/bindable/package.scala +++ b/shared/src/main/scala/com/thoughtworks/binding/bindable/package.scala @@ -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 = Single Element + * + * @html + * def myBindingSeq = Element 1Element 2 + * + * @html + * def myBindingOrBindingSeq(singleElement: Boolean) = { + * if (singleElement) { + * Single Element + * } else { + * Element 1Element 2 + * } + * } + * + * @html + * def mySection =
+ * {myBinding.bind} + * {myBinding} + * {myBindingSeq} + * {Binding{myBindingSeq.all.bind.toSeq}} + * {myBindingSeq.all.bind.toSeq} + * {myBindingOrBindingSeq(true)} + * {myBindingOrBindingSeq(false)} + *
+ * + * val root = document.createElement("span") + * html.render(root, mySection) + * + * root.innerHTML should be( + * """
+ * Single Element + * Single Element + * Element 1Element 2 + * Element 1Element 2 + * Element 1Element 2 + * Single Element + * Element 1Element 2 + *
""" + * ) + * }}} + * + * + */ @typeclass trait BindableSeq[-From] { type Value