This is a Scala adapter to RxJs.
Example usage:
val o = Observable.interval(200).take(5)
o.subscribe(n => println("n = " + n))
Observable.just(1, 2, 3, 4).reduce(_ + _)
Example usage in Browser:
Observable.fromEvent(document.getElementById("btn"),"click")
.mapTo(1)
.scan(0)(_ + _)
.subscribe(n => println(s"Clicked $n times"))
Add the following to your sbt build definition:
libraryDependencies += "com.github.lukajcb" %%% "rxscala-js" % "0.15.0"
then import the types from the package rxscalajs
.
RxScala.js doesn't actually come bundled with the underlying rx.js
file, so you'll need to either add them manually or specify them as jsDependencies
:
jsDependencies += "org.webjars.npm" % "rxjs" % "5.4.0" / "bundles/Rx.min.js" commonJSName "Rx"
Similary to RxScala, this wrapper attempts to expose an API which is as Scala-idiomatic as possible. Some examples:
// instead of concat:
def ++[U >: T](that: Observable[U]): Observable[U]
// curried in Scala collections, so curry fold also here:
def foldLeft[R](seed: R)(accumulator: (R, T) => R): Observable[R]
// called skip in RxJS, but drop in Scala
def drop(n: Int): Observable[T]
// like in the collection API
def zipWithIndex: Observable[(T, Int)]
// the implicit evidence argument ensures that switch can only be called on Observables of Observables:
def switch[U](implicit evidence: Observable[T] <:< Observable[Observable[U]]): Observable[U]
RxScala.js:
- The API documentation can be found here.
RxJs:
If you're new to Rx, I suggest starting with this interactive tutorial.
- The basics - How to use some of the most important operations in RxScala.js
- Spaceship Reactive - A port of Spaceship Reactive found in Sergi Mansillas awesome book Reactive Programming with RxJS. Code can be found here.
- RxScala.js as a state store - A basic example on how to write a simple state store with RxScala.js. (Find the working example here)
For bugs, questions and discussions please use the Github Issues.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.