Fork me on GitHub
#hyperfiddle
<
2023-03-02
>
JAtkins00:03:35

Live reloading seems to break sometimes. I'm in the electric datomic browser demo adding a new router endpoint, and when I make a new file anything in that file stops updating.

(ns app.trial
  "must have datomic on classpath, and must load 'test ns"
  ;;#?(:cljs (:require-macros app.trial)) ;; I'm using a git dep on latest electric, no longer needed
  (:require
   [hyperfiddle.electric :as e]
   [hyperfiddle.electric-dom2 :as dom]))

(e/defn Child 
  []
  (e/client
   (dom/div (dom/text "hirt"))) ;; Changing the string has no effect on the browser
  )
;; In the router in app.datomic-browser

(e/defn Child 
  []
  (e/client
   (dom/div (dom/text "hidb"))) ;; Changing the string updates the browser
  )

;; Referring to the second file, doesn't update properly
::test-page (history/router 1 (e/server (app.trial/Child.)))

;; Referring to this file, updates properly
::test-page (history/router 1 (e/server (Child.)))
This seems to be isolated to the datomic browser repo, since demos in the electric repo work fine as well. Any ideas?

2
Dustin Getz03:03:23

Ok, from your comment it seems you have this linked up against electric master, so you know about and have the latest hot code reloading changes

Dustin Getz03:03:01

Ah, the :dev/always flag might be on the wrong file now ... checking

Dustin Getz03:03:26

the meta comes first

JAtkins03:03:37

Ah! Ok perfect thanks! I didn’t even realize that was in the ns decl :)

vincent01:03:15

i expect the view to update w/ the change in atom state, but some components are not hiding ... hmm

vincent01:03:51

i need to change something about how i store user views x)

vincent01:03:25

the view the current user is experiencing should live on the server, probably tied to the session var

J10:03:49

Hi guys, I have a weird behaviour with datalevin and pending. Sometimes, the catch branch is not unmount. Here, a code to reproduce (https://gist.github.com/jeans11/3401cc6b23f0dd8f889971f6aa76fcac).

👀 2
2
Dustin Getz11:03:29

ty, we will investigate

xificurC14:03:41

Hi @UHZPYLPU1! Thanks for the repro! https://gist.github.com/xificurC/1cbc281dd49e7eb3c9f5adcba6382158. I'm not sure why your version glitches, but it's a tricky beast that catches Pending on the server and requests the client to render something, which will throw a new Pending! A better way to do this is to try/catch on the client, which resolves this issue

J15:03:32

Thanks @U09FL65DK! You rock

😉 2
Dave Mays11:03:14

Really excited about Electric, and the demos are helpful. I apologize for asking this because it is so basic, but are there any walkthroughs or example repos on how to connect to a persistent DB? Being new to the Clojure world (let alone Electric) I'm still figuring out the DB options (Datomic, Datascript, XTDB) but these Datalog based DBs are part of what draw me to Clojure in the first place, and am leaning towards XTDB (not asking for XTDB specific instructions.) The standalone starter app's require statement seems to show a conditional #?(:clj allowing us to say what runs on the server side. I was suprised datascript is server side, I thought it was client side for some reason, and "meant to run in the browser." Is datascript appropriate for persistence in production, or would one of the others be needed? With Electric being automatically "multiplayer", what tells other user's UIs to update? When a bunch of different client UIs need to, update do they each re-read directly from the database, or does a websocket just tell them what pieces to update?

👀 2
2
Dustin Getz11:03:25

there is a rudimentary SQL tutorial linked in the readme, more robust examples coming soon. we use datascript in examples because it is zero setup but conceptually any db works mostly the same

Dustin Getz11:03:24

we have a WIP XTDB starter as well, it’s a common request, will try to land it this week

Dustin Getz11:03:57

re sql view updates - on mobile now, will write more in a few hours after my meetings this morning

Dave Mays11:03:02

Thanks I'll track down the SQL tutorial, and keep an eye out for the XTDB! Thanks again, really exciting work!

🙂 2
tatut11:03:10

XTDB is basically as easy to get started as datascript, you can start a node with (xt/start-node {}) (for in-memory) to get started

👍 4
💡 2
Dustin Getz15:03:25

I'm looking for a cooler SVG demo that highlights multiplayer, LMK if anyone does something with it

vincent15:03:36

wishlist: recompile only the bits of sourcecode and deps that changed x)

