Question about clojurescript and cljc files in general just to understand the Cljc and script world a bit better. Clojurescript has the fantastic ability of sharing code with the backend via cljc files, making things like dataschemas and routers a breeze to develop in clojure. But since that is compiled to javascript I was wondering: can any javascript framework technically use content from cljc files? if you spent the effort to make an adapter for it? Hypothetical: • Develop a clojure proof of concept webapplication with cljs. • Customer accepts the poc but wants to use a different frontend tech. ie. svelte, pure react etc etc. because they have developers for that. ◦ Could I make the cljc code available in this switch, or is that lost as well?
cljc is just a clj file and cljs file combined into one. so you write one file and get two out
in turn you could create a CLJS build that includes those files and exposes some kind of API that JS can use
Thank you Thomas, I understand api is maybe not as seamless as I hoped but it is still useful, for example in communication and datavalidation side of things. Though maintaining that and a separate js framework sounds like a risky business.
well, JS frameworks in general have a very different view of the world than CLJS. the datastructures alone require conversion. you can't just dump a CLJS map into a JS app and expect that understand how to work with it. so yeah there is always friction. besides that any (defn some-function [...] ...) you can make directly accessible to JS easily
True enough, It is that datastructure conversion that worries me, though that is probably already handled in the numerous react wrappers that cljs has. could maybe pull it out from one of those. Thanks again.
sure there are clj->js and js->clj to help, but conversion is lossy, so generally still requires manual work. plus its not free and doesn't map 1:1 often
Hi, I have a question about keeping server and clients data in sync, even when clients can edit some data when offline. Client/browser development is not my strongest suit, so I’m looking for some advice on the (dis)advatanges of different approaches and/or library recommendations. I’m leaning towards datalevin on the server and datascript on the client. Are there ways to persist datascript data on the client so that a PWA can access some data when offline? And how to handle syncing the data when clients come back online?
You can setup a watch to serialise your datascript dB to browser localStorage after every transaction and reload it on page refresh. Alternatively you can extract a transaction and persist a transaction log either to a file on localStorage or to indexed-db. I've a very ugly attempt at the latter here -- https://github.com/cormacc/cljserial -- appears to work, though only toy/POC. I've been working on a version of that with separate OPFS file storage / sync to supabase in a work project intermittently recently. Hope to pull some of the non-business-domain stuff out and feed it back into that repo at some point. That repo is using replicant actions to trigger persistence rather than a watch on an atom, but the same principle apples (initially I was using an atom, and intending to pull the datascript db out of my replicant/app state and treat it more like a backend db in the next bit of rework). Edit Big disclaimer - I'm primarily an embedded guy, so anything there is likely not representative of best practice :)
Yesterday I pushed ClojureScript 1.12.42 to Maven Central - if would be helpful if people could try it out. Things to note - it requires Java 21 due to changes to Closure Compiler. It removes 6 years of small breaking changes from Google Closure Library, some really old CLJS libraries from the very first days now work again.
Just tried with shadow-cljs 3.0.6 that depends on CLJS 1.12.42 on a decent code base with lots of interop and CommonJS modules but very little GCL usage. Everything seems to be working fine.
set the channel topic: ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.12.42
The "Clojure’s Fork of Google Closure Library" section is great.
thanks!
yes, so good!
The date on this post is "16 May 2024", I guess this should be 2025?
yeap, sorry fixed, thanks!
Thanks for this sensible approach, I am happy to hear that you carry the torch of stability further :)