This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-19
Channels
- # announcements (3)
- # asami (3)
- # babashka (39)
- # beginners (65)
- # calva (13)
- # cider (4)
- # clj-kondo (69)
- # cljdoc (19)
- # cljs-dev (2)
- # clojure (90)
- # clojure-dev (10)
- # clojure-europe (61)
- # clojure-france (15)
- # clojure-nl (8)
- # clojure-uk (2)
- # clojurescript (28)
- # conjure (2)
- # core-logic (4)
- # cursive (8)
- # datalevin (5)
- # datascript (7)
- # datomic (14)
- # depstar (4)
- # events (1)
- # graphql (7)
- # holy-lambda (5)
- # jobs (5)
- # kaocha (1)
- # malli (14)
- # membrane-term (13)
- # missionary (13)
- # nextjournal (6)
- # off-topic (1)
- # polylith (15)
- # portal (10)
- # re-frame (35)
- # reitit (1)
- # remote-jobs (3)
- # schema (3)
- # sci (121)
- # spacemacs (6)
- # tools-build (8)
- # tools-deps (74)
- # xtdb (7)
What’s the best way to do server-side-rendering as in next.js for cljs?
honestly, never tried doing ssr of reagent or similar components in cljs - but can imagine it’s very similar
in practice though, the cljs apps aren’t just hiccup, but have behaviour.. it’s a bit of a mess. with discipline or the correct library, there’s no reason why hiccup producing functions can’t be used both server side, and on the client
to be specific - things like hooks that load data would need abstracting so they are platform agnostic
We’ve had some success using cljs as the “guts” of our apps with vanilla React at the outer layer to handle the SSR coordination parts. It works fairly well, since it is all JS at runtime
You can maybe take a look at the SSR branch of this full stack project that I open sourced. It uses Inertia.js for wire the front and the back end: https://github.com/prestancedesign/pingcrm-clojure/tree/ssr
I recently wrote a little about some different techniques for pre-rendering reagent+re-frame apps: http://www.arthurbrrs.me/prerendering-react-clojurescript-land.html
Anyone know of a relatively simple and tidy Om Next example repository? Got some legacy code I need to wrap my head around, and think it might help to first wrap my head around something less complex
@ps the percentage of usage in the survey hasn't really changed ~3% over time, so I would say less declining rather it's just not that interesting of an option for mainstream JS dev - many people are aware that it exists - w/o having ever used it far as I can tell
I have this macro. I want to make the cljs.analyzer.api optional for those who only use this library on the clojure JVM:
#?(:clj
(defmacro copy-ns [ns-sym sci-ns]
(macros/? :clj `(copy-ns-fn (ns-publics ~ns-sym) ~sci-ns )
:cljs (let [publics-map (cljs.analyzer.api/ns-publics ns-sym)
publics-map (zipmap (map (fn [k]
(list 'quote k))
(keys publics-map))
(map (fn [m]
{:name (list 'quote (:name m))
:val (:name m)
:meta (select-keys (:meta m) [:arglists
:no-doc
:doc])})
(vals publics-map)))]
;; (prn publics-map)
`(copy-ns-fn ~publics-map ~sci-ns)))))
Should I do this using the usual means of trying to resolve the cljs.analyzer.api + a try catch or so?Isn't it already optional with this code?
The :cljs
branch won't be included in the CLJ code at all, so the NS won't be needed.
The :cljs
"branch" then needs to explicitly require
the cljs.analyzer.api
namespace. And yeah, I would go with try-catch. At least then you can print out a reasonable error and not make it implicit, where it would fail for some but work for others that happened to require
that ns some place else.
I can't think of any reason why you wouldn't want to do that, or of any other reasonable way to achieve the same outcome.
I already wrote a lib for this. https://github.com/borkdude/dynaload
Hmm, right.
FWIW, from a user's perspective I would rather have an exception tell me what I forgot to add than to see Could not locate cljs/analyzer/api__init.class, cljs/analyzer/api.clj or cljs/analyzer/api.cljc on classpath.
.
An extra +1 to the niceness if the error can also tell what lib exactly needs to be added to have that namespace available. :)
Kind of. You can provide a default, so you an provide a function that upon usage throws a nice error message at you
I think I may have run into a bug here with :reload
?
[email protected] /tmp/foo $ clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.879"}}}' -M -m cljs.main -re node
ClojureScript 1.10.879
cljs.user=> (require '[foo.foo] :reload)
nil
# newest CLJS
[email protected] /tmp/foo $ clj -M -m cljs.main -re node
ClojureScript 1.10.893
cljs.user=> (require '[foo.foo] :reload)
Execution error (TypeError) at (<cljs repl>:1).
Cannot read property 'remove' of undefined