Fork me on GitHub
#hyperfiddle
<
2023-06-22
>
s-ol07:06:15

I've noticed that when I change my reactive database from within a (ui/button (e/fn [] ...)) in some cases that e/fn updates twice or even causes an infinite update loop. How can I prevent that and "freeze" reactive vars on mount in the e/fn?

xificurC08:06:06

can you share the code that behaves this way?

s-ol08:06:50

I can share the repo, but you probably won't be able to get it to repro easily because I don't have code to seed the database

braai engineer08:06:35

I'm trying to demo electric-starter-app on a fresh Mac that has Clojure installed via brew install clojure/tools/clojure but am hitting a Cursive exception when opening the project or attempting to start a REPL in IntelliJ:

java.util.concurrent.ExecutionException: com.intellij.execution.ExecutionException: Cannot execute: /usr/local/bin/clojure does not exist
	at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396)
	at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2096)
	at org.jetbrains.concurrency.AsyncPromise.get(AsyncPromise.kt:49)
I can run clj -A:dev -X user/main in terminal just fine, but then I can't do REPLy things. Hopefully this is a simple linking issue? I also tried brew install clojure.

s-ol08:06:33

leave off the -X user/main and it drops you in a repl, then run (main) to start the compiler

s-ol08:06:07

there's probably a way to connect Cursive properly but I don't know that tool

braai engineer08:06:29

@U05AL1ZH8TW clj -A:dev does not seem to start an nREPL, at least not one that I know how to connect to: there is no .nrepl-port file.

braai engineer08:06:17

I realize I can add an nREPL dependency etc., but would really like to be able to use the Local REPL feature in Cursive.

s-ol08:06:04

yeah, it's a plain clojure repl. I just did a quick search and it seems that you can configure Cursive to use a 'clojure.main REPL' which is what you want, I think: https://cursive-ide.com/userguide/repl.html#local-repls

braai engineer08:06:51

FIXED: add a symlink like so:

sudo ln -s /opt/homebrew/bin/clj /usr/local/bin/clojure

👀 2
s-ol08:06:45

just curious: is there a /opt/homebrew/bin/clojure?

braai engineer08:06:09

yes because I installed Clojure via Homebrew, e.g.

➜  ~ which clj
/opt/homebrew/bin/clj

s-ol08:06:27

I meant clojure (long-form)

braai engineer08:06:48

yes,

➜  ~ which clojure
/opt/homebrew/bin/clojure

s-ol08:06:01

maybe it expects to find that next to clj, but the symlinking breaks that

braai engineer09:06:10

no, it was looking for /usr/local/bin/clojure which did not exist (and was not symlinked).

braai engineer09:06:02

Both /opt/homebrew/bin/clj and /opt/homebrew/bin/clojure` are symlinks to files in Cellar paths.

braai engineer11:06:09

I see that hyperfiddle.electric-svg/svg-element, uses dom/with and e/on-unmount to inject SVG nodes. Would this be considered a good reference for dealing with imperative libraries that need access to underlying DOM nodes, e.g. Mapbox GL? For various reasons I don't want to use React go-betweens because it adds a lot Reagent/React complexity and would rather just add map events myself and deal with component lifecycle.

Dustin Getz11:06:56

you don't need dom/with, you just need dom/node

braai engineer11:06:55

Thanks, Dustin. How do I do cleanup on unmount?

Dustin Getz11:06:11

Clean up what exactly?

Dustin Getz11:06:30

on-unmount means what it means in reactjs

Dustin Getz11:06:10

Your Mapbox integration is likely not going to be coded in electric, it will manage all the callbacks and events with a missionary adapter

Dustin Getz11:06:23

so your callback allocation/disposal will be managed by m/observe

braai engineer11:06:40

thx, any examples around? BlinkerComponent example is simple

Dustin Getz11:06:46

search m/observe

Dustin Getz11:06:21

in the slack

👍 2
Vincent21:06:49

I'm a little confused on how to achieve POST via cljs-ajax from Client to Server.

(ui/button 
 (e/fn [] 
  (do (.log js/console !w)
   (POST "/create-account" 
          {:params {:w !w} 
           :format :text}))) 
 (dom/text "Hit me"))
using cljs-ajax to accomplish the POST but on the server I see
:body #object[org.eclipse.jetty.server.HttpInputOverHTTP 0x21eee3a5 HttpInputOverHTTP@21eee3a5[c=0,q=0,[0]=null,s=STREAM]],
when reading ring-req

Dustin Getz00:06:35

i’d guess you’re missing a middleware

Vincent00:06:01

yeah i think so, tried adding some json reading middleware, still looking into it

Vincent00:06:20

i appreciate all the help i really do 😅