lukajcb / rxscala-js   0.15.2

Website GitHub

Scala idiomatic wrapper for RxJS

Scala versions: 2.12 2.11 2.10
Scala.js versions: 0.6

RxScala.js Build Status Scala.js Gitter Maven Central

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"))

Getting Started

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.

Javascript Dependencies

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"

Differences from RxJS

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]

Documentation

RxScala.js:

  • The API documentation can be found here.

RxJs:

If you're new to Rx, I suggest starting with this interactive tutorial.

Samples

Bugs and Feedback

For bugs, questions and discussions please use the Github Issues.

LICENSE

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.