reagent

Michelle Lim 2023-05-19T20:43:08.251779Z

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

juhoteperi 2023-05-20T08:04:12.634129Z

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.

🙏 2
Michelle Lim 2023-05-20T19:15:33.324849Z

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

p-himik 2023-05-19T21:08:31.144669Z

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-himik 2023-05-19T21:14:32.867409Z

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-himik 2023-05-19T21:20:56.583029Z

Conceptually, that's not different from WebSockets.

Michelle Lim 2023-05-19T21:25:24.702289Z

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