Fork me on GitHub
#hyperfiddle
<
2023-09-19
>
Kein07:09:23

In what situation does a body expression in e/fn won’t be executed and is skipped? I have a function where I do datalog query. This function is triggered when an event happens and the corresponding atom changes. The issue is that any expression that depends on the query won’t be executed.

(e/defn create-data! [data]
  (let [a  (e/server (d/q '[A-DataLog-Query] db))
       ]
    
    (e/client
     (println "First") ;Executed regularly
     (println "Second" a)) ;It is skipped
    )
)

Kein07:09:11

x is a , I mistyped

xificurC07:09:43

can you show the callsite? Most likely the callsite is mounting and immediately unmounting the e/fn, so anything synchronous gets through and anything that requires a roundtrip is lost

Kein08:09:23

what is a callsite?

xificurC08:09:42

where you call create-data!

Kein08:09:52

In the event callback function, bound in (e/for-event-pending-switch)

Kein08:09:42

In e/for-event-pending-switch, I call an e/fn which depends on db query

xificurC08:09:31

the -switch in the name means if a new event arrives the previous one's execution is cancelled. My guess is a new event arrives in before the previous finished executing. You can check by printing out the events. If you need all events processed, even if they overlap (overlap = event E1 is still running while E2 comes in), use e/for-event-pending

👀 1
Kein08:09:17

Is it possible that only the expressions that depends is lost, and others return properly?

Kein08:09:36

The issue still exist after I changed to for-event-pending

xificurC08:09:31

possible if the dependent expression threw an exception

Kein08:09:14

Is there a way to check these potential errors?

xificurC08:09:59

these helpers don't rethrow exceptions, you can wrap it like https://github.com/hyperfiddle/electric/blob/5a3799bdca4f70aed0dc51ac98ff9728dbffacae/src/hyperfiddle/electric_dom2.cljc#L229

(let [[state v] (e/for-event-pending-switch ...)]
  (case state (::e/init ::e/ok) v (::e/pending ::e/failed) (throw v)))

Kein08:09:40

Ok thanks

Dustin Getz10:09:06

the for-event apis are not meant for userland use due to how complicated they are currently, how did we end up calling them? have i missed something?

xificurC11:09:23

it's used for bridging arbitrary react callbacks

J19:09:55

Hi guys! I don’t remember what e/on-unmount is used to be replaced with?

J19:09:49

Because he is not resolved in the ide

Dustin Getz20:09:16

Yes thanks Tommy - this API has not been deprecated

J06:09:49

Yes sorry! My ide cache is bad…