Skip to content

Commit

Permalink
Add portal.api/inspect
Browse files Browse the repository at this point in the history
  • Loading branch information
djblue committed Mar 31, 2023
1 parent a00969a commit e1ecae5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
12 changes: 12 additions & 0 deletions src/portal/api.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,15 @@
(docs nil))
([options]
(open (assoc options :window-title "portal-docs" :value (get-docs)))))

(defn inspect
"Open a new portal window to inspect a particular value."
{:command true
:added "0.38.0"
:see-also ["open"]}
([value]
(inspect value (:options rt/*session*)))
([value options]
(open (assoc options :value value))))

(register! #'inspect)
25 changes: 16 additions & 9 deletions src/portal/extensions/vs_code_notebook.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,25 @@
(defonce context (atom nil))
(defonce component (r/atom embed/app))

(defn inspect
"Open a new portal window to inspect a particular value."
{:command true}
([value]
(inspect value))
([value _]
(.postMessage
^js @context
#js {:type "open-editor"
:data (binding [*print-meta* true]
(pr-str value))})))

(rt/register! #'inspect {:name `portal.api/inspect})

(defn app [id value]
[@component
{:id id
:value value
:on-open
(fn [value]
(.postMessage
^js @context
#js {:type "open-editor"
:data (binding [*print-meta* true]
(pr-str value))}))}])
:on-open #(rpc/call `portal.api/inspect % {:launcher :vs-code})}])

(defonce functional-compiler (r/create-compiler {:function-components true}))

Expand All @@ -43,8 +51,7 @@
(if-not (:portal.nrepl/eval conn)
value
(a/do
(rpc/connect
(assoc conn :session session))
(rpc/connect (assoc conn :session session))
(reset! state/sender rpc/request)
(apply rpc/call value)))))

Expand Down

0 comments on commit e1ecae5

Please sign in to comment.