Fork me on GitHub

What's the recommended approach for using websockets with re-frame?


Not sure why there has to be a recommended approach - the two are completely orthogonal. I prefer to use it with core.async wrapping sente. I just have a go-loop at an app's entry point that fetches sente's messages and dispatches relevant events. And I have some effects that send messages via the sente's open channel.


hah fair enough


what's the other approach?


sente seems a bit heavyweight to me, not sure if I'll need it


The other? :D I'd imagine there are quite a few. You can use something other than sente and/or core.async. You can react to messages with just one event or with many. You can store the current connection in a separate atom (that's what I do) or in some closure, or in the app-db itself. You can send re-frame event vectors over the wire and make the other part handle them, or you can send back and forth some specific data that has nothing to do with events. There are likely other degrees of freedom that I can't think of right now.


very informative, thanks

👍 2

thinking about how to piece the two together hurts my head a bit


I think I'll just go with a regular JS websocket client that I put in the app db


...and then spawn a re-frame event for each event I get over the websocket


Will be easier if you start small. Re-frame interfaces with the outside world via the world dispatching events and via re-frame doing stuff in effect handlers - that's it. That's the only constant in all the ways of using WebSockets with re-frame. So if you write something tiny that does that, you will pretty much grasp the whole concept.


sounds good, thanks


the tricky part is that I'll need to use websockets to keep objects I've fetched over ajax in up to date


but I'm fairly confident I'll find a way to deal with that


...once I've got something basic going