This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-02-26
Channels
- # announcements (1)
- # babashka (6)
- # beginners (12)
- # biff (39)
- # calva (4)
- # cider (5)
- # clj-commons (1)
- # clj-yaml (9)
- # clojure (42)
- # clojure-conj (1)
- # clojure-europe (8)
- # clojurescript-ios (1)
- # clr (1)
- # conjure (7)
- # data-science (1)
- # datalevin (9)
- # emacs (3)
- # helix (1)
- # honeysql (11)
- # hyperfiddle (60)
- # introduce-yourself (1)
- # lsp (26)
- # music (1)
- # off-topic (1)
- # pathom (2)
- # polylith (3)
- # releases (1)
- # sci (1)
- # scittle (21)
- # shadow-cljs (57)
- # spacemacs (3)
- # xtdb (38)
Do you think electric would be a good fit for building something like forum software? How do logins and permissions work in electric?
afaict, permissions would work like in any web software, your server side calls should only access what the current user is allowed to do
I don’t see why you couldn’t build a form in electric, but… even every reader will need a websocket connection and therefore resources from the server. I would wager that if a forum is publicly browsable, it is much easier to cache unauthenticated pages with a traditional full page server side rendering solution.
I don’t know the internals that well, but it seems it would be difficult to cache the WS messaging in any meaningful way
not a good fit yet, need SSR and “resumable” rendering, all of which are naturally done from signals based rendering approaches as proven by Solid.js which is dominating SSR benchmarks right now
however even though it can be done, “website” type apps is not our current focus today; Electric today is for ultra dynamic stateful apps like google docs or webflow or IDE
like we want to rebuild datascript in electric clojure so we can make the query engine network transparent, slice the indexes so they are partially client side so that “last mile” filtering happens on the client - offline first datascript! that’s what the kind of thing electric clojure is intended to make possible
on the other hand, if you tried to build a forum with electric today, the client/server boundary can be refactored and moved around at will, so you could choose to preload the page in one message and then not load anything else until you navigate
so in theory you could probably make it work, even release the websocket when not needed, or use cloud flare durable objects (edge network for websockets with durable state) - lots of possible ways to scale this
No good way to restart the WS today (it reboots the page if you do, both client and server). We already did a first POC of resyncing state on reconnect, but hit a design flaw in the wire protocol preventing us from doing it efficiently. Maybe next iteration? historically we do a major revision about every 3 months
Interesting about possibly rewriting Datascript in Electric. I'm sure other things (like Electric itself) are higher priority but I'm curious if this has been started? Offline first datascript sounds pretty cool. I've also come across Asami which could be interesting as it also runs in browser.
we did some early analysis work, it could be POCed in a couple days
What would be the idiomatic way to update a table in a page, without redrawing/reloading the whole page. I have a table in a page, rows are fetched from the db and table is build, I am trying to add delete functionality, a button deletes the item from the db and removes the row.
(dom/tbody
(e/for [[id fname lname dob] (e/server
(->> (db/patients (e/client (user.)))
(map #(vector (str (:patients/id %))
(:patients/first_name %)
(:patients/last_name %)
(str (:patients/date_of_birth %))))))]
(dom/tr
(dom/props {:id id})
(dom/td
(dom/props {:rowspan "1", :colspan "1"})
(dom/text fname))
(dom/td
(dom/props {:rowspan "1", :colspan "1"})
(dom/text lname))
(dom/td
(dom/props {:rowspan "1", :colspan "1"})
(dom/text dob))
(dom/td
(dom/props {:rowspan "1", :colspan "1" :align "right"})
(h/Button. "Delete" "btn btn-sm btn-outline-secondary"
(e/fn [_]
;;(e/server (db/patient-delete id))
;; (-> js/document
;; (.getElementById id)
;; (.remove))
))))))
Did you see the SQL hello world: https://gist.github.com/dustingetz/1960436eb4044f65ddfcfce3ee0641b7
I did see that I had separate question about that I tried to follow that and wrapped the snippet in a try catch and e/wrap
the db calls but I got no output no error. So if I understood the example correctly, atom changes which triggers the watch so any code within the scope of that watch is rerun?
changing the atom causes the watch to update, which causes any expressions that depend on the watch to update (but not the whole scope, it is fine-grained updates based on a reactivity graph)
I want to make a component that displays the k,v pairs of a map atom as an html table
(e/defn AtomTable [map-atom]
(e/client
(dom/div
(dom/table
(e/for [[k v] map-atom]
(dom/tr
(dom/td
(dom/text k v))))))))
#(:clj (defonce !users (atom (list))))
(e/def users (e/server (reverse (e/watch !users))))
fwiw, this works for me
(e/defn AtomTable [val]
(e/client
(dom/table
(e/for [[k v] val]
(dom/tr
(dom/td (dom/text k))
(dom/td (dom/text v)))))))
(e/defn Other []
(let [atom-map (atom {:foo 42})
atom-map-value (e/watch atom-map)]
(AtomTable. atom-map-value)))
see https://github.com/hyperfiddle/electric/blob/master/src-docs/user/demo_3_system_properties.cljc
actually, not sure :thinking_face: can you define the atom outside the component as clj and still watch it? i'm getting 'n is not a function' :thinking_face:
make sure to watch the atom from the same place it is defined at
i define it on the server, then i want the ui component to ppulate a table of it... hmm
I guess my question is, can I display all the server atoms to the client in real-time?
I guess my question is, can I display all the server atoms to the client in real-time?
if i want to output to both js console and clojure sys out can i do so in the same e/defn?
any ideas how could we improve the tutorials? what document do we need to write that would have gotten you what you need quicker?
i don't mind the learning curve. it is factored into the cost of taking on a new framework always. in this case, it is very profitable because i only need to learn it once to be productive many times. i looked at a basic example and went as far as i could writing code myself.
but when it didn't work as expected, i had to turn to the examples again.
i think a side-by-side page of the code and the demos would be lovely and probably helpful.
a big game changer for me was creating the AtomTable
component and being able to live introspect changing values on the page while working / recompiling. a peek into the "db" of the app. i think those sorts of things will help people grok faster.
do you have code for AtomTable that we should include in a tutorial? send me some scraps of what you have and i'll think about how to include it
ty for the feedback & ideas, keep it coming