Fork me on GitHub
#clojurescript
<
2020-01-03
>
Luis10:01:27

Hi at all! I have a little question about CLJS with Reagent. To learn CLJS I'm trying to create a simple website with two template, site and admin. For the admin version I'm creating reagent component from AdminLTE template. Now I want to understand if is possibile to have a single css file for each component that I've created. For example, I've create two component admin-page and site-page. I want to load two different css for each page-component.

Luis10:01:30

How do it?

p-himik10:01:03

I would split admin and site into different HTML files. I don't see any point in keeping them within the same SPA. This way, you'll be able to separate everything - CSS, JS, any other resources.

Luis10:01:55

I remember when I develop with Vue.js... I have only one app.js, like a root of my application. The first two child are site and admin. Like as you said, seems to have two app.js, right?

p-himik10:01:52

Yeah. If you use shadow-cljs, here's a good article about code splitting: https://code.thheller.com/blog/shadow-cljs/2019/03/03/code-splitting-clojurescript.html

šŸ‘ 4
Luis10:01:38

Really interesting! Did you now a boot-leiningen template with a valid configuration of reagent, shadow-cljs to start to develop a production-ready app?

p-himik10:01:22

Not really, I don't use templates. thheller, the author of shadow-cljs, just uses npx create-cljs-project as well.

Luis10:01:54

Thanks @p-himik! I'll check immediatelly!

šŸ‘ 4
dazld18:01:02

Instructions are in the repo

dazld18:01:17

Works for me! :)

dazld10:01:22

is it possible to monkey patch a library function in cljs? there isnā€™t an alter-var-root, right?

dazld10:01:36

(doing some debugging..)

p-himik10:01:51

Depends on what you want to monkey-patch, I guess. And whether the advanced optimizations have changed it.

dazld10:01:40

for example, reagent.core/cursor

dazld10:01:01

and yep, not doing advanced compilation, just some local work

p-himik10:01:12

The easiest way to do this is to copy the whole file with the source code of the function into your src where you can change it. Since your src should have a higher priority in the classpath, this file will be used by the compiler. Just make sure that you put it in the correct ns.

dazld10:01:36

thatā€™s a good idea

dazld10:01:40

thank you!

šŸ‘ 4
dazld10:01:07

so, in this case, iā€™d recreate the reagent folder structure in my project, and copy core in there?

p-himik10:01:58

TBH I've never tried it with CLJS, just with CLJ. But I don't know any reason why it shouldn't work.

dazld10:01:44

iā€™ll give it a go

dazld11:01:41

works! thank you again šŸ™‚

p-himik11:01:33

No problem.

qqq15:01:27

Does anyone have a setup that combines CLJS with Rust/Wasm32? Rust/wasm32 is used for the "high performance" part of the application and CLJS is used as the scripting/glue language.

dnolen18:01:30

@dazld there's an easier way - you can just use set!

ā¤ļø 8
oliver18:01:02

Hi there, sorry for bothering your guys, but I'm in the process of rolling out my first clojurescript-based site and all of a sudden I'm having trouble with my http requests. The following works fine in the browser and gives me the desired JSON:

. 
The following in my CLJS-Node-App returns an error response:
(go  (print (<! (http/get ""))))
The data is public anyway so feel free to try for yourself. The problem probably isn't clojurescript-related and I know I have to deep deeper into HTTP, but since I'm somewhat under pressure with this right now, I hope you'll forgive my asking here! Many thanks!

dpsutton18:01:55

i don't see an error message here. likely a CORS issue? often there will be an error message in the browsers console. can you see if there's anything there?

oliver18:01:04

Thanks for takeing the time. You mean the JS console ? No error there other tahn the favicon missingā€¦

oliver18:01:35

The weird thing is that in the browser I get JSON but not from my appā€¦ as to CORS: The CMS I'm accessing here had already been on the same serverā€¦ only now I pointing an new domain to itā€¦

oliver18:01:40

BTW, did you mean seeing no error evaluating the go block or entering the URL into your own browser?

oliver19:01:31

many thanks, that sounds helpfulā€¦ I'll figuring ot what that means

dpsutton19:01:10

(async/go
  (print (async/<!
           (http/get
             ""
             {:with-credentials? false}))))

oliver19:01:50

does that work for you? On my setup it doesn'tā€¦

oliver19:01:49

Excuse my ignorance, but what console did you pull this error message from?

p-himik19:01:18

Browser developer tools console.

p-himik19:01:23

But since you do that using Node, CORS shouldn't affect it AFAIK. What error do you see when requesting the URL in Node?

dpsutton19:01:47

i took app to mean the browser app. and the first sentence "the weird thing in the browser" to mean when navigatign directly to the url

dpsutton19:01:55

if that's not the case then i apologize

dpsutton19:01:33

(go (println
      (:body (<! (http/get ""
                           {:with-credentials? false})))))
->
{:data [{:status published, :code de, :kurzname de, :langname Deutsch} {:status published, :code en, :kurzname en, :langname English} {:status published, :code uk, :kurzname уŠŗр, :langname уŠŗрŠ°Ń—Š½ŃŃŒŠŗŠ°}], :public true}

oliver19:01:00

I'm getting back a 404 response and then some HTMLā€¦ https://pastebin.com/tdWWEEwq

oliver19:01:26

Sorryā€¦ maybe I didn't make clear that I'm running on node

oliver19:01:30

Ok, I seeā€¦ that means it works for you fom CLJS running as a client app, rightā€¦?

dpsutton19:01:19

what are you using for a http client?

p-himik19:01:48

Since the URL seems to be the same, it looks like it's the problem at the server that handles requests to . Assuming you ran the browser code and the Node code from the same machine, it seems that the server does something strange based on User-Agent.

oliver19:01:36

I'm deploying the app to the server right nowā€¦ maybe it will work there, which will give me some breathing room

p-himik19:01:43

Try replacing the User-Agent and see how it works. If it doesn't, I'd use something like Wireshark to see what actually gets sent.

oliver19:01:07

Thanksā€¦ I'll try thatā€¦

oliver19:01:21

And thanks to both of you for the quick replies

jjttjj21:01:06

I think I'm missing something small. I have this multimethod in cljs:

(defmulti handle-prop! (fn [el k v] k) :default ::default)

(defmethod handle-prop! :width [el k v]
  (gsty/setWidth el v))
And this works but then when i require that namespace and try to defmethod in the other namespace:
(d/defmethod handle-prop! :x [el k v]
  el)
I get the following error
394 | (d/defmethod handle-prop! :x [el k v]
 395 |   el)
---------^----------------------------------------------------------------------
 Use of undeclared Var jt8.ui.components/el
Anyone see anything wrong here?

mfikes21:01:49

What's the d alias used with defmethod?

mfikes21:01:05

(Assuming you meant to write defmethod, not d/defmethod.)

jjttjj07:01:43

D'oh this was it, I meant to put d/handle-prop! And not d/defmethod

Alex Miller (Clojure team)21:01:54

did you refer handle-prop! in the second ns?

oliver21:01:55

@p-himik, @dpsutton thanks to both of you again. I've come to realize that the problem was probably due to some quirk with the recent transfer of the domainā€¦ kinda solved itself an hour ago and my first CLJS-Website (actually my first one altogether) is now live at: http://violina-petrychenko.de/en/

šŸ‘ 4
oliver22:01:59

So much, just for closure (no pun intended)