Cyclejs Read/write websocket 驱动程序?

Cyclejs Read/write websocket driver?

我是 cyclejs 的新手,我正在寻找 websocket 支持,但我没有看到任何支持(除了文档中的只读 websocket 驱动程序和一些 0.1.2 节点端 npm 包)。

我应该创建自己的驱动程序还是我遗漏了什么?

提前致谢

此页面对您有帮助吗?

https://cycle.js.org/drivers.html

具体提到的示例代码:

function WSDriver(/* no sinks */) {
  return xs.create({
    start: listener => {
       this.connection = new WebSocket('ws://localhost:4000');
       connection.onerror = (err) => {
          listener.error(err)
       }
       connection.onmessage = (msg) => {
         listener.next(msg)
       }
    },
    stop: () => {
      this.connection.close();
    },
 });
}

如果添加接收器,这应该是一个读写驱动程序。来自他们的文档:

Most drivers, like the DOM Driver, take sinks (to describe a write) and return sources (to catch reads). However, we might have valid cases for write-only drivers and read-only drivers.

For instance, the one-liner log driver we just saw above is a write-only driver. Notice how it is a function that does not return any stream, it simply consumes the sink msg$ it receives.

Other drivers only create source streams that emit events to the main(), but don’t take in any sink from main(). An example of such would be a read-only Web Socket driver, drafted below: