Skip to content

Commit

Permalink
Resolve circular dep and avoid requring-resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
mk committed Jun 21, 2023
1 parent 66ae6a5 commit 53584e3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
9 changes: 5 additions & 4 deletions src/nextjournal/clerk.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
[nextjournal.clerk.eval :as eval]
[nextjournal.clerk.parser :as parser]
[nextjournal.clerk.viewer :as v]
[nextjournal.clerk.webserver :as webserver]))
[nextjournal.clerk.webserver :as webserver]
[nextjournal.clerk.window :as window]))

(defonce ^:private !show-filter-fn (atom nil))
(defonce ^:private !last-file (atom nil))
Expand Down Expand Up @@ -78,9 +79,9 @@
#_(show! "https://raw.githubusercontent.com/nextjournal/clerk-demo/main/notebooks/rule_30.clj")
#_(show! (java.io.StringReader. ";; # In Memory Notebook 👋\n(+ 41 1)"))

(defn window! "todo" [& args] (apply (requiring-resolve 'nextjournal.clerk.window/open!) args))
(defn close-window! "todo" [id] ((requiring-resolve 'nextjournal.clerk.window/close!) id))
(defn close-all-windows! "todo" [] ((requiring-resolve 'nextjournal.clerk.window/close-all!)))
(defn window! [& args] (apply window/open! args))
(defn close-window! [id] (window/close! id))
(defn close-all-windows! [] (window/close-all!))

(defn recompute!
"Recomputes the currently visible doc, without parsing it."
Expand Down
23 changes: 11 additions & 12 deletions src/nextjournal/clerk/tap.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
;; # 🚰 Tap Inspector
(ns nextjournal.clerk.tap
{:nextjournal.clerk/visibility {:code :hide :result :hide}}
(:require [nextjournal.clerk :as clerk]
[nextjournal.clerk.viewer :as v])
(:require [nextjournal.clerk.viewer :as v])
(:import (java.time Instant LocalTime ZoneId)))

(defn inst->local-time-str [inst] (str (LocalTime/ofInstant inst (ZoneId/systemDefault))))
Expand All @@ -24,18 +23,18 @@
[:button.text-xs.rounded-full.px-3.py-1.border-2.font-sans.hover:bg-slate-100.cursor-pointer
{:on-click #(nextjournal.clerk.render/clerk-eval `(reset-taps!))} "Clear"]]))))

^{::clerk/sync true ::clerk/viewer switch-view ::clerk/visibility {:result :show}}
^{:nextjournal.clerk/sync true :nextjournal.clerk/viewer switch-view :nextjournal.clerk/visibility {:result :show}}
(defonce !view (atom :stream))

(defonce !taps (atom ()))

(defn reset-taps! []
(reset! !taps ())
(clerk/recompute!))
((resolve 'nextjournal.clerk/recompute!)))

(defn tapped [x]
(swap! !taps conj (record-tap x))
(clerk/recompute!))
((resolve 'nextjournal.clerk/recompute!)))

(defonce tap-setup
(add-tap (fn [x] ((resolve `tapped) x))))
Expand All @@ -57,10 +56,10 @@
(update-in [:nextjournal/value ::tapped-at] inst->local-time-str)))})


^{::clerk/visibility {:result :show}
::clerk/viewers (v/add-viewers [tap-viewer])}
(clerk/fragment (cond->> @!taps
(= :latest @!view) (take 1)))
^{:nextjournal.clerk/visibility {:result :show}
:nextjournal.clerk/viewers (v/add-viewers [tap-viewer])}
(v/fragment (cond->> @!taps
(= :latest @!view) (take 1)))

(comment
(last @!taps)
Expand All @@ -69,9 +68,9 @@
(tap> (shuffle (range (+ 20 (rand-int 200)))))
(tap> (clerk/md "> The purpose of visualization is **insight**, not pictures."))
(tap> (v/plotly {:data [{:z [[1 2 3] [3 2 1]] :type "surface"}]}))
(tap> (clerk/html {::clerk/width :full} [:h1.w-full.border-2.border-amber-500.bg-amber-500.h-10]))
(tap> (clerk/table {::clerk/width :full} [[1 2] [3 4]]))
(tap> (clerk/plotly {::clerk/width :full} {:data [{:y [3 1 2]}]}))
(tap> (clerk/html {:nextjournal.clerk/width :full} [:h1.w-full.border-2.border-amber-500.bg-amber-500.h-10]))
(tap> (clerk/table {:nextjournal.clerk/width :full} [[1 2] [3 4]]))
(tap> (clerk/plotly {:nextjournal.clerk/width :full} {:data [{:y [3 1 2]}]}))
(tap> (clerk/image "trees.png"))
(do (require 'rule-30)
(tap> (clerk/with-viewers (clerk/add-viewers rule-30/viewers) rule-30/rule-30)))
Expand Down

0 comments on commit 53584e3

Please sign in to comment.