Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions js/js.sbt
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
22 changes: 21 additions & 1 deletion shared/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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] {
Expand All @@ -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]`.
Expand Down