Fork me on GitHub
#reagent
<
2023-05-19
>
Michelle Lim20:05:08

are there any good libraries or examples out there for fetching and displaying event streams in clojurescript/reagent/re-frame?

p-himik21:05:31

I don't think there's enough details in the question to provide a useful answer. What is an "event" exactly? What is a "stream"? How does one fetch a stream? What would be an appropriate way of rendering a fetched event stream?

p-himik21:05:32

For example, it's easy to imagine that you have a WebSocket connection where a stream of events is just serialized EDN data that you receive as text messages. In that case, you can have e.g. an instance of PersistentQueue in an atom storing a window of the latest 1000 messages that you display as strings without deserialization in a flat list with Reagent while using a message's timestamp as the item's key.

p-himik21:05:56

Conceptually, that's not different from WebSockets.

Michelle Lim21:05:24

was curious if there are any examples out there, for someone who has not worked with anything like this before (easy is relative heh)

juhoteperi08:05:12

I've just used EventSource directly. The whole connection handling is like 15 lines and then you can just dispatch the received events to re-frame and handle everything else like regular.

🙏 3
Michelle Lim19:05:33

that makes sense! my use case was unusual (didn't know it at first) in that i wanted to use a POST endpoint, and EventSource is only meant for GET. i ended up finding the sse.js library which solves that, and was able to use it with shadow cljs. this is what i ended up with for a simple openai chat interface: https://gist.github.com/eemshi/81beda81558a0bb480ee0f5221b93519