👍 2
Dustin Getz15:03:56

on the roadmap, we want it too

vincent15:03:15

figured. just wanted to cast a vote 😅

Dustin Getz15:03:44

for now the best trick is to comment out the pages of your app you aren't actively working on, also use a fast computer (I know you mentioned you had two)

Dustin Getz15:03:45

The compiler is doing a full program analysis on every change, so commenting out parts of the program you aren't developing is highly effective (Yeah i know this is dumb, sorry)

vincent15:03:28

that's a great idea.

Dustin Getz21:03:03

New maven release: {:mvn/version "v2-alpha-123-ga7fa624f"} Changelog since 2-0: • hot code reloading stability improvements. note: you MUST run shadow and your REPL from the same JVM; do NOT use shadow from nodemodules!_ • drop need for :require-macros in electric src files • e/wrap is now e/offload, note the signature changed it takes a clojure thunk now, https://github.com/hyperfiddle/electric/blob/3fb66e9da5ee96a3efc81c56d2af8dd3b090486e/src-docs/user/demo_3_system_properties.cljc#L24 • zero config entrypoint – please compare to the https://github.com/hyperfiddle/electric-starter-app/blob/a8810accfdd96f82eefc2d976645538223a88de9/src/user.cljs#L7-L10 to see if any entrypoint boilerplate can be removed • clojure deep def is now supported (for debugging) • SVG support • shadow-css is now supported • added e/on-unmount, see the https://github.com/hyperfiddle/electric/blob/3fb66e9da5ee96a3efc81c56d2af8dd3b090486e/src-docs/user/demo_4_chat_extended.cljc#L55. Notes: (a) this interface is going to change; (b) e/mount has been removed, https://github.com/hyperfiddle/electric/commit/dfcfe505e8142f06b5001d0eda00f7b406d1bb95 • async stack traces were improved • fix: reactive exceptions no longer spam the console • fix: pending bugs • electric-goog-history example https://github.com/hyperfiddle/electric/blob/3fb66e9da5ee96a3efc81c56d2af8dd3b090486e/src/contrib/electric_goog_history.cljc, this is going to move and have breaking changes but we do commit to maintaining it somewhere • misc fixes • starter app and datomic-browser are updated • clj-kondo config is exported • legacy photon-ui and photon-dom are removed, you must upgrade • introduced dom/on! optimized callback for fast events like https://github.com/hyperfiddle/electric/blob/3fb66e9da5ee96a3efc81c56d2af8dd3b090486e/src-docs/user/demo_reagent_interop.cljc#L70 (note: usage is going to change soon, the atom in this example is pure overhead)

metal 8
clojure-spin 4
👏 6
🎉 6
pez05:03:19

Can you give an example for hire to run shadow from the same JVM as the repl?

Michael W06:03:51

You can just run a calva deps.edn + shadow repl, then load user.clj and run (main) from the comment to get a consolidated repl for calva.

pez06:03:46

Thanks! In Calva, it is slightly less convenient to run deps.edn + shadow-cljs, than just shadow-cljs. But the latter isn't an option anymore, right?

Michael W06:03:09

I'm not sure I have just always done deps.edn + shadow

👍 2
pez06:03:45

@U09K620SG: You think this PR needs to be adapted to this new reality? https://github.com/hyperfiddle/electric-starter-app/pull/8

👀 2
pez06:03:34

If so we need to fix the config and instructions for the main repo as well.

