Skip to content

Commit

Permalink
Dump data to the console & clipboard, as a raw or pretty string.
Browse files Browse the repository at this point in the history
  • Loading branch information
kimo-k committed Jun 30, 2023
1 parent d0b105b commit e31e197
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file. This change

#### Added

- Options to dump data to the console & clipboard, as a raw or pretty string. See #178.
- Option to ignore keyboard input. See #386.
- Option to re-bind the open/close panel key. See #386.
- Open/close panel key now binds to `Ctrl-Shift-X` (from `Ctrl-h`). See #386.
Expand Down
3 changes: 2 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
;; re-highlight only has a transitive dependency on highlight.js for
;; shadow-cljs builds, so we need to declare a dependency on cljsjs/highlight
;; for 10x to support other build systems.
[cljsjs/highlight "10.3.1-0"]]
[cljsjs/highlight "10.3.1-0"]
[org.clojure/tools.logging "1.2.4"]]

:plugins [[day8/lein-git-inject "0.0.15"]
[lein-less "RELEASE"]]
Expand Down
18 changes: 15 additions & 3 deletions src/day8/re_frame_10x/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[re-frame.interop]
[day8.re-frame-10x.inlined-deps.re-frame.v1v1v2.re-frame.core :as rf]
[day8.re-frame-10x.fx.local-storage :as local-storage]
[day8.re-frame-10x.fx.log :as log]
[day8.re-frame-10x.navigation.events :as navigation.events]
[day8.re-frame-10x.navigation.views :as navigation.views]
[day8.re-frame-10x.panels.app-db.events :as app-db.events]
Expand Down Expand Up @@ -44,12 +45,14 @@
:ctrlKey true
:metaKey false
:shiftKey true}}})
(rf/inject-cofx ::local-storage/load {:key "log-outputs" :or [:day8.re-frame-10x.fx.log/console]})
(rf/inject-cofx ::local-storage/load {:key "log-pretty?" :or true})
rf/unwrap]
(fn [{:keys [panel-width-ratio show-panel selected-tab filter-items app-db-json-ml-expansions
external-window? external-window-dimensions show-epoch-traces? using-trace?
ignored-events low-level-trace filtered-view-trace retained-epochs app-db-paths
app-db-follows-events? ambiance syntax-color-scheme categories data-path-annotations?
show-event-history open-new-inspectors? handle-keys? key-bindings]}
show-event-history open-new-inspectors? handle-keys? key-bindings log-outputs log-pretty?]}
{:keys [debug?]}]
{:fx [(when using-trace?
[:dispatch [::settings.events/enable-tracing]])
Expand Down Expand Up @@ -79,7 +82,9 @@
[:dispatch [::settings.events/show-event-history? show-event-history]]
[:dispatch [::settings.events/open-new-inspectors? open-new-inspectors?]]
[:dispatch [::settings.events/handle-keys? handle-keys?]]
[:dispatch [::settings.events/key-bindings key-bindings]]]}))
[:dispatch [::settings.events/key-bindings key-bindings]]
[:dispatch [::settings.events/log-outputs log-outputs]]
[:dispatch [::settings.events/log-pretty? log-pretty?]]]}))

;; Global

Expand All @@ -92,4 +97,11 @@
(rf/reg-event-db
:global/unloading?
(fn [db [_ unloading?]]
(assoc-in db [:global :unloading?] unloading?)))
(assoc-in db [:global :unloading?] unloading?)))

(rf/reg-event-fx
:global/log
[(rf/path [:settings]) rf/trim-v]
(fn [{{:keys [log-outputs log-pretty?]} :db} [value]]
{:fx (mapv #(do [% {:value value :pretty? log-pretty?}])
log-outputs)}))
27 changes: 27 additions & 0 deletions src/day8/re_frame_10x/fx/log.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(ns day8.re-frame-10x.fx.log
(:require-macros [day8.re-frame-10x.inlined-deps.re-frame.v1v1v2.re-frame.trace])
(:require
[clojure.pprint :refer [pprint]]
[day8.re-frame-10x.inlined-deps.re-frame.v1v1v2.re-frame.core :as rf]
[day8.re-frame-10x.inlined-deps.re-frame.v1v1v2.re-frame.loggers :as loggers]
[day8.re-frame-10x.fx.clipboard :as clipboard]))

(defn pretty [value] (binding [*print-length* 20]
(with-out-str (pprint value))))

(rf/reg-fx
::console
(fn [{:keys [value]}]
(loggers/console :log value)))

(rf/reg-fx
::console-raw
(fn [{:keys [value pretty?]}]
(loggers/console :log (if pretty?
(pretty value)
(pr-str value)))))

