Skip to content

Commit

Permalink
Reduce subscription load in cljs-devtools component
Browse files Browse the repository at this point in the history
  • Loading branch information
superstructor committed Jul 22, 2021
1 parent 03e74b4 commit 4eeead1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 35 deletions.
46 changes: 20 additions & 26 deletions src/day8/re_frame_10x/components/cljs_devtools.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@
(declare jsonml->hiccup)

(defclass jsonml-style
[ambiance syntax-color-scheme]
[]
{:display :inline
:flex-direction :row
:background-color (styles/syntax-color ambiance syntax-color-scheme :signature-background)}
:background-color (styles/syntax-color :bright :cljs-devtools :signature-background)}
["> span"
{:vertical-align :text-top}]
[:li
Expand All @@ -252,19 +252,17 @@
{:fill (if (= ambiance :bright) styles/nord0 styles/nord5)}])

(defn data-structure [_ path]
(let [ambiance (rf/subscribe [::settings.subs/ambiance])
syntax-color-scheme (rf/subscribe [::settings.subs/syntax-color-scheme])
expanded? (rf/subscribe [::app-db.subs/node-expanded? path])]
(let [expanded? (rf/subscribe [::app-db.subs/node-expanded? path])]
(fn [jsonml path]
[:span
{:class (jsonml-style @ambiance @syntax-color-scheme)}
[:span {:class (toggle-style @ambiance)
{:class (jsonml-style)}
[:span {:class (toggle-style :bright)
:on-click #(rf/dispatch [::app-db.events/toggle-expansion path])}
[:button
(if @expanded?
[material/arrow-drop-down]
[material/arrow-right])]]
(if (and @expanded? (has-body @ambiance @syntax-color-scheme (get-object jsonml) (get-config jsonml)))
(if (and @expanded? (has-body (get-object jsonml) (get-config jsonml)))
(jsonml->hiccup
(body
(get-object jsonml)
Expand Down Expand Up @@ -318,25 +316,21 @@
(nil? data)))

(defclass prn-str-render-style
[ambiance syntax-color-scheme]
{:background-color (styles/syntax-color ambiance syntax-color-scheme :signature-background)
:color (styles/syntax-color ambiance syntax-color-scheme :bool)})
[]
{:background-color (styles/syntax-color :bright :cljs-devtools :signature-background)
:color (styles/syntax-color :bright :cljs-devtools :bool)})

(defn prn-str-render
[data]
(let [ambiance @(rf/subscribe [::settings.subs/ambiance])
syntax-color-scheme @(rf/subscribe [::settings.subs/syntax-color-scheme])]
[:div {:class (prn-str-render-style ambiance syntax-color-scheme)}
(prn-str data)]))
[:div {:class (prn-str-render-style)}
(prn-str data)])

(defn simple-render [_ path & [class]]
(let [ambiance (rf/subscribe [::settings.subs/ambiance])
syntax-color-scheme (rf/subscribe [::settings.subs/syntax-color-scheme])]
(fn [data]
[rc/box
:size "1"
:class (str (jsonml-style @ambiance @syntax-color-scheme) " " class)
:child
(if (prn-str-render? data)
(prn-str-render data)
(jsonml->hiccup (header data) (conj path 0)))])))
(defn simple-render
[data path & [class]]
[rc/box
:size "1"
:class (str (jsonml-style) " " class)
:child
(if (prn-str-render? data)
(prn-str-render data)
(jsonml->hiccup (header data) (conj path 0)))])
17 changes: 8 additions & 9 deletions src/day8/re_frame_10x/panels/app_db/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,15 @@
[rc/gap-f :size styles/gs-12s]]))]))

(defclass panel-style
[_]
[]
{:margin-right styles/gs-5
:overflow :auto})

(defn panel [_]
(let [ambiance @(rf/subscribe [::settings.subs/ambiance])]
[rc/v-box
:class (panel-style ambiance)
:size "1"
:children
[[panel-header]
[pod-section]
[rc/gap-f :size styles/gs-19s]]]))
[rc/v-box
:class (panel-style)
:size "1"
:children
[[panel-header]
[pod-section]
[rc/gap-f :size styles/gs-19s]]])

0 comments on commit 4eeead1

Please sign in to comment.