Fork me on GitHub
#hyperfiddle
<
2023-03-14
>
Fit Opene12:03:30

hello, I just started learning Clojure and I really appreciate this Electric library. However, I don't know how to use it in an Expo + React Native project. I tried modifying the https://github.com/PEZ/rn-rf-shadow project, but I've been struggling for a day with configuring deps.edn and shadow-cljs.edn, and I can't seem to make it work. Could you give me some advice on this? Thank you.

๐Ÿ™‚ 2
Dustin Getz12:03:10

We have not yet tried React Native, it will likely not work yet with Electric

Dustin Getz12:03:37

I have no reason to believe it won't work, but we know nothing about React Native as a platform, so I'd assume some minor work is required

Fit Opene12:03:37

Thank you for your reply, I will keep trying and hopefully make some progress soon.

denik18:03:51

would like to set pending state on an atom for a loading state but strangely pending is caught twice

(defmacro set-pending [atm & body]
  `(try (let [ret# (do ~@body)]
          (and (do ret# true)
               (do (println :done) true)
               (reset! ~atm false)

              ret#))
        (catch Pending e#
          (println :pending)
          (reset! ~atm true)
          (throw e#))))

xificurC19:03:57

is this on master? There were a couple of fixes around try/catch lately

denik19:03:20

yup Iโ€™m on master

xificurC19:03:38

it's also possible body is throwing Pending twice. Can you provide a repro?

denik19:03:27

even if it does that should be okay, is there an ultimate Success / return state?

xificurC19:03:22

I mean if the body goes e.g. Pending, v, Pending, v then seeing 2 Pendings is fine, right?

xificurC19:03:24

this prints a single pending (p/run (set-pending (atom 1) (p/offload #(do 2))))

denik19:03:42

this sets pending to true but not back to false

xificurC19:03:13

I see. That's because in electric almost everything is running concurrently. (try a b c) will run all of them at the same time. So (reset! !p false) will finish before hitting the catch handler

xificurC19:03:56

You can do (catch Pending _ (reset! !p true) (e/on-unmount #(reset! !p false)))

xificurC19:03:53

to elaborate a bit, the electric code

(do (throw (ex-info "boom" {}))
    (println "hi"))
will both throw and print, because all of dos children are running concurrently

denik20:03:15

okay great thanks that worked

denik20:03:16

(defmacro set-pending [atm & body]
  `(try (do
          (e/on-unmount #(reset! ~atm false))
          ~@body)
        (catch Pending e#
          (reset! ~atm true)
          (throw e#))))

xificurC20:03:35

I'd put the unmount call in the catch block. In your use case ( (dom/on "click" (e/fn [_] <here>)) ) it makes no difference though

๐Ÿ‘ 2
denik20:03:19

getting a lot of these after reloads, never before

๐Ÿ‘€ 2
โœ… 2
denik20:03:48

anyone else have that issue?

Dustin Getz20:03:00

i think we are seeing it too

Dustin Getz20:03:08

what commit are you on?

denik20:03:54

7d184721c4b470f18002fbc248dc3018329526c7

denik20:03:59

have been seeing it for a while though

Dustin Getz20:03:36

are you doing css work lately?

denik20:03:52

yes though itโ€™s been intermeshed w everything else

Dustin Getz20:03:37

We're bisecting, the key piece of the repro is to touch a css file and ALSO load it like this: (dom/link (dom/props {:rel :stylesheet, :href "/todomvc.css"}))

Dustin Getz20:03:51

Seems we can repro all the way back to last summer

Dustin Getz20:03:59

Are you also loading css like that?

adamfrey21:03:41

is there a different / better way to load a css file for electric? That form matches https://github.com/hyperfiddle/electric-starter-app/blob/main/src/app/todo_list.cljc#L57

xificurC21:03:53

this is buggy, we're searching why. Seems to be a months old regression

Dustin Getz21:03:08

Yeah you can probably work around this by loading css through index.html

Dustin Getz21:03:35

Peter bisected this back to August 2022, this is the first time we noticed

xificurC10:03:07

@U050CJFRU this might be related to a fix we just landed, can you try updating to latest master and see if the problem still persists?

denik16:03:13

@U09FL65DK it seems to be gone! will report back should I see it again. thank you!

๐Ÿ‘ 4
denik17:03:27

@U09FL65DK on master still seeing this occasionally

xificurC07:03:16

Sorry to hear that. We haven't seen this after the latest fixes, so if you find a good repro let us please know