基于论文Deprecating the Observer Pattern with Scala.React我试图从论文中设置一个简单的例子,但它抛出了一个异常Exception in thread "main" java.lang.AssertionError: assertion failed: This method must be run on its domain scala.react.NilDebug@1502c065
一个相关的问题是运行一个简单的 Scala.React 表达式。
如何设置一切以使用 scala react 库的强大功能?
除了库scala-react之外,我还使用了以下示例:
object MyFirstReact extends App {
object MyDomain extends scala.react.Domain {
protected val scheduler: Scheduler = new ManualScheduler
protected val engine: Engine = new Engine
}
import MyDomain._
case class MouseEvent(position: (Int, Int))
class Path(var positions: Seq[(Int, Int)]) {
def this(pos: (Int, Int)) = this(Seq(pos))
def lineTo(pos: (Int, Int)) { positions = positions :+ pos }
def close { positions = positions :+ positions.head }
}
val mouseDown: Events[MouseEvent] = Events.once(MouseEvent((0, 0)))
val mouseMove: Events[MouseEvent] = Events.once(MouseEvent((1, 1)))
val mouseUp: Events[MouseEvent] = Events.once(MouseEvent((2, 2)))
def draw(path: Path) { /* ... */ }
Reactor.loop { self =>
// step 1
val path = new Path((self await mouseDown).position)
self.loopUntil(mouseUp) { // step 2
val m = self awaitNext mouseMove
path.lineTo(m.position)
draw(path)
}
path.close // step 3
draw(path)
}
}