This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-17
Channels
- # announcements (7)
- # babashka (56)
- # beginners (114)
- # bristol-clojurians (4)
- # calva (22)
- # cider (7)
- # clara (1)
- # clj-kondo (17)
- # cljs-dev (1)
- # clojure (93)
- # clojure-europe (8)
- # clojure-italy (5)
- # clojure-nl (2)
- # clojure-uk (79)
- # clojuredesign-podcast (18)
- # clojurescript (108)
- # code-reviews (6)
- # cursive (3)
- # data-science (16)
- # datomic (151)
- # duct (7)
- # emacs (10)
- # events (1)
- # fulcro (76)
- # luminus (8)
- # off-topic (3)
- # other-lisps (2)
- # pathom (8)
- # re-frame (5)
- # reitit (8)
- # schema (9)
- # shadow-cljs (37)
- # specter (3)
- # sql (17)
- # tree-sitter (2)
- # yada (9)
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 so immutability 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?
> 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?
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 :)
> 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?