Skip to content

Commit

Permalink
Get rid of form-2 subs in defview
Browse files Browse the repository at this point in the history
  • Loading branch information
rasom committed Sep 10, 2020
1 parent 5aa33fc commit f9df0f3
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/status_im/utils/views.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
(:require [clojure.walk :as w]))

(defn atom? [sub]
(or (vector? sub)
(and (seq sub)
(#{`reagent.core/atom} (first sub)))))
(and (seq sub)
(#{`reagent.core/atom} (first sub))))

(defn walk-sub [sub form->sym]
(if (coll? sub)
Expand All @@ -24,13 +23,16 @@
(map (fn [{:keys [form sym]}]
[form sym]))
(into {}))]
[(mapcat (fn [{:keys [form sym sub]}]
(if (vector? sub)
[sym `(re-frame.core/subscribe ~(walk-sub sub form->sym))]
[(mapcat (fn [{:keys [form sub]}]
(when-not (vector? sub)
[form (walk-sub sub form->sym)]))
pairs)
(apply concat (keep (fn [{:keys [sym form sub]}]
(when (atom? sub)
(cond
(vector? sub)
[form `(deref (re-frame.core/subscribe ~(walk-sub sub form->sym)))]

(atom? sub)
[form `(deref ~sym)]))
pairs))]))

Expand Down

0 comments on commit f9df0f3

Please sign in to comment.