2

我是reactivex的新手,并尝试将它与scala-swing一起使用。

我的代码很简单,但它不起作用:

import rx.lang.scala.Observable

import scala.swing.{Frame, MainFrame, SimpleSwingApplication, TextField}

object HelloReactiveX extends SimpleSwingApplication {

  val input = new TextField()

  override def top: Frame = new MainFrame {
    title = "Hello, reactivex"
    contents = input
  }

  val stream = Observable[String] { subscriber =>
    println("before input.subscribe")
    input.subscribe {
      case _ => {
        println("input changed: " + input.text)
        subscriber.onNext(input.text)
      }
    }
    println("after input.subscribe")
  }

  stream.subscribe(t => println("###: " + t))

}

依赖是:

"org.scala-lang.modules" %% "scala-swing" % "1.0.1",
"io.reactivex" %% "rxscala" % "0.25.0",

奇怪的是控制台上没有打印任何东西!

我的代码有什么问题吗?

PS:现场项目在这里https://github.com/freewind/scala-swing-demo/blob/fc79c5b65e6fecc21d3894888d336d8f5204f62e/src/main/scala/scalaswing/HelloReactiveX.scala

4

0 回答 0