Mostjs 的动态重新路由和循环依赖

Dynamic rerouting and circular dependency with Mostjs

很明显,xstream 通过 addListenerremoveListener 这两种方法,能够动态地重新路由流(更改它们的源和汇)。我看不到与 mostjs 的等价物。 most 只让您布置一次流的路由吗?如果是这样,这种静态特性是否允许 mostjs 优化以获得如此卓越的性能?

此外,xstream 使用 imitate 方法使其具有循环依赖性。有什么办法可以实现mostjs的循环依赖吗?

您是否在 most.js 中看到过关于 xstream.js imitate 的问题?https://github.com/cujojs/most/issues/308

most.js 中有许多函数同时对 SourceSink 进行操作,例如 map(),它转换流中的所有事件,通过消费事件充当 Sink,并在对事件应用函数后生成新事件值时充当 Sourceobserve() 是一种特定类型 Sink 的示例,它使用事件,并将它们传递给您提供的函数。

Most.js Streams 在您使用 "terminal" 组合器、observedrainreduce。当您调用其中一个时,Stream 会在 Source-Sink 链中向链最开头的 Source 发送一个信号。该制作人 Source 将开始制作活动。

然后通过简单的方法调用,事件从 Source 同步传播到 Source-Sink 链。

因此,您可以将自己的 "listener" 函数提供给 map 来转换事件。

影响 most.js 性能的因素有很多。

The simple call stack event propagation architecture, plus hoisting try/catch out of combinator implementations were two of the earliest and biggest performance improvements.

Most.js performs several other optimizations automatically, based on algebraic equivalences. A relatively well-known example is combining multiple map operations, e.g. map(g, map(f, stream)), into a single map by doing function composition on f and g.

The operation also combines multiple filter operations, multiple merge operations, multiple take and skip, among others. These optimizations reduce the number of method calls needed to propagate an event from producer to consumer.

See this interview with Brian Cavalier

Most.js 本身不处理循环依赖,但是使用 most-proxy. Motorcycle 完全有可能在它的 run 包中创建它的循环。