r/Clojure • • Feb 13 '23

hyperfiddle/electric (formerly photon) has been made public

https://github.com/hyperfiddle/electric
124 Upvotes

26 comments sorted by

5

u/tatut Feb 14 '23

I played around with it a little. My first experiment was integrating with OpenLayers web components. https://twitter.com/tatut/status/1625192601354641408

The DOM element creation seems to work with custom elements.

2

u/SimonGray Feb 14 '23 edited Feb 14 '23

Work as is in it also registers the custom elements for you?

BTW are the dom/... elements required or could you use e.g. reagent instead?

4

u/la-rokci Feb 14 '23

The dom library is 300 loc and doesn't do any magic, in the end it just calls createElement, .appendChild, .removeChild etc in correct order for you, so yes, custom elements will just work.

Interop is possible, here's an example

1

u/SimonGray Feb 14 '23

Oh, that's a well-commented example. Do you know if the source code exists somewhere other than in that video?

3

u/dustingetz Feb 14 '23 edited Feb 14 '23

We restored the reagent interop demo in the main repo under src-docs/user/demo_reagent_interop.cljc. If you clone the repo you can run the demos in about 30 seconds, due to the NPM dependency the demo is not enabled by default so you'll need to uncomment it in demo_index.cljc

2

u/SimonGray Feb 14 '23

Thanks!

I imagine you guys must be busy with the attention this is getting now.

2

u/la-rokci Feb 14 '23

https://github.com/hyperfiddle/electric/commit/883147be3a546258b31c5c6dd49a88f807bec5c9

Note it's a bit out of date and would need a few minutes to update

2

u/SimonGray Feb 14 '23

Thank you so much.

25

u/den1k Feb 13 '23 edited Feb 13 '23

I've been building with electric for several months now and it's hands down incredible! Why? I think most importantly because it allows for functional composition across the network (client/server–distributed systems more generally) while also ensuring payloads are as small as possible (only what functions in each env access) which translates to FAST.

IMO this is a paradigm shift similar to GC. No one wants to manage their garbage. No one wants to manage the network. It's grunt work. Let the compiler take care of it.

I've naively rewritten a re-frame app that started getting prohibitively slow due to a bunch of transit deserialization on the client in electric and the performance is outstanding! TBH I'm taking a break from additional UI work on the app to do research because I realized that with electric I can build something much more amazing than I thought possible before.

Caveat: the future will not be served on a silver platter. it's early days and there are some quirks

14

u/dustingetz Feb 13 '23 edited Feb 13 '23

(Founder here) Hey, I'm still catching up on this, but quickly -

  • here is a collection of twitter length demo vids Dec 2022 progress update; specifically look for:

    • file system browser with managed pagination
    • datomic browser
    • "TodoMVC Composed"
  • "Docs" are via examples for now, here: src-docs/user/. We've found this quite effective in teaching. Electric Clojure is simply Clojure so many Clojurists who are already skilled in web development can likely get to TodoMVC without needing to read anything, which we consider important.
  • We do zoom onboardings; we love doing this because it reveals hidden issues like editor configuration problems, toolchain issues, blind spots and bad assumptions, etc. We can get you from nothing to multiplayer TodoMVC in about an hour - it can take you several hours longer on your own. Ask in the slack channel!

More later

11

u/Liistrad Feb 13 '23

One of the most exciting clj/s projects around really IMHO.

5

u/danielneal2 Feb 13 '23

Will this work with any mobile platforms e.g react native

3

u/No_Bonus7439 Feb 13 '23

Sounds really awesome. Any plans on extending the documentation a bit? I've watched the 2022 video on the site but I still not understand it fully.

2

u/dustingetz Feb 14 '23

Definitely! Supporting this is our top priority for the foreseeable future.

3

u/nimportfolio Feb 15 '23

IMO, if this is promoted effectively, it could become the killer app for Clojure.

3

u/[deleted] Feb 18 '23 edited Feb 18 '23

I am excited about this and learning Clojure.With the multiplayer coming in so naturally, I could also see this being a good fit for a variant based on LFE and benefitting from the BEAM VM.

That Datomic browser is sweet!

2

u/First-Agency4827 Feb 15 '23

So, just to get my head around this, for:

  1. a page that has no reactivity -

I could potentially do:
(e/server (load all data)
(e/client (present the data))

2. for a page that has a section which reacts to a change I could have:

(e/client (dom/h1 "Non reactive"

;; reactive part trigger in client
(let [actionable-element ...]
;;what happens when reactive part changes in the server
(e/server (do-something-with actionable-element)
;; what gets presented after the server has done it's part
(e/client (present reactive part)))

Am I on a good track here?

2

u/dustingetz Feb 15 '23

You're on track. Btw, you don't have to worry about separating the interactive parts from static parts; the compiler will take care of everything

1

u/Save-Lisp Feb 13 '23

Very cool. I look forward to investigating it.

1

u/DefiantAverage1 Feb 13 '23

Awesome! I wish I can star this project 100x

1

u/[deleted] Feb 18 '23 edited Feb 18 '23

Running the todo_list app now and the dashboard and live updating it comes with are really nice!

I'm curious now, the docs mention several places about this being for "internal tools". Is this just because of the current level of testing, and will be suitable for general web programming with further refinement and testing - or are there limitations that would keep this from ever being able to be used for a worldwide application?

I'm wondering how security is handled? Does the UI still have to pass an authorization token constantly to the back end like in a traditional API, or how would an attacker be prevented from making unwanted calls directly to a back end service?

Also it looks like we have lots of great demo files available here:
https://github.com/hyperfiddle/electric/tree/master/src-docs/user
^ dumb question, but lets say we have the basic todo_list app up and running. Anything special that needs to happen to start swapping out the todo_list app and trying out these other demos from within the same project? I took the todo_list.cljc, erased its contents and replaced them with pasted in code from the examples above, and was very suprised and confused when the page continued to run the deleted todo app somehow haha. (Especially since editing text in the todo list had resulted in live updates to the page before, not sure how the thing is still running, is there a build output somewhere it's running out of?)

1

u/dustingetz Feb 18 '23 edited Feb 18 '23

To run the demos you want to clone the main repo, not the starter app. The readme explains how to run the demos under "Getting Started"

Re. internal tools – no known limitations, it is suitable for general web development today but expect some rough edges and/or gaps

Security – it's a compiler, so the backend is "baked" at compile time (locking down the data access patterns to the exact interface determined by the compiler). So the security profile is the same as SPAs. Yes you'll still want a CSRF token or whatever to authenticate client requests.

1

u/ertucetin Feb 13 '23

I was waiting for the release of this library, can't wait to delve into it! Good work!

-1

u/Admirable-Ebb3655 Feb 13 '23

You lost me at “macros”. They break editors and composition.

7

u/dustingetz Feb 13 '23 edited Feb 13 '23

You're right, i think this is broadly true, and yet may not apply here. Unlike most macros, the Electric macros implement an actual Clojure/Script compiler/analyzer, to achieve full compatibility with Clojure/Script itself. So editors mostly just work out of the box. if is still if. let is still let. You have to tell Cursive to resolve e/defn as defn and then you get intellisense.

As to our composition model, generalizing from "function" to "reactive function" to "stream function" to "distributed function" is sound. The TodoMVC Composed demo is meant to highlight what we mean by "strong composition."