Fork me on GitHub
#re-frame
<
2019-12-26
>
Cam01:12:11

re-framers! merry xmas and all that! quick question from a Clojure n00b; I see that devcards currently don't play nice with re-frame. I have been researching the various libs, frameworks and tools in clojurescript for a while, and I think re-frame is exactly what I am after. However, devcards, or something similar would be a huge help. My project is essentially a softphone. And being able to build my UI without making/receiving phonecalls would be a huge productivity win, massive in fact! Is devcard support on the way? or an alternative available? or perhaps you can recommend another framework like re-frame that takes me beyond the reagent basics and will work well with devcards?

flowthing08:12:06

I haven’t used either myself so I can’t really give any solid recommendations, but you might be interested in https://github.com/nubank/workspaces

Cam08:12:01

Ok, that's worth a look, I'll check out out, thanks for the tip @U4ZDX466T

ingesol14:12:04

I don’t think there’s any significant difference between workspaces and devcards regarding re-frame? Don’t the same problems apply to both?

Cam15:12:22

Thats a good question @U21QNFC5C I guess I'll find out :thinking_face:

🙂 1
Ramon Rios09:12:15

Merry xmas everybody

Ramon Rios10:12:39

Have you tried to put a conditional statement on a event?.

(rf/reg-event-fx
 :customer/show
 (fn [{:keys [db]} [_ id]]
   {:db (->> id
             (get (d/customers db))
             (d/set-current db))
    :dispatch [:customer/check-correspondence]}))
I would like to dispatch check-correspondence with a if condition. Is that possible?

p-himik10:12:17

(cond-> {:db ...} condition? (assoc :dispatch ...)

Ramon Rios13:12:43

(rf/reg-event-fx
 :customer/show
 (fn [{:keys [db]} [_ id]]
  (cond-> {:db (->> id
                    (get (d/customers db))
                    (d/set-current db))}
    ( false? (contains? (d/current db) :policy-correspondence)) (assoc :dispatch [:customer/default-correspondence]))))

Ramon Rios13:12:49

Like this right?

p-himik13:12:19

Yeah. A few things though: - {:keys [db]} can be written as {db :db} - a bit shorter, but only if you need just the DB and nothing else - Don't use ->> for getting by ID, use it to thread through collections instead. More details: https://stuartsierra.com/2018/07/06/threading-with-style - Don't do false? unless you need a strict check for false. Just use not.

Ramon Rios13:12:31

What would you do instead of ->>

p-himik14:12:51

(let [customer (get (d/customers db) id)] ... (d/set-current db customer))

Ramon Rios16:12:35

Thanks for the tips

👍 1
Ramon Rios17:12:00

(rf/reg-event-fx
 :customer/show
 (fn [{:keys [db]} [_ id]]
   (let [customer (get (d/customers db) id)]
     (cond-> {:db (d/set-current db customer)}
       (not ( customer :police-correspondence)) (assoc :dispatch-n [[:customer/item-changed :policy-correspondence "prod-manager"]
                                                                    [:customer/item-changed :invoicing-correspondence "prod-manager"]])))))

Ramon Rios17:12:59

My current code, it would better to call twice a event that does what i want instead of create a brand new. The condition is not working but i'm trying to figure out why.