Fork me on GitHub
#re-frame
<
2020-03-17
>
Oz17:03:41

Another question/s - I'm sending some messages over a websocket using an event that triggers an effect. I want each message to have an identifier, but uuid is a bit of an overkill. So I wanted to start simple with a counter that will number each message. But I'm a little confused how to implement it. Should I create another effect that updates the database with the counter? How do I get the value then to the :ws-send effect? using the coeffects? (cfx) Maybe I need an interceptor for this? wow doge so immutability doge much reactive Also, effects in reg-event-fx always need an input argument because it's a map. But what if my effect doesn't need input? do I just put nil there?

p-himik18:03:11

> uuid is a bit of an overkill. Maybe. But why do you care? > Should I create another effect that updates the database with the counter? > How do I get the value then to the :ws-send effect? Just use a regular atom, not even a reagent.core/atom. The latest message ID is not a part of your state in any way. > But what if my effect doesn't need input? do I just put nil there? Put anything you want. Just out of interest - what does such an effect do, if it doesn't have any parameters?

Oz18:03:32

Thank you for the answer! > Maybe. But why do you care? No reason, but another developer requested something simpler, and now I'm just curious > Just use a regular atom, not even a reagent.core/atom. The latest message ID is not a part of your state in any way. Sounds reasonable > Put anything you want. Just out of interest - what does such an effect do, if it doesn't have any parameters? Increments the counter, so maybe It makes sense to make a general :increment effect, and pass to it the atom. Or just put nil. My tendency for overthinking seems to clash with the fact that many things in clojure simply work :)

p-himik18:03:02

> another developer requested something simpler UUIDs are simpler than a counter simply because they have no state. It's just a random value, that's it. > Increments the counter Not sure I follow. You have a :ws-send effect - why would you have an external effect that just increases the counter? Why not combine the two and increase the counter inside the :ws-send effect handler?

👍 4
p-himik18:03:44

Also, if your WS connection links together a CLJ(S) server and a CLJ(S) client, then consider using something that has already been written, like Sente.