Fork me on GitHub
#clojurescript
<
2022-07-20
>
witek09:07:16

Hello. How to create a valid EDN string from arbitrary objects? I create EDN strings using (with-out-str (pprint something)) . This works fine as long something contains standard clojure data (maps, vectors, lists, strings, numbers,...). But when there is a nested JavaScript-Object (for example a Promise), then I get invalid EDN. What is the idiomatic way to ensure valid EDN, even if something is (or contains) JavaScript objects? It would be ok, when the JavaScript-Object is written as a string, containing the toString() value. Do I have to walk something manually and convert the values? Or is there something to help me with the problem?

thheller09:07:35

regular printing has extension mechanisms (eg. IPrintWithWriter). pprint does not I think.

thheller09:07:22

I'd recommend validating or not putting non EDN things in there in the first place if your intent is to store and read later

thheller09:07:19

the default is to print "unsupported" things tagged with #object, is that not enough?

thheller09:07:51

at least for pr-str. not actually sure what pprint does by default.

thheller09:07:22

there are also other libs (eg. fipp) that support more customization options than regular pprint

Takis_20:07:43

clojurescript web applications use clojure on server (ring) + clojurescript on client(reagent for example) ?

Takis_20:07:58

clojurescript and nodejs is not used in general? we have libraries that do something like MERN(mongodb, express, react, nodejs) for clojurescript? i mean back-end clojurescript

augustl20:07:49

I’m not aware of anyone using clojurescript on the back-end at least

Takis_21:07:26

thank you augustl : )

Takis_22:07:49

thank you rolt

Takis_20:07:10

i dont say its good idea, i am just curious what people mainly use, and what libraries we mostly have

ns20:07:00

So I've rebuilt most of our admin system in ClojureScript and so far so good, actually great. Now I'm at the point where I need to integrate some old React components which are written in just plain js + React. The minified .js build containing those is included into the page but I'm not sure how to "interop" with them in Cljs so they appear on the page. If someone could point me in the right direction I would be really grateful.

p-himik20:07:35

If they're minified, they probably already include their own version of React. Including them in your CLJS app will be a PITA.

ns20:07:29

They are and they do contain their own version of React. I was hoping not to have to rewrite them in CLJS at this point because there is quite a bit of code (maybe sometimes later).

ns20:07:45

Forgot to mention, I do have access to that old code, so if I need to modify something and rebuild again to make it easier to interop with CLJS I can do so.

p-himik20:07:46

You can just use them as JS sources, without minifying them before using in CLJS. Similar to how you work with NPM modules.

p-himik20:07:31

Unless they require some preprocessing to be built - like some new JS features or using TS. In that case, something like webpack will be required, which can be used with CLJS.

ns20:07:55

As far as I know it's just vanilla js + React built using Gulp

isak20:07:40

I don't think it is too bad to work around that file providing it's own react. You'd just need something like this in your shadow-cljs.edn file:

:exclusions [cljsjs/react
              cljsjs/react-dom
              cljsjs/react-dom-server
              cljsjs/create-react-class]
and in compiler options:
:js-options
   {:resolve {"react" {:target :global
                       :global "React"}
              "react-dom" {:target :global
                           :global "ReactDOM"}
              "create-react-class" {:target :global
                                    :global "createReactClass"}}}

ns20:07:11

Actually, there might be some new js features, I see Babel and browserify in there, but no TS.

ns20:07:31

@U08JKUHA9 Thanks, I'll check that out

1