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
Sourceand aSink, e.g.,map(), which transforms all the events in a stream, acts as aSinkby consuming events, and as aSourcewhen producing new event values after applying a function to them.observe()is an example of a particular kind ofSinkthat consumes events, and passes them to a function you provide.Most.js
Streamsare not active until you consume them, by using one of the "terminal" combinators,observe,drain, orreduce. When you call one of those, theStreamsends a signal in theSource-Sinkchain to theSourceat the very beginning of the chain. That producerSourcewill then begin producing events.Events are then propagated synchronously from the
Sourcethrough theSource-Sinkchain by a simple method call.Thus, you could provide your own "listener" function to a
mapwhich 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 itsrunpackage.