ThoughtWorksInc / Binding.scala

Reactive data-binding for Scala
https://javadoc.io/page/com.thoughtworks.binding/binding_2.13/latest/com/thoughtworks/binding/index.html
MIT License
1.59k stars 108 forks source link

Referring to non-existent method com.thoughtworks.binding.FutureBinding$.apply(scala.concurrent.Future,scala.concurrent.ExecutionContext) #204

Closed seveniruby closed 5 years ago

seveniruby commented 5 years ago

i use github demo https://scalafiddle.io/sf/TKPExZE/4 , and invoke it use another object, then i get an error

[error] involving instantiated classes:
[error] Github$
[error] App$
[error] Referring to non-existent method com.thoughtworks.binding.FutureBinding$.apply(scala.concurrent.Future,scala.concurrent.ExecutionContext)com.thoughtworks.binding.FutureBinding

Github.scala

import scalajs.js

//@js.annotation.JSExport
object Github {
  // $FiddleStart
  import com.thoughtworks.binding.dom
  import com.thoughtworks.binding.FutureBinding
  import com.thoughtworks.binding.Binding.Var

  import org.scalajs.dom.document
  import org.scalajs.dom.raw.Event
  import org.scalajs.dom.html.Input
  import org.scalajs.dom.ext.Ajax

  import scala.scalajs.js
  import scala.scalajs.js.JSON
  import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue
  import scala.util.{ Failure, Success }

  import scalaz.std.list._

  @dom def render = {
    val githubUserName = Var("")
    def inputHandler = { event: Event => githubUserName := event.currentTarget.asInstanceOf[Input].value }
    <div>
      <h3>
        This DEMO displaces the avatar of a Github user,
        <br/>
        along with names of organizations belong to that user
      </h3>
      <hr/>
      <input type="text" oninput={ inputHandler }/>
      <hr/>
      {
      val name = githubUserName.bind
      if (name == "") {
        <div>Please input your Github user name</div>
      } else {
        val githubResult = FutureBinding(Ajax.get(s"https://api.github.com/users/${name}")) // 发起 Github API 请求,
        githubResult.bind match {
          case None =>
            <div>Loading the avatar for { name }</div>
          case Some(Failure(exception)) =>
            <div>{ exception.toString }</div>
          case Some(Success(response)) =>
            val user = JSON.parse(response.responseText)
            <div>
              <img src={ user.avatar_url.toString }/>
              {
              FutureBinding(Ajax.get(user.organizations_url.toString)).bind match {
                case None =>
                  <div>Loading organization list for { name }</div>
                case Some(Failure(exception)) =>
                  <div>{ exception.toString }</div>
                case Some(Success(response)) =>
                  <ul>{
                    val organizationList = JSON.parse(response.responseText).asInstanceOf[js.Array[js.Dynamic]].toList
                    for (organizationSummary <- organizationList) yield <li>{
                      FutureBinding(Ajax.get(organizationSummary.url.toString)).bind match {
                        case None =>
                          <div>{ organizationSummary.login.toString }</div>
                        case Some(Failure(exception)) =>
                          <div>{ exception.toString }</div>
                        case Some(Success(response)) =>
                          val organization = JSON.parse(response.responseText)
                          <div>{
                            if (js.isUndefined(organization.name)) {
                              organization.login.toString
                            } else {
                              organization.name.toString
                            }
                            }</div>
                      }
                      }</li>
                    }</ul>
              }
              }
            </div>
        }
      }
      }
    </div>
  }

  def main2(): Unit = {

    dom.render(document.body, render)
    // $FiddleEnd

  }

}

App.scala

object App {
  def main(args: Array[String]): Unit = {
    Github.main2()
  }

}

sbt配置

enablePlugins(ScalaJSPlugin)

name := "binding"

version := "0.1"

scalaVersion := "2.12.9"

scalaJSUseMainModuleInitializer := true

libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "0.9.7"
libraryDependencies += "com.thoughtworks.binding" %% "binding" % "latest.release"
libraryDependencies += "com.thoughtworks.binding" %% "futurebinding" % "latest.release"
libraryDependencies += "com.thoughtworks.binding" %%% "dom" % "latest.release"

addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full)
seveniruby commented 5 years ago

just change to scala.js

libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "0.9.7"
libraryDependencies += "com.thoughtworks.binding" %%% "binding" % "latest.release"
libraryDependencies += "com.thoughtworks.binding" %%% "futurebinding" % "latest.release"
libraryDependencies += "com.thoughtworks.binding" %%% "dom" % "latest.release"