Fork me on GitHub
#clojurescript
<
2020-07-03
>
Rob Aguilera01:07:09

What's the best way to load a file in Clojurescript? I'm trying to read an .env file to retrieve my api keys.

noisesmith01:07:34

there might be a lib but my first instinct would be to use platform interop - it's not hard to use node apis (or use the OS js apis on the slim chance you are using that instead of node...)

Rob Aguilera01:07:51

I'm actually not using Node. It's just a toy app I'm building to play around with cljs. The only library I'm using is Reagent.

Rob Aguilera01:07:28

I tried the environ lib but couldn't make that work. Tried a variety of things and could never get CLJS to recognize the library (I'm also using leiningen for what what that's worth)

noisesmith01:07:47

if you aren't using node, which js vm is running your code?

noisesmith01:07:27

if it's running in a browser, you can't read their files unless the user explicitly goes and provides it to the app, for security reasons

noisesmith01:07:45

if you want to do this from the server, this is a clojure question and not a clojurescript one

Rob Aguilera01:07:28

Good question, I'm not actually sure. I'm using lein with the reagent template. I don't think it's running node under the hood. I'm actually trying to read my own .env file in my project directory for the API key I'm going to use to hit a third party api.

noisesmith01:07:25

OK then this is a clojure question, you can use slurp in your clojure code (the part that runs on the back end)

Rob Aguilera01:07:50

Yeah I know you can use the io namespace in Clojure. Was hoping I could do something similar in CLJS. Bummer, thanks anyways!

noisesmith01:07:30

cljs can't read data on your server, because it's running on the client's machine

noisesmith01:07:41

if it could read files on your server, that would be a big problem

dpsutton01:07:59

also, if its a secret, it can't go to a random person's browser. if it does, it's not secret since you've shared it

💯 3
noisesmith01:07:26

funny how secrets work that way isn't it

dpsutton01:07:57

its easy to slip into code = compiled and not inspectable i guess

noisesmith01:07:53

when I was first learning ot program I often thought things were safe because I would never figure them out

noisesmith01:07:06

I underestimated how much more I'd know a few decades later

Rob Aguilera02:07:23

Gosh that's such a good point. Was too busy figuring out clojure I forgot the basics. Thanks for the help guys.

Harshana05:07:16

Hi. I've been using material-ui in my cljs. I have used Button, TextField components. But I cant use material-ui/MenuItem component. I want to use it inside material-ui/Select. My code is: (defn MenuItem [] [:> material-ui/MenuItem {:value "a"}]) ; :children "A"}]])) (defn Select [] [:> material-ui/Select {:defaultValue "Change Review event" :multiple true :values ["a" "b"]} (MenuItem)]) I get this error:

The above error occurred in the <ForwardRef> component:
    in ForwardRef (created by ForwardRef)
    in div (created by ForwardRef)
    in ForwardRef (created by WithStyles(ForwardRef))
    in WithStyles(ForwardRef) (created by ForwardRef)
    in ForwardRef (created by WithStyles(ForwardRef))
    in WithStyles(ForwardRef) (created by ForwardRef(Select))
    in ForwardRef(Select) (created by WithStyles(ForwardRef(Select)))
    in WithStyles(ForwardRef(Select)) (created by reviews_next.pages.feedback_event.feedback_event)
    in div (created by reviews_next.pages.feedback_event.feedback_event)
    in div (created by reviews_next.pages.feedback_event.feedback_event)
    in reviews_next.pages.feedback_event.feedback_event (created by )
    in div (created by )
    in 

p-himik09:07:14

It talks about "The above error". And what is the above error?

Harshana09:07:47

Thanks @U2FRKM4TW, I have resolved the error. I had to change the :values to :value in Select component.

henryw37411:07:31

Hi all, I want to consume some es6 code from clojurescript, which doesn't come from a library - I mean the es6 code is just a local file. It is possible to require a .js file from cljs when it is written with goog.provide I know, but this code is written as an es6 module. The Google Closure compiler is fine reading this es6 code when I invoke it directly (not via cljs compiler) and I have a demo of that here https://github.com/henryw374/cljs-using-non-foreign-es6, but I can't work out how to write the clojurescript require so that it will work to read the es6 file. I want this to work everywhere, including shadow so js modules https://clojurescript.org/reference/javascript-module-support is not going to be an option. I'm starting to dig into the cljs compiler for answers but if anyone can give me some pointers it'd be appreciated 😉

henryw37417:07:58

I've asked about es6 import from google closure module on Closure forum so maybe that will provide the next clue

thheller17:07:25

regular CLJS does not

henryw37417:07:33

Thanks! Shame regular cljs doesn't support this

dominicm12:07:30

Tried this a while ago and had problems getting both to work.

👍 3
piotrts13:07:26

Hey, not sure if I am posting this on the right channel (its my first public message ever on this Slack), but in one of the projects I am migrating from cljs-time 0.4.0 to 0.5.2 and it seems that behaviour of cljs-time.coerce/from-string has changed over the years, i.e.:

(cljs-time.coerce/from-string "2015-06")
=> #object[Object 20150106T000000]
Has anyone came across this? Not sure if this behaviour is expected? I'd expect 2015-06-01, not 2015-01-06. I can probably change the order of formatters used to parse dates, but I'd prefer not to.

p-himik13:07:26

But "2015-06" is ambiguous either way. If you yourself know that it's definitely "yyyy-MM", then it's better to avoid from-string altogether and just call cljs-time.format/parse.

piotrts13:07:51

hmmm, cljs-time.format/formatters contains an entry for yyyy-MM , but unfortunately for me another formatter is chosen by parse-string. So I will just assume the input is in yyyy-MM format and parse it as such, what seems doable. Thanks @U2FRKM4TW

noisesmith16:07:09

couldn't you effect this by specifying a locale? it's a regional thing which order month/day are in right?

noisesmith16:07:25

probably better to specify a precise ISO rather than locale actually

mfikes16:07:45

It feels like you could treat this as a valid RFC-3339 representation, just like #inst "2015-06" works

mfikes16:07:45

I guess it depends on what semantics you want to tie to that string...

mfikes17:07:47

Oh, wow, sorry about that. I didn't realize the date format for #inst isn't really specified as ISO 8601, which allows for partial representations. (RFC-3339 doesn't allow for what I suggested above.) I guess the actual format of #inst is a bit of an open question.

henryw37417:07:07

in java.time that would be the default format of a YearMonth, which is as ISO thing https://www.w3.org/TR/NOTE-datetime . using yearmonth entity you can convert into date etc. unashamed plug coming up: https://github.com/henryw374/cljc.java-time