(rf/reg-fx
::clipboard
(fn [{:keys [value pretty?]}]
(clipboard/copy! (cond-> value pretty? pretty))))
2 changes: 1 addition & 1 deletion src/day8/re_frame_10x/panels/app_db/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
:child
[buttons/icon {:icon [material/print]
:title "Dump inspector data into DevTools"
:on-click #(js/console.log data)}]]]]]]))
:on-click #(rf/dispatch [:global/log data])}]]]]]]))

(def diff-url "https://github.com/day8/re-frame-10x/blob/master/docs/HyperlinkedInformation/Diffs.md")

Expand Down
2 changes: 1 addition & 1 deletion src/day8/re_frame_10x/panels/fx/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
:margin-right "1px"}
:child
[buttons/icon {:icon [material/print]
:on-click #(js/console.log data)}]]]]))
:on-click #(rf/dispatch [:global/log data])}]]]]))

(defclass section-style
[ambiance]
Expand Down
17 changes: 17 additions & 0 deletions src/day8/re_frame_10x/panels/settings/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,20 @@
[(rf/path [:settings :key-bindings]) rf/trim-v (local-storage/save "key-bindings")]
(fn [key-bindings [key-intent value]]
(assoc key-bindings key-intent value)))

(rf/reg-event-db
::log-outputs
[(rf/path [:settings :log-outputs]) rf/trim-v (local-storage/save "log-outputs")]
(fn [log-outputs [value & [enabled?]]]
(if (vector? value)
value
(-> (set log-outputs)
((if-not (false? enabled?) conj disj) value)
sort
vec))))

(rf/reg-event-db
::log-pretty?
[(rf/path [:settings :log-pretty?]) rf/trim-v (local-storage/save "log-pretty?")]
(fn [_ [pretty?]]
pretty?))
15 changes: 15 additions & 0 deletions src/day8/re_frame_10x/panels/settings/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,18 @@
(if k
(get key-bindings k)
key-bindings)))

(rf/reg-sub
::log-outputs
:<- [::root]
(fn [{:keys [log-outputs]} [_ k]]
(if k
(get log-outputs k)
log-outputs)))

(rf/reg-sub
::log-pretty?
:<- [::root]
(fn [{:keys [log-pretty?]} _]
log-pretty?))

26 changes: 25 additions & 1 deletion src/day8/re_frame_10x/panels/settings/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
[day8.re-frame-10x.panels.traces.subs :as traces.subs]
[day8.re-frame-10x.material :as material]
[day8.re-frame-10x.styles :as styles]
[day8.re-frame-10x.tools.datafy :as tools.datafy]))
[day8.re-frame-10x.tools.datafy :as tools.datafy]
[day8.re-frame-10x.fx.log :as log]))

(def comp-section-width "400px")
(def instruction--section-width "190px")
Expand Down Expand Up @@ -250,6 +251,29 @@
settings-box-81])

[rc/line]
(let [log-outputs @(rf/subscribe [::settings.subs/log-outputs])
log-pretty? @(rf/subscribe [::settings.subs/log-pretty?])]
[settings-box
[[rc/label :label [:span "Dump data to:"]]
[rc/checkbox
:model (-> log-outputs set ::log/console)
:label "Browser console (cljs-devtools view)"
:on-change #(rf/dispatch [::settings.events/log-outputs ::log/console %])]
[rc/checkbox
:model (-> log-outputs set ::log/console-raw)
:label "Browser console (raw string)"
:on-change #(rf/dispatch [::settings.events/log-outputs ::log/console-raw %])]
[rc/checkbox
:model (-> log-outputs set ::log/clipboard)
:label "Clipboard"
:on-change #(rf/dispatch [::settings.events/log-outputs ::log/clipboard %])]
[rc/checkbox
:model log-pretty?
:label "Pretty-print?"
:on-change #(rf/dispatch [::settings.events/log-pretty? %])]]
[[:div "How should the log (" [material/print] ") buttons behave?"]]
settings-box-131])
[rc/line]
(let [ambiance @(rf/subscribe [::settings.subs/ambiance])]
[settings-box
[[rc/button
Expand Down
2 changes: 1 addition & 1 deletion src/day8/re_frame_10x/panels/subs/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@

[pod-header-section
:width styles/gs-31s
:attr {:on-click #(js/console.log value)}
:attr {:on-click #(rf/dispatch [:global/log value])}
:last? true
:children
[[rc/box
Expand Down
4 changes: 2 additions & 2 deletions src/day8/re_frame_10x/panels/traces/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@
:size styles/gs-31s
:child
[buttons/icon {:icon [material/print]
:on-click #(js/console.log tags)}]]]]
:on-click #(rf/dispatch [:global/log tags])}]]]]
(when expanded?
[rc/h-box
:class (table-row-expanded-style ambiance syntax-color-scheme)
Expand Down Expand Up @@ -380,4 +380,4 @@
:children
[[filters]
[queries]
[table]]])
[table]]])

0 comments on commit e31e197

Please sign in to comment.