portal

genekim 2022-12-12T00:55:06.189999Z

Lovely presentation by James Trunk on Portal — https://youtu.be/A-QvUw5LLVU

💯 7
2
🙏 2
pez 2022-12-12T11:12:41.715179Z

Hello! Is it possible to use the vscode extension with shadow-cljs?

pez 2022-12-13T16:14:26.054099Z

What can I expect when using the remote-api? My taps do not show up in the VS Code portal extension when I try.

pez 2022-12-13T16:19:30.083819Z

I now notice I also get this in the browser console when I tap:

portal.client.web.js:3 Refused to connect to '' because it violates the document's Content Security Policy.

djblue 2022-12-13T16:46:02.381599Z

Very odd, the main thing required for the web client to work is CORS. Is that being blocked here?

pez 2022-12-13T16:54:32.036449Z

Probably. I'll figure out how to check.

🙏 1
pez 2022-12-13T17:23:42.344189Z

I love you, @djblue!

❤️ 1
pez 2022-12-13T17:42:37.663669Z

Answering my questions: • Yes, I can use the VS Code extensions with shadow-cljs (also for a browser target) if I use the remote-api (`portal.shadow.remote`) like described https://cljdoc.org/d/djblue/portal/0.35.0/doc/guides/shadow-cljs. • I can expect taps from the ClojureScript app to show in the same portal as taps from my Clojure backend app. 🎉

🎉 1
pez 2022-12-13T18:00:33.797489Z

Now I need to figure out how to also hook my node session to portal. That's where the tests are auto-running.

djblue 2022-12-13T18:16:04.192909Z

Did you want to pipe node taps to the jvm portal?

pez 2022-12-13T20:19:02.912299Z

The jvm portal is the one started via portal.api/open, right? Yes, to start with I want to do roughly the same as I do with the browser app. So that any taps happening as part of the tests will end up in the same portal view as the rest. I would like for the test results to go there as well, is that possible with node tests?

djblue 2022-12-13T20:51:38.524429Z

This is very doable but not something I expected people to do so it will be a little more involved

djblue 2022-12-13T20:52:13.528389Z

The main problem is getting the jvm port into the node process

pez 2022-12-13T20:57:05.502429Z

To get the taps from the test runs into portal, I tried to configure my test build like so:

:participant-test {:target :node-test
                             :autorun true
                             :output-to "target/node-test/participant-ui-tests.js"
                             :ns-regexp "participant-ui.*-test"
                             :build-hooks [(portal.shadow.remote/hook)]
                             :preloads     [portal.setup]}

pez 2022-12-13T20:57:35.910159Z

Where portal.setup is the same as with my app build.

djblue 2022-12-13T20:58:54.439409Z

Actually, with newer versions of node, portal.client.web might work since it ships a with a version of the fetch api 🤔

👀 1
pez 2022-12-13T21:07:31.379679Z

My portal/node_setup.cljs now looks like so:

(ns portal.node-setup
  (:require [portal.client.web :as portal]))

(add-tap portal/submit)
No dice. Also tried with portal.client.node.

djblue 2022-12-13T21:08:30.236159Z

Did portal.shadow.remote not work in node for you?

pez 2022-12-13T21:10:23.196189Z

I'm not sure I am doing it right. But that was the first thing I tried, and I didn't see the taps.

djblue 2022-12-13T21:10:58.430319Z

Can you call portal.shadow.remote/get-port at the node repl?

pez 2022-12-13T21:11:38.885029Z

Thing is I don't have an interactive REPL there. But maybe I can reach it from shadow's control panel...

pez 2022-12-13T21:17:57.690549Z

From shadows console I can tap and it ends up in the portal view in VS Code.

pez 2022-12-13T21:20:36.437869Z

But I might have done that from the browser app's runtime, I now realize....

pez 2022-12-13T21:21:39.399749Z

Actually it was from the jvm runtime... The node-tests do not show up as a runtime.

pez 2022-12-13T21:27:11.493209Z

I had misconfigured the preload. Now configured it so that a println in my portal/node_setup.cljs prints this in the terminal where the test output shows:

(portal.shadow.remote/get-port) 58848

djblue 2022-12-13T21:30:57.672799Z

(ns portal.node-setup
  (:require [portal.client.node :as portal]
            [portal.shadow.remote :as shadow]))

(defn submit [value]
  (portal/submit {:port (shadow/get-port)} value))

(add-tap submit)
Might be what you want

pez 2022-12-13T21:36:13.613039Z

Nope. The port is the same for both REPLs (browser and node), is that as it should?

pez 2022-12-13T21:37:05.987359Z

Still don't have an interactive REPL, but shadow reloads my node-setup namespace when I save the file. So I can print stuff that way. 😃

pez 2022-12-13T21:47:48.345799Z

I can create a small project for this and maybe it is easier to collaborate around how to do it.

pez 2022-12-13T23:15:09.830619Z

Here's a project: https://github.com/PEZ/shadow-portal

djblue 2022-12-12T16:45:54.934329Z

portal.api via node should work, however portal.web won't work. You will have to use the remote-api. https://cljdoc.org/d/djblue/portal/0.35.0/doc/guides/shadow-cljs for more info.

jason1903 2022-12-12T23:52:30.450119Z

Hi, is it possible to have tap>s appear in the Portal UI as trees by default? Every tap> I evaluate appears with :portal.viewer/inspector as the viewer. Placing https://github.com/djblue/portal/blob/master/src/examples/default_visualizer.clj on the data passed to a tap> works, but I was hoping for something I could, say, pass to p/open that would set the default viewer without having to attach metadata to every tap> call. I am using the IntelliJ plugin.

djblue 2022-12-12T23:55:48.780239Z

I think the easiest way to do this is to pass a custom submit function to add-tap:

(defn can-meta? [value]
  (instance? clojure.lang.IObj value))

(defn submit [value]
  (p/submit
   (if-not (can-meta? value)
     value
     (with-meta value {:portal.viewer/default :portal.viewer/tree}))))

(add-tap submit)

jason1903 2022-12-13T00:23:00.408659Z

That worked. Thank you!

pez 2022-12-14T15:02:49.157319Z

For shadow-cljs I did this:

(defn submit [value]
  (shadow/submit
    (if (implements? IWithMeta value)
      (with-meta value {:portal.viewer/default :portal.viewer/tree})
      value)))

(add-tap submit)