Fork me on GitHub
#hyperfiddle
<
2023-09-29
>
nivekuil00:09:03

out of curiosity, has the electric team looked at e-graphs?

Dustin Getz00:09:51

no , looks optimization related which we mostly haven’t gotten to yet

nivekuil07:09:48

not using https://github.com/hyperfiddle/electric/blob/master/src/hyperfiddle/history.cljc, but looking at it I'm wondering how you would restore scroll position on back/forward (life is very painful without this). You need some top-level way of knowing when everything has been rendered before you can set the scroll position. how do you do that when everything is rendered eagerly? is thunking ~@body always enough to perfectly defer all effects?

👀 1
Dustin Getz10:09:55

good q, we will need to think about this

Dustin Getz10:09:13

possibly electric-dom will need to be changed, there have been some chats internally about doing batched dom updates which is related

Dustin Getz10:09:40

differential electric is first

Can07:09:50

Hello! Is there any example in Electric we generally use JavaScript for learning. I.e. I picked a basic page (one input one button) on the internet and tried to write the same code in electric. But while same code working nicely in the HTML compiler My code in electric my javascript validation function doesn't work. What is wrong here? https://gist.github.com/Bariscanates404/4549b116fe44b3da1fd82315fedad4c9

nivekuil07:09:42

why do you think it doesn't work? have you tried printing the value of username on click?

Geoffrey Gaillard07:09:45

(def usernameInput (.getElementById js/document "username")) executes on JS file load (when the page loads) At the time it runs, the #username HTML is not mounted yet

Can08:09:40

I giving an invalid number input i.e. "12" it must be a minimum of 3 characters. That doesn't show me an error as in HTML

nivekuil08:09:27

well, geoffrey gave you the answer 😛 but generally you can narrow down what the problem must be by printing stuff out that you think should be run

Geoffrey Gaillard08:09:07

Also, while Electric compiles down to JS, their evaluation model are different (imperative vs reactive). You cannot directly translate idiomatic JS into idiomatic Electric. Let me get back to you with an idiomatic Electric code snippet

👀 1
nivekuil08:09:17

electric creates the elements dynamically when the js is run, while the browser will read the html first and create those elements before the js is run

Can08:09:53

@U2DART3HA Thanks, I want to learn JavaScript usage in electric I think i will need it always 🙂

Geoffrey Gaillard08:09:05

Notes: • + in clojure only does addition. Use str to concatenate strings • < , >, <=, >= can take more than two args. Useful to check ranges: “x is between 3 and 12 included” : (<= 3 x 12) If you want to call addEventListener manually, you can do so on dom/node:

(dom/button ; in this block, the current DOM node is bound to `dom/node`
  (dom/text "Click me")
  (.addEventListener dom/node "click" handle-click))

(defn handle-click [^js event]
  (js/alert "Button was clicked")) 

Can08:09:53

Thanks! Starting study on it.

Can08:09:06

That is very valueable help for me. 🙂

Dustin Getz10:09:29

I would consider doing all imperative js-style code in ordinary clojurescript until you have a reason not to. Just use defn instead of e/defn

Dustin Getz11:09:19

I guess you were already doing this, maybe this comment isn't helpful

Dustin Paluch16:09:23

How would you remove the reactivity from TwoClocks, such that the current time on server/client is displayed once immediately but then not updated? Or perhaps, add a button that turns the streaming updates on or off?