Lovely presentation by James Trunk on Portal — https://youtu.be/A-QvUw5LLVU
Hello! Is it possible to use the vscode extension with shadow-cljs?
What can I expect when using the remote-api? My taps do not show up in the VS Code portal extension when I try.
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. Very odd, the main thing required for the web client to work is CORS. Is that being blocked here?
Probably. I'll figure out how to check.
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. 🎉
Now I need to figure out how to also hook my node session to portal. That's where the tests are auto-running.
Did you want to pipe node taps to the jvm portal?
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?
This is very doable but not something I expected people to do so it will be a little more involved
The main problem is getting the jvm port into the node process
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]}You essentially need https://github.com/djblue/portal/blob/master/src/portal/shadow/remote.cljs#L1 but with https://github.com/djblue/portal/blob/master/src/portal/client/node.cljs
Where portal.setup is the same as with my app build.
Actually, with newer versions of node, portal.client.web might work since it ships a with a version of the fetch api 🤔
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.Did portal.shadow.remote not work in node for you?
I'm not sure I am doing it right. But that was the first thing I tried, and I didn't see the taps.
Can you call portal.shadow.remote/get-port at the node repl?
Thing is I don't have an interactive REPL there. But maybe I can reach it from shadow's control panel...
From shadows console I can tap and it ends up in the portal view in VS Code.
But I might have done that from the browser app's runtime, I now realize....
Actually it was from the jvm runtime... The node-tests do not show up as a runtime.
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(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 wantNope. The port is the same for both REPLs (browser and node), is that as it should?
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. 😃
I can create a small project for this and maybe it is easier to collaborate around how to do it.
Here's a project: https://github.com/PEZ/shadow-portal
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.
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.
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)That worked. Thank you!
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)