Fork me on GitHub
#beginners
<
2015-09-25
>
timfield00:09:49

Ok, so I'm new to websockets ( as well as clojure ). New enough to possibly be asking a very stupid question. But how are people using them? Do I open one and put everything I want in it within a map ?

danielcompton01:09:09

@timfield: We’re using Sente which provides some higher level abstractions over websockets

danielcompton01:09:52

But you can just send maps over the wire. You probably want to serialise it with something, either EDN or Transit are good options

timfield01:09:54

Ok I'm using Chord currently

timfield01:09:13

And I think I'm going to send a single map that represents the whole page state

timfield01:09:22

Ok, so I'm not doing anything really odd then. Good to know

danielcompton01:09:31

What’s the context behind sending a map with the page state?

danielcompton01:09:59

Is that everything that the page needs to render itself?

danielcompton01:09:10

What else are you using on the frontend? Reagent/Om?

timfield01:09:26

Yeah quiescent

timfield01:09:30

another React wrapper

timfield01:09:34

What I don't like about this idea tho, is that I'm making a few API requests to construct the page state, and if they are in a single map, then I need to wait for all my API requests to return with data before I can begin rendering

timfield01:09:38

If I was doing this with ajax, each component might fetch its own state via ajax

timfield01:09:52

but I'm not sure how to do that with websockets

timfield01:09:25

Context, Clojure on server is creating page state, sending page state via a websocket to ClojureScript

timfield01:09:19

Agh, but what if those API requests wrote to the channel when ready, then my client listens to that channel and reacts based on its content

danielcompton02:09:40

Have you looked at re-frame? It’s one way to do what you’re describing

timfield03:09:43

re-frame looks rad. Next project for sure. For now I'm rolling with this setup; Single channel & single page state map. Both are passed down to quiescent components which can use the channel to trigger a change to the single page state map ( on the server ) which is then passed down again.

timfield03:09:51

Sounds like flux, which I like.