1
我使用Redux的循環寫一個非常簡單的應用程序,有3個要素:在週期js中動態更新源和接收器?
- 的文本字段輸入URL
- A 「連接」 按鈕連接到WebSocket終點
- 的輸出面板,顯示收到的消息
我已經寫在此基礎上回答https://stackoverflow.com/a/42926532/842860
了Wi一個非常簡單的WebSocket司機代碼是這樣的:
const cycleMiddleware = createCycleMiddleware();
const {makeActionDriver} = cycleMiddleware;
function main(sources) {
return {
ACTION: sources.WEBSOCKET // The websocket driver emits commands which are consumed by reducers
}
}
const store = createStore(
reducer, // Update redux state
applyMiddleware(cycleMiddleware)
);
run(main, {
WEBSOCKET: WSDriver("ws://localhost:3000/something"), // The initial connection string
ACTION: makeActionDriver()
});
問題是如何使websocket重新連接到另一個端點時點擊連接按鈕?我是否需要修改我的websocket驅動程序來捕獲事件並重新連接,或者cyclejs是否提供動態更新源/接收器的方法?