This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-06
Channels
- # babashka (130)
- # beginners (97)
- # biff (36)
- # calva (6)
- # cherry (23)
- # clojure (29)
- # clojure-dev (1)
- # clojure-europe (9)
- # clojurescript (5)
- # datomic (24)
- # emacs (13)
- # fulcro (5)
- # hyperfiddle (33)
- # interop (2)
- # jobs (18)
- # kaocha (1)
- # london-clojurians (1)
- # lsp (20)
- # nrepl (1)
- # off-topic (60)
- # pathom (4)
- # reitit (7)
- # releases (1)
- # remote-jobs (4)
- # scittle (3)
- # specter (1)
- # tools-deps (7)
- # xtdb (16)
the 'use server'
directive causes the compiler to split it into a function that gets run on the backend, and a function that on the client will send an RPC call to the backend function

JavaScript has a ResizeObserver for listening to resize events for individual dom elements How would you integrate it into the life cycle of electric? https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver https://stackoverflow.com/a/39312522
also see this IntersectionObserver snippet: https://clojurians.slack.com/archives/C7Q9GSHFV/p1669672518189879?thread_ts=1669672330.176349&cid=C7Q9GSHFV
This is where I have got to: I'm not sure how to feed my custom listener the dom elements as created by dom/div in my Meadow component
hmm doing some searching in channel, maybe using dom/node inside the context of dom/div will work let's see
please can you paste the code as a single slack attachment - its too hard to read like this due to slack's shit UI
(don't use backtick, use cmd-shift-enter)
I think it's struggling with js/ResizeObserver. at the moment
"its struggling" ?
On the backend there's a stack trace that has "Caused by: java.lang.RuntimeException: No such namespace: js"
you may need to guard the whole function to be cljs only
that function doesn't compile as clojure
also, L19 - illegal e/server inside a clojure lambda. electric stuff is only valid in electric fns
Yeah I switched back to defn, when was trying something, I've put it back to e/defn, I'm conscious I'm trying to return a m/observe object
listen-for-resize should be a clojure function, it doesn't contain any reactive code
Missionary is a clojure/script library, not an electric library
change (emit!)
to (emit! (.-contentRect entry))
the flow returned by listen-for-resize needs an initial value, you can add nil with m/reductions, or call (emit! nil)
once right away at the beginning of mount
. Then, bridge to electric with new
:
(dom/div (new (listen-for-resize dom/node)) ...)
move the e/server stuff to the electric body
(dom/div (let [{:keys [width height]} (new (listen-for-resize dom/node))]
(e/server (swap! !nodes merge (.-id entry) {:width width :height height}))
...))
Here's a minimal interop wrapper that you call as (new (size> my-dom-node))
and returns a reactive view of [width height]
. Change based on your needs.
Met @dustingetz at the conj and he told me about electric clojure, just wanted to stop by after I had a chance to look at it and say Nice Work!
š have you had a chance to tinker with it yet? it's a little bit of a mind wrap but really satisfying
just the live tutorial. I'll take a closer look when I have a UI to build for some internal tooling