-
Notifications
You must be signed in to change notification settings - Fork 74
Description
Even though still a WIP, this project has been a great help to me already.
I am adding a websocket client in my app, and would have loved to see an example of that doing idiomatically.
What I have done so far is add a ws service and ws feature with actions and epics.
The server pushes 4 (for now) kinds of objects, and and the ws client turns the incoming data into actions and the the data end up in the redux store.
I am reasonably comfortable (though far from certain) that this approach broadly is idiomatic and reasonable.
But one detail seems like a hack. The ws service needs the Redux dispatch function to be able to generate redux actions from the server pushed data. My solution so far has been to call the ws service's initialization function from store/index.ts explicitly passing store.dispatch to it.
I am wondering how to improve this. Maybe I should use react-redux connect() to wrap the websocket initialization function and call it from App.tsx ?
The other challenge that I haven't yet tried to implement, is I would would like to implement a semi-synchronous-feeling request/response/error/timeout flow over websockets similar to how REST API requests work . I suspect I have to deal with a mux/demux issue as there can be more than one request active, and need to match responses to the right requests. I will come up with something, but I suspect others have already invented clever ways of doing it that will never occur to me.