diff --git a/js/js.sbt b/js/js.sbt index eb7d091..c5784c5 100644 --- a/js/js.sbt +++ b/js/js.sbt @@ -1,5 +1,7 @@ enablePlugins(Example) +libraryDependencies += "com.thoughtworks.binding" %%% "jspromisebinding" % "11.7.0+144-dfef7165" + libraryDependencies += "com.thoughtworks.binding" %%% "dom" % "11.7.0" % Test addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.9.10") diff --git a/shared/build.sbt b/shared/build.sbt index 2e983f7..d04a141 100644 --- a/shared/build.sbt +++ b/shared/build.sbt @@ -2,8 +2,28 @@ libraryDependencies += "org.scalatest" %%% "scalatest" % "3.0.7" % Test libraryDependencies += "com.thoughtworks.binding" %%% "binding" % "11.7.0" +libraryDependencies += "com.thoughtworks.binding" %%% "futurebinding" % "11.7.0" + libraryDependencies += "com.github.mpilquist" %%% "simulacrum" % "0.15.0" libraryDependencies += "com.thoughtworks.enableIf" %% "enableif" % "1.1.6" -addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full) +// Enable macro annotation by scalac flags for Scala 2.13 +scalacOptions ++= { + import Ordering.Implicits._ + if (VersionNumber(scalaVersion.value).numbers >= Seq(2L, 13L)) { + Some("-Ymacro-annotations") + } else { + None + } +} + +// Enable macro annotation by compiler plugins for Scala 2.12 +libraryDependencies ++= { + import Ordering.Implicits._ + if (VersionNumber(scalaVersion.value).numbers >= Seq(2L, 13L)) { + None + } else { + Some(compilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full)) + } +} 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 93baeeb..fa67a04 100644 --- a/shared/src/main/scala/com/thoughtworks/binding/bindable/package.scala +++ b/shared/src/main/scala/com/thoughtworks/binding/bindable/package.scala @@ -1,6 +1,8 @@ package com.thoughtworks.binding +import com.thoughtworks.binding._ import com.thoughtworks.binding.Binding._ +import com.thoughtworks.enableIf import simulacrum._ import scala.language.implicitConversions @@ -47,6 +49,9 @@ package bindable { import Jvm._ import Js._ + import scala.concurrent.{ExecutionContext, Future} + import scala.util.Try + private[bindable] trait LowPriorityBindable0 { implicit def constantBindable[Value0]: Bindable.Aux[Value0, Value0] = new Bindable[Value0] { @@ -69,6 +74,21 @@ package bindable { def toBinding(from: Binding[Value0]): Binding[Value] = from } + implicit def futureBindable[Value0]( + implicit executionContext: ExecutionContext): Bindable.Aux[Future[Value0], Option[Try[Value0]]] = + new Bindable[Future[Value0]] { + type Value = Option[Try[Value0]] + def toBinding(from: Future[Value0]): Binding[Value] = FutureBinding(from) + } + + @enableIf(c => c.compilerSettings.exists(_.matches("""^-Xplugin:.*scalajs-compiler_[0-9\.\-]*\.jar$"""))) + implicit def thenableBindable[Value0] + : Bindable.Aux[scala.scalajs.js.Thenable[Value0], Option[Either[Any, Value0]]] = + new Bindable[scala.scalajs.js.Thenable[Value0]] { + type Value = Option[Either[Any, Value0]] + def toBinding(from: scala.scalajs.js.Thenable[Value0]): Binding[Value] = JsPromiseBinding(from) + } + } /** A dependent type class that witnesses a type that can be converted to a `Binding[Value]`.