Is re-frame for Clojure reactive programming? (answer: no, use nabab instead) #686
Replies: 6 comments
-
Hi @piotr-yuxuan, we added CLJ support for re-frame to support testing and development use-cases. This lets you simulate re-frame handlers calling to in-process 'server-side' handlers, run unit tests from a Clojure REPL, and similar dev-time activities. I've also seen re-frame used server-side to render an HTML page which is then hydrated with Reagent when it is sent over to the client. I guess you could use re-frame for creating a server, but I'm not really sure how it would work. In re-frame the results of your events don't directly create a response, they only update a reactive (in ClojureScript) database which can then trigger subscriptions. You would need some way of replying to a client with the changes from an event. It doesn't seem like a terribly good fit to me, but I'm interested in hearing more about how you would do it. To your questions:
Because re-frame was built to work in a single-threaded browser environment, and we wanted the Clojure version to match that.
Probably not, I don't think it's a path we're very interested in, and we've already had some concurrency issues on the JVM which we've had to fix.
I'd recommend looking at CQRS and event sourcing patterns. There is CMDR which might give you some ideas. In summary, building server applications isn't re-frame's intended usage (currently), and you might find other solutions which are a better fit. |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for your detailed, precisely worded reply! Now my previous message looks blur, and I like to give it more context. I've started a pet project which displays a list of LineageOS-compatible phones. I wrote it with re-frame. At first the phone list was constructed on each page rendering but page load was slow so UX wasn't great. I chose to fetch and insert the list at compile-time so it would faster the first rendering and still update it client-side to make sure it's up to date. In order to do so and minimize logic duplication, I ported my existing cljs re-frame code to cljc. Now I'm figuring out that some other data sources can't be fetched from a client runtime (because of CORS), only from a Clojure runtime (e.g a REPL) so this pet project is going to be executed more and more from a Clojure REPL. Right now I'm standing here: I like the structured event-based programming style but I'm wondering whether re-frame is still the right tool for this job, hence the title of this issue. In my humble point of view, here are the pros and cons, in no particular order:
If re-frame isn't a good fit for that use case, and if multi-threaded re-frame isn't interesting, would anybody mind suggest some structured event-based programming libraries? Manifold, RxClojure, or quasar-pulsar? I've had a brief look at them and they all seem to miss the "data-oriented, state management" part. |
Beta Was this translation helpful? Give feedback.
-
Further to what @danielcompton has written, I'd recommend recomend two FAQs to you:
We'd like re-frame to be excellent for browser-based SPAs. Beyond that, we have no ambitions. |
Beta Was this translation helpful? Give feedback.
-
@danielcompton, thank you for your reply. |
Beta Was this translation helpful? Give feedback.
-
If you'd like to get a list of phones pre-loaded into the page, you could look at bundling the JSON via a global script tag on the HTML page you serve to the browser, or maybe as a URL encoded JSON string inside a meta tag (I've seen this technique on some of Apple's sites). Will close this for now, but thanks for the good question. |
Beta Was this translation helpful? Give feedback.
-
Follow-up: use the right tool for the right job. |
Beta Was this translation helpful? Give feedback.
-
Hello, thanks again for that great project :-)
I'm using it server-side to take part of cljc isomorophism (run same code in server and client) and for the most part it's quite awesome but after reading some code and documentation, I wonder whether it's an intended usage.
From Clojure code:
Hence, I have a couple of questions:
Beta Was this translation helpful? Give feedback.
All reactions