←back to thread

170 points bko | 1 comments | | HN request time: 0s | source
Show context
nkh ◴[] No.43649648[source]
One thing I've always liked about the Clojure community, is that they are obessesed with state. I think they have correctly identified, that when things go sideways, it is because state management was involved in some way. This is a cool front end approach using datastar to put all of the state on the backend and side step front end state management entirely. There are some other really interesting things happening with electric clojure and a new "framework" called Replicant. Of all of them, Replicant seems the most intriguing to me personally. If it didn't exist, I think I would be trying to use datastar as this article outlines.
replies(4): >>43649743 #>>43650835 #>>43651272 #>>43652007 #
fancyswimtime ◴[] No.43649743[source]
single minded react user signing in. When dealing with state in react theres generally a good incentive not to model state exactly like the database model. Does Clojure removing this abstraction improve the application? I can see many pros but not knowledgable enough to see the potential shotgun
replies(1): >>43649856 #
nkh ◴[] No.43649856[source]
The Clojure ecosystem embraced react early and built on top of it (with OM, Reagent and Re-Frame (for SPAs). The UI = f(applicationState) is definitely viewed as the correct approach. In other words, gather all your application state in one place. Whenever it changes, pass all of it to a single function to produce the next version of your UI.

Replicant takes this idea and runs with it, narrowing it down even further: The function is a pure function that returns the new UI as data. Replicant uses this representation to update the DOM accordingly.

That’s it. No partial updates, no mutable objects, no network activity from UI components. It’s basically a templating system. You give it data, and it returns a view. Whether that data comes from a DB or any other place, it's just a clojure data structure. Here is the article that most of this comment is lifted from: https://replicant.fun/top-down/

replies(2): >>43650402 #>>43650543 #
enugu ◴[] No.43650543[source]
Doesn't re-frame also work with ui as a pure function of state? (https://day8.github.io/re-frame/a-loop/)

So, is the main difference that replicant is not built on top of react?

replies(1): >>43652486 #
1. diggan ◴[] No.43652486{3}[source]
reagent (which you'd put re-frame on top of) is what handles rendering (via React) when we're using re-frame, and is the library you can say does "UI as a pure function of state". re-frame is basically like redux (over-simplification) but for the CLJS ecosystem, focuses solely on state and how to mutate it.