Michael W06:03:49

Using that starter app and calva I don't see any Electric options for a repl in calva, is that not in calva yet?

Michael W06:03:41

Oh I see it's on that PR branch, that's nifty.

pez07:03:34

@UAB2NMK25, note that you can build in the step you mention to load user.clj and run (main). Something we should consider adding to the repo, once I understand the change mentioned above.

Michael W07:03:40

Yes I got it working with this:

{
    "calva.replConnectSequences": [
        {
            "name": "Electric App",
            "projectType": "deps.edn",
            "cljsType": "shadow-cljs",
            "afterCLJReplJackInCode": "(require '[user]) (user/main)",
            "menuSelections": {
                "cljsLaunchBuilds": [":dev"],
                "cljsDefaultBuild": ":dev"
            }
        }
    ]
}

metal 2
Michael W07:03:03

Thanks for the pointer, was getting tired of having to manually start it from 'user.

🙏 2
tatut08:03:39

I can’t seem to add a class to svg element, is that a known issue?

👀 2
tatut08:03:51

it just doesn’t appear

Michael W08:03:03

I have that same issue, but :style works

tatut08:03:19

good to know, but I’m using tailwind, so rather use the classes it provides

xificurC13:03:21

can you provide a snippet of what code doesn't work?

tatut13:03:28

(svg/svg
               (dom/props
                {:class "stroke-current flex-shrink-0 h-6 w-6"
                 :fill :none :viewBox "0 0 24 24"})
               (svg/path
                (dom/props
                 {:stroke-linecap "round" :stroke-linejoin "round"
                  :stroke-width "2"
                  :d "M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"})))
all the other props come thru ok

xificurC13:03:37

thanks! dom/props https://github.com/hyperfiddle/electric/blob/dfcfe505e8142f06b5001d0eda00f7b406d1bb95/src/hyperfiddle/electric_dom2.cljc#L86 calls (set! (.-className node) ...) which is a read-only field on https://developer.mozilla.org/en-US/docs/Web/API/SVGElement. We'll need to use classList or some goog dom API instead

tatut13:03:06

wouldn’t setAttribute work as well

Dustin Getz13:03:48

there is a complexity, svg/svg element is governed by the svg xml namespace, it's not clear if class is strictly speaking legal here, needs discovery

Dustin Getz13:03:23

It seems it is legal, perhaps the issue is the intersection of the html xml ns and the svg xml ns and how to configure that properly

xificurC13:03:25

I don't know how setAttribute works, so not sure. I think for now something like this would work as a workaround

(-> dom/node .-classList (.add "my-class"))
(e/on-unmount #(-> dom/node .-classList (.remove "my-class")))

xificurC13:03:38

Thanks for the help! I logged a ticket in our system. I'll wait for Geoffrey to help on fixing this since he has more expertise in this field

Dustin Getz15:03:53

@U0ETXRFEW fyi i commented out the calva setup instructions until i verify the correct setup

👍 2
Dustin Getz15:03:43

@UAB2NMK25 you can auto-start by adding a line at the bottom of user.clj to call (main)

pez21:03:22

I like to be able to load any namespace without starting things. So having the call to main in the connect sequence makes sense to me.

vincent23:03:10

question, how can i add an <a href> element? (dom/a (dom/props {:href "url"})) ?

2
Dustin Getz23:03:43

yes, did it not work?

vincent23:03:21

it did not work

vincent23:03:36

testing again....

vincent23:03:12

oh it works

vincent23:03:19

i needed the (dom/text) around the text x)

Dustin Getz23:03:38

ha yes sorry about that it bites us all, hope to fix this spring

vincent23:03:44

2nd question, how can I do like a "slideshow" of several images in clojurescript? would that be using timeout?

Dustin Getz23:03:30

try using e/system-time-secs modulo N

Dustin Getz23:03:13

does that make sense? (on mobile)

Dustin Getz23:03:57

see the “blinker” demo actually