This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-21
Channels
- # admin-announcements (1)
- # announcements (6)
- # babashka (8)
- # beginners (134)
- # calva (18)
- # chlorine-clover (1)
- # cider (6)
- # circleci (6)
- # clj-commons (111)
- # cljsrn (13)
- # clojure (95)
- # clojure-australia (2)
- # clojure-europe (15)
- # clojure-nl (1)
- # clojure-spec (52)
- # clojure-uk (17)
- # clojurescript (4)
- # datavis (9)
- # datomic (8)
- # docker (2)
- # emacs (15)
- # events (7)
- # fulcro (6)
- # graphql (1)
- # gratitude (1)
- # introduce-yourself (2)
- # kaocha (8)
- # meander (87)
- # minecraft (2)
- # music (2)
- # off-topic (20)
- # portal (119)
- # releases (1)
- # reveal (55)
- # shadow-cljs (34)
- # sql (36)
- # tools-deps (9)
- # vim (8)
- # xtdb (39)
I'm looking over the portal site and trying to find actual documentation... what am I missing?
Yeah, sorry about that. Been meaning to put some docs together but haven't gotten around to it yet.
If I tab to the >_
icon and get the popup, it looks like I can run arbitrary Clojure on the value? (which I can do with REBL and Reveal) But it says filtering stuff so maybe I can't run an arbitrary Clojure function on the value?
The first thing I tried was (tap> (System/getenv))
which produces something like a hash map with string keys but Portal doesn't seem to be able to do anything with it -- this is displayed as a table in Reveal and REBL because it's a hash map...
Hmm, it seems if I do (tap> (into {} (System/getenv)))
I get what I expect...
Is there anything in Portal that will take a string that is a filepath and read it/parse it?
You can open a file with <os specific control character>+O
. Not sure if that would meet your needs.
No, I don't want to open a general file. I want to resolve a string that is a filepath to the contents of the file.
If your runtime is the jvm, I have slurp setup to work with files/urls. I guess I could also add arbitrary strings :thinking_face:
It would be nice if Portal allowed arbitrary Clojure code, like REBL and Reveal.
Then you could do (slurp (
or something. In Reveal, *v
means "current value". I think it's %
in REBL
The problem is, if you have a value/data structure that doesn't happen to conform to Portal's (limited) set of functions, you're kind of stuck.
If you had arbitrary Clojure code manipulation of results, then (tap> (System/getenv))
which produces a "map-like" thing could be viewed by just doing (into {} %)
to turn it into a real hash map in Portal.
I've been reluctant to add arbitrary eval since it wouldn't work for cljs, but I could see enabling it for clj and not cljs
I'm currently comparing Reveal and Portal, since the former has now sprouted a "Pro" paid version with features I don't need, so that's just the first thing I've bumped into.
I don't know how easy it is to extend Portal (given the lack of docs) but I have some custom "table view" stuff for Reveal that I'd want to get running in Portal before I could switch.
When I start needing complex manipulations, I tend to select the value I care about and manipulate if from my code editor
That doesn't really work if you're tap>
'ing values tho' -- you can't just explore the values, you have to go back into the code and rework the tap>
calls.
Since those values make it into the client, they are still selectable and can be derefed
For the Portal-as-atom thing, can you get back prior values or just the current value?
And the semantics of deref are more like: give me the currently selected value in the ui, even if it isn't the root value
OK, so I just did this:
(def p (p/open))
(tap> (System/getenv))
@p
and got nil
-- shouldn't I get back the value of (System/getenv)
?Ah, yes.
What type of table customizations do you have setup for reveal? If you don't mind me asking
https://github.com/seancorfield/dot-clojure/blob/develop/dev.clj#L62 -- it adds an "intelligent" display panel.
If I have an element selected in the Portal view, how do I navigate to the >_
button via the keyboard? I tried tab
but that seems to cycle through other selections before moving to the view drop-down and then the >_
button.
Thanks! Yes, ctrl + j works for google-chrome
on WSL2 as well.
Definitely need more options in that command list!
Can I register additional functions for that?
Really? I'm shocked! 😐
A quick hack would be to update https://github.com/djblue/portal/blob/master/src/portal/runtime.cljc#L192-L200
The one thing I haven't figured out is how to allow for custom menus like for select-keys and get-in
Also, I think for a custom table view, I think leveraging the hiccup viewer could work
I tried to alter-var-root
that private var to add 'keywordize #(update-keys % keyword)
and when I invoked it I got an NPE. What does it expect the value of those map elements to be? It looks like they can be function values...
The NPE was from the (apply f args)
so presumably f
was nil
?
Is there a trick for working with a local copy of Portal? I cloned it and started a REPL pointing to the local root version and got that main.js
error:
user=> (def p (p/open))
#'user/p
user=> Mon Sep 20 23:36:09 PDT 2021 [worker-2] ERROR - GET /main.js
java.lang.IllegalArgumentException: Cannot open <nil> as a Reader.
at $fn__11544.invokeStatic(io.clj:288)
at $fn__11544.invoke(io.clj:288)
at $fn__11446$G__11422__11453.invoke(io.clj:69)
at $reader.invokeStatic(io.clj:102)
at $reader.doInvoke(io.clj:86)
at clojure.lang.RestFn.invoke(RestFn.java:410)
at clojure.lang.AFn.applyToHelper(AFn.java:154)
at clojure.lang.RestFn.applyTo(RestFn.java:132)
at clojure.core$apply.invokeStatic(core.clj:669)
at clojure.core$slurp.invokeStatic(core.clj:6944)
at clojure.core$slurp.doInvoke(core.clj:6944)
at clojure.lang.RestFn.invoke(RestFn.java:410)
at portal.runtime.jvm.server$main_js.invokeStatic(server.clj:87)
Ugh! I don't do any cljs and don't have bb
or node
or anything installed.
BTW, I added a function to the fns
map and it didn't even show up in the ctrl + j
menu...
Yeah, I think it needs to be added to both since the first map is about which fns are public and the second map is the merge of that and all the private ones which is used for the dispatch
OK, yeah, that worked.
And that does let me turn the (System/getenv)
into a regular hash map with keywords for keys.
(although (partial into {})
is really all I need there)
OK, I'm heading to bed. I may well play with this some more tomorrow, but without arbitrary eval it's a bit limited (although I don't use that in REBL/Reveal all that often so maybe I can live without it). I'll take a look at the Hiccup view thing to create custom views -- there's no docs for that, right?
Knowing how to manipulate the runtime vars to add functions to the menu is a big step forward so thank you for that.
I'm hoping to put together an api for that and also keyboard shortcuts so you can bind arbitrary fns to keystrokes 💯
I much prefer written documentation to grubbing through a demo (or, worse, watching a video) but I'm kinda old school.
I'll probably switch my :dev/repl
alias over to Portal tomorrow and see how I get on with my day tap>
'ing values into it. Expect complaints and suggestions 🙂
Ah, OK. I have in-laws there (and Tucson) and one of my former colleagues moved there from the Bay Area. "It's a dry heat!" 🙂
OK Chris, well, thanks for all your help!
This is my baseline for starting work with it tomorrow: https://github.com/seancorfield/dot-clojure/commit/51f002bec5c1617bdc96bcccb5031b44d7988649
(and starting my REPL like this: SOCKET_REPL_PORT=5000 clojure -Sforce -M:rebel:portal:everything:dev:test:runner:build:dev/repl
)
I'll let you know how it goes!
Is there a way to display a URL's web page in Portal -- more directly than ctrl-j slurp v html
? Can a function that processes values tell Portal how to then display the result?
I think something like this might work :thinking_face:
(defn doc [url]
(with-meta
[:div
{:style {:background :white}}
[:portal.viewer/html (slurp url)]]
{:portal.viewer/default :portal.viewer/hiccup}))
Oh nice! I can provide metadata that instructs Portal how to display things! Awesome! That's not in the docs, right? I didn't just completely miss it, did I?
The https://github.com/djblue/portal/blob/master/CHANGELOG.md might be the best source of documentation currently
I don't do well with video "documentation", sorry. I haven't actually watched it yet, so maybe I'll do that and make notes and, hey, maybe I'll contribute some documentation back! 🙂
Sorry, I mean the https://djblue.github.io/portal/
Ah, I played with that site/demo but it didn't tell me anything about the API and it was initially very hard to figure out how to navigate the UI (I didn't realize I needed to TAB around to get focus on the value panel so that I could use the other nav commands).
On the plus side, I'm really liking it so far 🙂
One thing I'd like is a shortcut to navigate back to the "top" -- if I've been drilling into data and then switch back to the editor and eval (tap) some new value, I don't see it in Portal because it doesn't shift focus when new data is tapped -- which I can see pros and cons with, but a quick hotkey to get all the back up to the top would save a bunch of cmd-left
I think cmd-shift-left will take you all the way back to the tap list, is that what you mean?
Oh, let me try that...
Hah, yes, it does!
Yup, found that in the docs.
It would be nice if there was a key to jump up into the filter box - /
maybe (since that seems to be a shortcut on a lot of web apps).
Ah, I see why I didn't spot cmd-shift-left in the popup: the "left" part had rendered as just an empty box character...
Let me restart the REPL in case some of the experimentation I've been doing has borked it...
Nope, still little square boxes.
<div class=" G__54">⭢</div>
That's what I get from Google Chrome inspector.(with Reveal I have a have a hotkey to eval some code that, given a Java object/type, produces a URL into Oracle's docs, which Reveal can then auto-display inline as a web page with an extra bit of code)
Also, it might be nice for the HTML viewer to set the default background to white regardless of the theme -- I prefer a dark them overall but displaying web pages inline can be unreadable if the web page assumes a light background (which a lot do).
Compare these two screenshots (viewing Java docs inline):
(fyi @djblue gave me a code snippet to solve this -- see long thread above! -- thank you!)
I'm curious, why is portal.api/tap
deprecated?
I think it's better if people do (add-tap #'p/submit)
because then it obvious how to stop pushing values to portal, (remove-tap #'p/submit)
.
Also, you have the ability to wrap submit with custom logic, like attaching date/time and any other customizations you'd like 👌
Fair enough. That was how I'd started using Portal but then I saw (p/tap)
in the example code somewhere...
Ah, there's two mentions of that in the figwheel-main example folder.
I thought I'd read it somewhere else too...
Yup, here: https://practical.li/clojure/clojure-tools/data-browsers/portal.html#starting-portal-on-repl-startup
(defn ->date [value]
^{:portal.viewer/default :portal.viewer/hiccup}
[:portal.viewer/relative-time value])
(defn my-submit [value]
(p/submit
(cond
(date? value)
(->date value)
:else value)))
(add-tap #'my-submit)
This is very useful for values that don't support metadata directly but where you still want to customize display
(fyi @djblue gave me a code snippet to solve this -- see long thread above! -- thank you!)
I've updated my dot-clojure repo to make Portal a "first class citizen" and I'm going to use it at work (instead of Reveal) for at least the rest of this week -- and may permanently switch if it works well for me 🙂