An experimental reactive library for lift web based on RxScala.
The core idea is to treat UI components as having three components:
- a UI component, e.g. an input element
- an Observable the UI component observes and maps to the UI, e.g. an Observable[String]
- an Observable of values produced by the component, e.g. an Observable[String]
This idea is modeled by RxComponent, which produces RxElements. RxComponents are factories that when given an Observable, return an RxElement that can be rendered in a browser.
This project uses Liftweb to render these RxElements. Have a look at the examples subproject for a demo.
The src is here
class Clock extends RxCometActor {
override def defaultPrefix = Full("clk")
// An Observable generating a string containing the time every 1 second
val ticker: Observable[String] = Observable.interval(Duration(1, TimeUnit.SECONDS)).map(_ ⇒ new Date().toString)
// using the label component, build an RxElement with the ticker
val timeLabel: RxElement[String] = Components.label.consume(ticker)
// send the JsCmds emitted by the label to the actor to send to the UI
publish(timeLabel)
// initial render uses the label's ui
def render = "#time" #> timeLabel.ui
}
Rendered with
<lift:comet type="Clock">
<p>Current Time: <span id="time">Missing Clock</span></p>
</lift:comet>