This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-02
Channels
- # asami (5)
- # aws (16)
- # babashka (41)
- # babashka-sci-dev (44)
- # beginners (157)
- # biff (3)
- # cider (1)
- # clj-commons (1)
- # cljdoc (22)
- # clojure (7)
- # clojure-dev (5)
- # clojure-europe (13)
- # clojure-nl (1)
- # clojure-uk (1)
- # clojurescript (17)
- # core-typed (13)
- # cursive (14)
- # datascript (10)
- # events (1)
- # fulcro (2)
- # graalvm (2)
- # gratitude (1)
- # jobs (3)
- # lsp (229)
- # pathom (2)
- # pedestal (3)
- # portal (53)
- # re-frame (7)
- # remote-jobs (1)
- # spacemacs (14)
- # xtdb (6)
On hacking on portal: I will try to share here my experience trying to see how portal works, and add features (in thread). I understand that the problems I'm getting are caused by my (wrong) mental models and inexperience, and so this is me trying to patch them. I will appreciate whatever explanation may come in response 😂❤️
Let's say I want to add a new color schema to portal, and I find the src/portal/colors.cljc
file. Now, I want to be able to try the colors interactively, so I want to open a repl. The documentation on github suggests, since I use emacs, to cider-jack-in-clj&cljs
. I'm a little confused about why I have to connect to both a clj and a cljs repl (this is not particularly tied to portal, I'm just confused about this).
A little trial and error later I know that I should have chosen clojure-cli
when prompted about which command to use, and then choose :client
as the shadow target (just because the others seem less probable). When I do that I get briefly the error message:
error in process filter: ClojureScript is not available. See for details
but on the other hand I can evaluate sexps in the repl that is open. Since I don't see a browser, given the error, I suspect that only the clj
part of the repl is open, but don't know what that implies for me. I try to eval something. I wish I could start a portal, I go to portal.api
, I open a repl in the usual manner. I go back to portal.colors
, do some modification to a theme, eval back and forth a couple of time, but can't change the actual colors.
I remember that there's a dev
folder that probably contains useful code;I find that there is a start!
, watch
, and repl
in dev/user.clj
that I should probably try to use. I try to eval the namespace declaration in dev/user.clj
and I get:
Could not locate tracker__init.class, tracker.clj or tracker.cljc on classpath
Some grep
later, I understand that I should have probably started my repl with the :dev
alias, so that I get the ns-tracker
dependency. I restart the repl. Same cljs error as before but now it dawns on me that maybe I should also include some other aliases, like :cljs
, or :shadow
. There are a bunch of them, and while I can see the dependencies that they bring in, I'm not sure I understand the affordances that they'll bring me. Let's go with :dep:cljs:shadow
as added dependencies.I pushed up a fix for .dir-locals so jack-in should work better now. Also, cleaned up user.cljs to make things easier. I would try master real quick and see if it's any better 👌
Thank you! I'm going to try this right away. I hope this kind of narration is useful to you too (maybe to understand where a beginner might struggle). It is surely useful to me 😍
Yeah, if you are having issues working in the source tree, it's probably something that needs to be fixed via docs or code 💯
Also, I think themes are pulled in directly by the cljs code so you just need to save the file and shadow should do the rest 👌
The need for two repls is because one is connected to the host runtime (jvm) and the other will be connected to the portal ui which will be running in the browser.
I know that this sounds like a very dumb questions, but, when I open both a clj
and cljs
repl in emacs, and I can find two buffers that are repls, but both seem to have shadow cljs stuff:
;; Startup: /run/current-system/sw/bin/clojure -A:dev:cljs:shadow -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.9.0"} cider/cider-nrepl {:mvn/version "0.28.3"} refactor-nrepl/refactor-nrepl {:mvn/version "3.5.2"} cider/piggieback {:mvn/version "0.5.2"}} :aliases {:cider/nrepl {:main-opts ["-m" "nrepl.cmdline" "--middleware" "[shadow.cljs.devtools.server.nrepl/middleware,refactor-nrepl.middleware/wrap-refactor,cider.nrepl/cider-middleware,cider.piggieback/wrap-cljs-repl]"]}}}' -M:cider/nrepl
is the same thing as:
;; Startup: /run/current-system/sw/bin/clojure -A:dev:cljs:shadow -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.9.0"} cider/cider-nrepl {:mvn/version "0.28.3"} refactor-nrepl/refactor-nrepl {:mvn/version "3.5.2"} cider/piggieback {:mvn/version "0.5.2"}} :aliases {:cider/nrepl {:main-opts ["-m" "nrepl.cmdline" "--middleware" "[shadow.cljs.devtools.server.nrepl/middleware,refactor-nrepl.middleware/wrap-refactor,cider.nrepl/cider-middleware,cider.piggieback/wrap-cljs-repl]"]}}}' -M:cider/nrepl
how do I see which one is the clj
one?and then, assumed I want to in fact hack colors, which portal should I open? Both the one in portal.api
and the one in portal.web
will have an interface
Either or should be fine, the running client code is the same so it should be identical
ok, so, I in the clj
one I required portal.api
and started a portal. Then I changed some colors in colors
, but pressing C-c C-c
doesn't change anything. When I have two repls, who am I sending the evaluation to?
I'm also noticing in the cljs repl I have a repeated occurrence of:
[:client] Build failure:
The required JS dependency "anser" is not available, it was required by "portal/ui/inspector.cljs".
which might be the reason for which hot reloading isn't working. And then, trying to evaluate (require '[portal.web :as p])
in the cljs repl tells me that there are no available js runtimes (maybe because of the error)
Also, if you are trying to open the dev version of portal, you need to do {:mode :dev}
In general though, if I didn't write in the cljs repl, but just issued the eval shortcut on a piece of code, which repl is going to get that? Both?
So, I think for cider, it depends on the file extension: clj -> clj repl, cljs -> cljs repl, cljc -> both repls
so, after an npm install
, the cljs repl compiles now, but still, if I try to require something in there, it will complain about not having a JS runtime. Is that a thing that I shouldn't be doing?
I think juggling multiple runtimes is one of the challenging aspects of working on portal
I opened a jvm portal in the clj repl, but still the same error when trying to open this portal.web/open in the cljs one complains for lack of a runtime
because it really seems that we could have just the JVM one, and do everything? Right?
The major exception is having access to native objects, the jvm specific one doesn't have access to js objects
so, when developing a cljs project that has a lot of js interop, a cljs portal is strictly more useful, right?
Usually I will open a dev portal and the web portal will be a prod one so my changes don't break my debugging
You mentioned in one of your presentations on portal that there's this kind of meta-hacking, but it never went into the presentation, and it's extremely interesting
First initial proposal for a gruvbox
theme https://github.com/djblue/portal/pull/118