Fork me on GitHub
#hyperfiddle
<
2023-05-06
>
Vincent17:05:21

lol back to PHP

Vincent17:05:41

SQL into the HTML is like whoa

J18:05:59

I’m curious how this works internally!

lilactown21:05:02

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

šŸ‘ 6
wow 2
Adrian Smith14:05:17

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

Adrian Smith17:05:41

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

Adrian Smith17:05:55

hmm doing some searching in channel, maybe using dom/node inside the context of dom/div will work let's see

Dustin Getz17:05:41

please can you paste the code as a single slack attachment - its too hard to read like this due to slack's shit UI

Dustin Getz17:05:01

(don't use backtick, use cmd-shift-enter)

Adrian Smith17:05:46

I think it's struggling with js/ResizeObserver. at the moment

Dustin Getz17:05:39

"its struggling" ?

Adrian Smith17:05:02

On the backend there's a stack trace that has "Caused by: java.lang.RuntimeException: No such namespace: js"

Dustin Getz17:05:36

you may need to guard the whole function to be cljs only

Dustin Getz17:05:47

that function doesn't compile as clojure

Dustin Getz17:05:21

also, L19 - illegal e/server inside a clojure lambda. electric stuff is only valid in electric fns

Adrian Smith17:05:17

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

Dustin Getz17:05:15

listen-for-resize should be a clojure function, it doesn't contain any reactive code

Dustin Getz17:05:31

Missionary is a clojure/script library, not an electric library

Dustin Getz17:05:45

change (emit!) to (emit! (.-contentRect entry))

Dustin Getz17:05:16

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)) ...)

Dustin Getz17:05:32

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}))
...))

xificurC19:05:08

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.

Adrian Smith20:05:30

Ah thank you, I need to clean up my code but it works! šŸ˜„

šŸ™‚ 2
Craig Brozefsky18:05:32

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!

šŸ‘‹ 2
Vincent18:05:19

Oh good he's gettin' the word out! It's the future šŸ˜…

Vincent18:05:16

😁 have you had a chance to tinker with it yet? it's a little bit of a mind wrap but really satisfying

Craig Brozefsky18:05:55

just the live tutorial. I'll take a closer look when I have a UI to build for some internal tooling

Vincent18:05:00

nice. yeah the live tutorial explains a ton.