Scala.js interface to XStream.js, a simple functional reactive stream library
XStream.scala is a Scala.js interface to XStream.js, an extremely intuitive, small, and fast functional reactive stream library for JavaScript.
XStream is notably used in Cycle.js, an honestly functional and reactive JavaScript framework.
"com.raquo.xstream" %%% "xstream" % "0.3.1"
It’s simple and lightweight. It makes the most sense when the developer does not typically subscribe
to streams manually. See these posts from the creator of XStream.js:
See XStream.js docs. XStream.scala retains original XStream.js classes and method names with only a few deviations that are easily discoverable with code autocompletion or (less conveniently) by looking in the code.
Notably, class Stream
is named XStream
in my interface to avoid the inconvenience of sharing the name with scala.collection.immutable.Stream
.
When mapping over a stream of tuples, you can use map
methods from TupleStream<N>
implicit classes to avoid the need for boilerplate or partial functions.
Per XStream.js docs, you should normally avoid using shamefullySend*
methods, so in order to use them you need to explicitly create an instance of ShamefulStream
. It is a value class, so normally the instantiation does not actually happen at runtime, thus there is no runtime penalty to it.
You should not need to use RawXStream
directly, use the XStream
object instead.
In XStream.js/Cycle.js, a common convention is to name stream variables with trailing dollar signs, e.g. response$
for a stream of responses. In Scala.js this naming sometimes causes a weird compilation error. I’m not sure why exactly, but I think it might have something to do with Scala’s or Scala.js’ internal representation making use of trailing dollar signs as well. I will try to figure this out some day, for now I personally prepend $
instead, e.g. $response
for a stream of responses. Although if you use jQuery maybe go for a responseStream
instead to avoid the confusion.
XStream
being actually covariant in T
. imitate
method seems to violate it, but its use case is also extremely limited to creating proxies. Find a compromise.XStream.of
should accept multiple paramsNikita Gazarov – raquo.com
XStream.scala is provided under the MIT license.
XStream.scala is a Scala.js interface to XStream.js, which we use under the terms of its MIT license.