Fork me on GitHub
#re-frame
<
2019-06-07
>
plins17:06:01

Hello everyone, Im having lots of very similar code which can be easily abstracted by another function..

(rf/reg-sub
  :str1
  (fn [db _]
    (:str1 db)))

(rf/reg-sub
  :str2
  (fn [db _]
    (:str2 db)))

(rf/reg-sub
  :str1-valid?
  (fn [db _]
    (:str1-valid? db)))
is it safe to use a function to do so? or a macro?

tavistock18:06:42

i have worked on fairly large cljs apps and the more i metaprogram the subscriptions the more i hate it. You could try

(defn simple-sub [k] (fn [db] (k db)))

(rf/reg-sub :str1-valid? (simple-sub :str1-valid?))

isak19:06:31

@U0C7D2H1U why do you hate it?

tavistock19:06:43

when im logging an event id prefer [:sub :arg] and be able to see the implementation of the action right there not have to chase down threads

4
plins17:06:08

something like

(defn make-sub [k] 
  (rf/reg-sub
     k
     (fn [db _]
       (k db)))