Fork me on GitHub
#clojurescript
<
2020-04-28
>
rberger01:04:57

How does one inject secrets and other configuration parameters into a clojurescript browser app at build time? Is there a way to have a config.edn file in the local filesystem of the build machine that can be read in or otherwise made available at runtime of the app? I’m using shadow-cljs.

dpsutton01:04:08

what kind of secrets are you intending?

rberger01:04:23

just password like secrets

dpsutton01:04:36

that you don't want shared with random people on the internet?

dpsutton01:04:54

then putting them in a frontend is a non-starter

rberger01:04:12

Well, yeah, I know it wil be in the browser. Its temporary. I just don’t want to check them into git.

rberger01:04:39

Also looking for a what the recommended way is to have config stuff from a file for clojurescript

dpsutton01:04:29

(ns 
  (:require [shadow.resource :as rc]))

(def x (rc/inline "./test.md"))

dpsutton01:04:20

combine this with closure defines you can swap out config. remember anything you put in cljs will be shipped and run on someone else's machine and should not be considered secret

rberger01:04:20

Understood about how not secure it is browser wise. The path is relative to the ns/file its in or the :paths?

dpsutton01:04:41

i think its doing the standard classpath lookup.

rberger01:04:46

Great thanks!

dnolen01:04:06

@grumplet https://www.surveymonkey.com/results/SM-CDBF7CYT7/ if you look at the #1 problem for ClojureScript users it's using libraries

dnolen01:04:19

also shadow-cljs has become immensely popular in a relatively short time because it makes this considerably easier to do

dnolen01:04:44

that alone isn't a reason to do it, but it means that's something is missing because you can't do it that easily with ClojureScript itself

dnolen01:04:19

whether that means ClojureScript projects will be bloated or not is somewhat besides the point

dnolen01:04:33

maybe you're doing something for React Native where the payload is less important etc.

dnolen01:04:19

the other thing is that the only other way to do it easily prior to :bundle is community maintained repo - CLJSJS

dnolen01:04:00

the maintenance burden is non-trivial - Bower for JS eventually went away because it's really not that sustainable to curate everything

dnolen01:04:23

I could go on - but I think you get picture - there are many reasons for and few against

dnolen01:04:12

one last point is that :bundle has nothing to do w/ Webpack

dnolen01:04:14

sure Webpack can consume it, but many many other tools can also consume this kind of output

dnolen01:04:33

bundlers come and go, but I'm pretty confident the Node ecosystem isn't going anywhere

dnolen01:04:49

@grumplet but maybe you aren't complaining now that I read your statement more closely 🙂 yes if you want to use crazy libs it will just work

rberger01:04:57

Is the only way to “hydrate” an edn expression in Clojurescript is to import a self-hosted cljs to do an eval? Or is there something I’m missing?

dnolen01:04:24

you mean data literals?

rberger01:04:45

Like maps and such with just data

dnolen01:04:37

clojure.edn is available

rberger01:04:47

Cool, so I can just require and use it then I presume

theeternalpulse05:04:13

also take a look at https://github.com/juxt/aero which provides reader conditionals that provide different functionality based on environment variables or values passed in while reading the edn.

Spaceman05:04:11

I'm running a clojurescript test using the cljs.test/run-tests command, and it contains the following test:

(deftest individual-field-test []
  (db-refresh)
  (dispatch [:checkout-fields :full-name "Some Name"])

  (testing "individual field"
    (is (= '([:full-name "Some Name"])
           (filter (comp some? val) @checkout-fields)
           ))
    )
  )
When running the test, the dispatch doesn't seem to trigger and the assertion fails. However when I individually evaluate the dispatch and check the value of (filter (comp some? val) @checkout-fields), it is equal to '([:full-name "Some Name"]), which is what it should be. Why is the dispatch not being triggered in cljs.test?

henryw37406:04:34

@pshar10 is that re-frame? if so, you need macro from https://github.com/day8/re-frame-test

Spaceman06:04:41

This works, but for convenience I tried creating a macro like so:

(defmacro deftest-sync [name test]
  `(deftest ~name ~(run-test-sync ~test))
  )
But when I do:
(macroexpand '(deftest-sync some-test (is (= 1 1))))
It simply outputs
(deftest-sync some-test (is (= 1 1)))
Which is unexpected. What am I doing wrong?

grumplet07:04:14

@dnolen - Definitely not complaining - rather the reverse - sorry if it came over like that - I was simply experimenting and reporting on an awkward lib that had previously proved troublesome and was happy to see that it did just work. So, great work 🙂

Spaceman07:04:18

I have this following idiom in my code:

(deftest my-test
   (run-test-sync
       (is (= 1 2)) ;; etc.
   )
And it seems like a good idea to create a macro which would replicate this like so:
(deftest-sync my-test
   (is (= 1 2))
)
And I have tried this:
(defmacro deftest-sync [name test]
  `(deftest ~name ~(run-test-sync ~test))
  )
But on doing in the shadow repl:
(macroexpand '(deftest-sync some-test (is (= 1 1))))
I simply get the result:
(deftest-sync some-test (is (= 1 1)))
But I seem to get the correct result in a clojure repl. Why would this be?

Spaceman14:04:22

I have an myapp.environment namespace like so in an environment.clj file.

(ns myapp.environment
  (:require  [myapp.config :refer [env]]))

(defmacro myapp-url [] (:myapp-url env))
Then I require this in an events.cljs file like
[myapp.environment :refer-macros [myapp-url]]
I get the error
The required namespace "myapp.environment" is not available, it was required by "myapp/events.cljs".
"myapp/environment.clj" was found on the classpath. Should this be a .cljs file?
when using it like so:
(http/get (str (myapp-url) "/somepath"))
How do I fix this?

unbalanced14:04:01

Did you try

(ns myapp.cljs-file
  (:require-macros [myapp.environment :refer [myapp-url]]))
? I think the :refer-macros might only work on a .cljc file , but that's just a WAG

unbalanced14:04:09

myapp.config doesn't happen to be cljs, does it? if so, might want to make that .cljc otherwise environment.clj won't be able to import it

takis_18:04:35

Hello , how i can do this await client.connect(); in clojurescript? i am new in clojurescript and javascript

unbalanced18:04:57

await is alternative syntax for a promise

unbalanced18:04:07

what's the async function you're using it in?

unbalanced18:04:53

usually something like

async function(blah) { await derp = something(); return derp }

takis_18:04:46

i want to write this await client.connect(); to Clojurescript

takis_18:04:01

connect is async function

unbalanced18:04:59

it would be something like

(let [p (js/Promise. (fn [resolve] (-> (.connect client) (.then #(resolve %))))]
  (-> p (.then (fn [] (comment "your code here")))))

takis_18:04:48

thank you alot 🙂 i have to read many things

thheller18:04:00

you don't need to make it that complex

thheller18:04:49

(-> (.connect client)
    (.then (fn [result-of-connect]
             ;; use result
             )))

☝️ 4
👍 4
unbalanced18:04:49

agreed but wanted to keep syntax basic ... how would you do it?

noisesmith18:04:24

to have a simpler syntax you'd need a macro right?

unbalanced18:04:25

I don't know if it can get simpler but you could use externally bound resolve/`reject` functions to change the pattern over to something like core.async

unbalanced18:04:51

I do that on longer chains of .then where I need to pass scope around

unbalanced18:04:13

wouldn't make sense here. I like @thheller’s approach

unbalanced18:04:28

I would not consider external resolve more simple though >.<

dnolen18:04:34

> @takis_ if you really want async / await syntax you can use core.async https://clojurescript.org/guides/promise-interop

dnolen18:04:04

for trivial stuff it's not needed, but if your code is heavily async then this can help

⬆️ 4
unbalanced18:04:43

wow I have never seen that before

unbalanced18:04:56

I have some really annoying service worker code I need to try that on

Alex Miller (Clojure team)18:04:28

the core.async stuff was just added in the last release

unbalanced18:04:31

@alexmiller I didn't know you hung out in #clojurescript ! you're everywhere 😄

Alex Miller (Clojure team)18:04:58

I'm like sauron, except a giant ear

😂 4
24
unbalanced18:04:01

Keeping an eye on the riffraff?

Alex Miller (Clojure team)18:04:30

just here to help

💯 12
lilactown18:04:51

is there a way to annotate JS errors so that I can pull stuff out with ex-data?

dnolen18:04:31

there isn't

unbalanced18:04:29

wonders what other cool cljs stuff came out this release

hindol21:04:56

It will be helpful if the guides when they were added and when they were last modified.

Alex Miller (Clojure team)21:04:20

generally, I'm not sure that it would

Alex Miller (Clojure team)21:04:58

many guides are about things that are not new, and thus their creation date is not relevant

Alex Miller (Clojure team)21:04:22

I update guides on the clojure site literally every week based on issues or whatever, but those changes might just be typos or something

Alex Miller (Clojure team)21:04:18

the approach we more commonly take is to annotate in a guide when it became relevant

hindol21:04:08

I said that in the context of this guide: https://clojurescript.org/guides/promise-interop At a glance it is not clear when it became available. (The promise interop looks really nice!)

hindol21:04:45

The other new guide about target :webpack, it was pretty clear the feature is new.

Alex Miller (Clojure team)21:04:54

I believe the top half of that page is new content but something that has been like that for a while. The bottom half could probably use an annotation about which version of core.async it was added in

Alex Miller (Clojure team)21:04:55

If you'd like, feel free to file an issue on the clojurescript-site or become a contributor and file a pull request

hindol21:04:36

I can send a PR, will do!

unbalanced21:04:45

Do changes/additions to documentation constitute a large or small change?

Alex Miller (Clojure team)21:04:28

depends if they are large or small :)

unbalanced21:04:45

:rolling_on_the_floor_laughing:

Alex Miller (Clojure team)21:04:00

the question is really whether you can sufficiently review your change in the github asciidoc view or not

Alex Miller (Clojure team)21:04:44

I would say most changes are "small" and you don't need to actually build and view the site to satisfy yourself

Alex Miller (Clojure team)21:04:15

David and I can both make those style touch-ups if needed too

unbalanced21:04:10

just wanted to offer how to do https://clojurescript.org/guides/native-executables from a tools-deps perspective since that document didn't work for me

Alex Miller (Clojure team)21:04:40

sometimes it's better to start with an issue describing the problem

Alex Miller (Clojure team)21:04:51

and then get feedback before a pr

unbalanced21:04:00

works for me 🙂

fabrao22:04:27

Hello all, how do I convert this

import { Responsive, WidthProvider } from 'react-grid-layout';

const ResponsiveGridLayout = WidthProvider(Responsive);
to cljs?

fabrao22:04:42

(def ResponsiveGridLayout (WidthProvider Responsive)) -> not working

unbalanced22:04:42

(def width-provider (reagent/adapt-react-class js/window.ReactGridLayout.WidthProvider))
(def responsive (reagent/adapt-react-class js/window.ReactGridLayout.Responsive))

(defn responsive-grid-layout []
  [width-provider responsive])
something like that

lilactown22:04:02

@fabrao it’s not possible to tell you why it’s not working without more information. e.g. what “not working” means

fabrao22:04:57

@lilactown

(ResponsiveGridLayout #js {:layouts {:lg {:x 0
                                             :y 0
                                             :w 100
                                             :h 100
                                             :i "1"}}}
                             (d/div {:key "1"} "Fernando"))
Cannot call a class as a function at Object.WidthProvider

lilactown22:04:01

you can’t call React Components as functions

fabrao22:04:43

yes, I saw it

fabrao22:04:21

This is the way I think it works

($ ResponsiveGridLayout {:layouts (into-array [:lg {:x 0
                                                    :y 0
                                                    :w 100
                                                    :h 100
                                                    :i "1"}])}
          (d/div {:key "1"} "Fernando"))

fabrao22:04:14

thanks 4 ur help

Spaceman22:04:15

Does anyone use respo? I myself use reagent because it seemed like an obvious choice when I first started using cljs. Are there any pros and cons for using respo instead of reagent?

unbalanced22:04:12

@dnolen https://clojurescript.org/guides/promise-interop this is really slick. My 🎩 off to you and your team. Very elegant solution to this callback hell problem