It is evident that xstream, with the two methods addListener
and removeListener
, is able to reroute streams (change their sources and sinks) dynamically. I see no equivalent with mostjs. Does most only let you lay out the routing of the streams once? If so, is this static nature what allows mostjs to optimize for such superior performance?
Also, xstream uses an imitate
method that lets it feature circular dependencies. Is there any way to achieve circular dependency with mostjs?
There are many functions in most.js that operate on both a
Source
and aSink
, e.g.,map()
, which transforms all the events in a stream, acts as aSink
by consuming events, and as aSource
when producing new event values after applying a function to them.observe()
is an example of a particular kind ofSink
that consumes events, and passes them to a function you provide.Most.js
Streams
are not active until you consume them, by using one of the "terminal" combinators,observe
,drain
, orreduce
. When you call one of those, theStream
sends a signal in theSource-Sink
chain to theSource
at the very beginning of the chain. That producerSource
will then begin producing events.Events are then propagated synchronously from the
Source
through theSource-Sink
chain by a simple method call.Thus, you could provide your own "listener" function to a
map
which would transform the events.There are many factors contributing to most.js’s performance.
See this interview with Brian Cavalier
Most.js itself doesn’t handle circular dependencies, but it is totally possible using
most-proxy
. Motorcycle does this to create its cycle in itsrun
package.