This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-12-27
Channels
- # adventofcode (1)
- # announcements (5)
- # babashka (11)
- # beginners (41)
- # biff (16)
- # calva (2)
- # clj-together (1)
- # clojure (9)
- # clojure-austin (8)
- # clojure-doc (1)
- # clojure-europe (45)
- # clojurescript (4)
- # clr (14)
- # datomic (13)
- # figwheel (1)
- # fulcro (11)
- # introduce-yourself (2)
- # lsp (31)
- # malli (6)
- # off-topic (3)
- # releases (2)
- # reveal (8)
- # schema (1)
- # shadow-cljs (13)
- # spacemacs (10)
- # timbre (8)
- # transit (3)
- # xtdb (5)
Hello there, I've got a question about changing one of the bb tasks
, specifically dev
, I think. I'm a little new to this and a bit unsure. I'm writing my code in vim and using https://liquidz.github.io/vim-iced/ to handle all the repl interaction. But to connect to a repl, vim-iced needs me to launch that repl with its own iced repl
command--a step that bb dev
bypasses. I suspect I can fix it by changing line 90 of com.biffweb.tasks to (apply shell {:extra-env {"BIFF_ENV" "dev"}} "iced repl"
but I'm not sure of the best way to go about do that. Any advice would be welcomed!
Hey! You can override tasks by defining a custom dev
task in your project (https://github.com/jacobobryant/biff/blob/master/example/tasks/src/com/example/tasks.clj) and then edit bb.edn
(https://github.com/jacobobryant/biff/blob/master/example/bb.edn#L2) to point to that custom task. See the hello
task for an example.
So you can copy-and-paste the dev
task into that file and make whatever changes you need. Switching that command to launch iced repl
should do the trick. Then from vim, you can start the app by calling the start
function from your main namespace.
That being said, it looks like you can also just run the normal bb dev
command and then do :IcedConnect
A potential downside is that iced repl
might be injecting additional libs/nrepl middleware that Biff does not, so you might want to edit the dev
task as you've mentioned anyway. On the other hand--if you ever want to connect to your app in production via bb prod-dev
or bb prod-repl
, you'll need to use :IcedConnect
anyway.
You could try :IcedConnect
and then see if everything works normally, and then switch to a custom dev
task only if you run into any problems.
Yeah, I thought I would be able to just run bb dev
and then feed the port to the :IcedConnect
command, but it was throwing an error telling me to start the repl with iced repl
instead. At some point, I think I inadvertently got two repls going, one from bb dev
and one from vim-iced, which was the cause of some confusion.
Creating a custom bb dev
has things working now, though!
sounds good! If you ever want to get :IcedConnect
working e.g. for use with prod, you should be able to have biff emulate iced repl
's behavior by adding libraries to deps.edn
as needed and modifying the -main
function (https://github.com/jacobobryant/biff/blob/master/example/src/com/example.clj#L72) to start nrepl with the same middleware that iced repl
does--might need to poke around in Iced's source code to see exactly what it's including though.
Thanks! That seems pretty simple. Presumably, once I do that, I can remove the custom bb dev
.
Got to say, I'm digging working with Biff.
Yep. And glad to hear it!
Weirdly, after two days of the overriding tasks solution working, bb
is telling me it can't find the namespace I put the override in. Near as I can tell, I haven't touched anything that would affect that. So I suspect it is haunted. Might have to investigate modifying the -main
function sooner than I thought.
this is a bug in bb I've been meaning to investigate/mention in the docs/report. sometimes the class path gets messed up/stale for some reason. you can fix it by passing --force to bb, e.g. bb --force dev
or bb --force -e nil
Wonderful! That did the trick. I can put my investigations off for another day.
Is there a straightforward way to do a com.biffweb/submit-tx
and then a com.biffweb/q
on the updated state within the same HTTP request? (get-sys)
works but that's not meant for production.
I thought xtdb.api/await-tx
would work but it doesn't.
Yep:
(fn some-handler [{:keys [biff.xtdb/node biff/db] :as req}]
(let [;; biff/submit-tx includes a call to `xt/await-tx`, so after it returns
;; you know the transaction has been indexed.
_ (biff/submit-tx req [...])
db (xt/db node)]
(q db ...)))
;; alternatively
(fn some-handler [{:keys [biff/db] :as req}]
(let [_ (biff/submit-tx req [...])
;; useful if you want to pass req to more functions and have it include
;; the new db value
{:keys [biff/db] :as req} (biff/merge-context req)]
(q db ...)))
Oooh, I didn't realize node was mutable! 😅 Thanks, that makes it all much easier