Fork me on GitHub
#clojurescript
<
2020-05-03
>
thheller06:05:53

@pshar10 the origin is client.cljs line 240?

Spaceman12:05:59

That isn't helpful. client.cljs isn't one of my src files. That might be one from the template that I'm using

thheller12:05:47

its in the browser console so you should be able to click it and it'll take you to the source?

rberger06:05:03

Is there a way to get a cljs map or vector of a Javascript Object’s properties? I tried

(.entries js/Ojbect myObject)
But I always get an empty vector

phronmophobic07:05:39

it’s included by default with cljs

phronmophobic07:05:02

you may have to require something like [goog.object :as gobject]

phronmophobic07:05:33

and use (gobject/getKeys obj)

dominicm07:05:29

There's js-keys in core

Jakob Durstberger10:05:53

Morning, I tried adding a JS library to the re-frame template. I used npm install --save aws-amplify and then added ["aws-amplify" :as aws]. But the site doesn’t show anything and the console only shows the error:

reload-failed Error: Failed to load website/core.cljs: 
at Object.shadow$cljs$devtools$client$browser$do_js_load [as do_js_load]
...
Does anyone know what I am doing wrong? Edit: Hmm I can import math-random so I think it is an issue with aws-amplify itself 😞

thheller10:05:55

that is the rest of that error?

thheller10:05:03

or the one before/after it?

thheller10:05:32

it failed to load website/core.cljs but that might be because an error in another file it depends on happened first

rberger20:05:25

I was using it like:

["@aws-amplify/core"
    :refer [Hub]
    :default Amplify]
Depends a bit on what you want from the very large library. Also they recently dramatically changed the library in 3.x.x with the ability to load only the portion you want/need. That have some javascript examples in https://github.com/aws-amplify/amplify-js and I find this a good guide to translating the import statements to Clojure require: https://code.thheller.com/blog/shadow-cljs/2017/11/10/js-dependencies-in-practice.html

👍 4
rberger20:05:28

@jakob.durstberger I wrote up a tutorial on using Amplify Auth and re-frame https://dev.to/rberger/aws-amplify-and-clojurescript-re-frame-part-1-3d3f It was pre amplify 3.x but I think its generally applicable still

👍 4
Jakob Durstberger04:05:19

I want to use the authentication part, I’ll have a look at your post. Thank you

rberger04:05:46

That’s primarily what I covered

Jakob Durstberger06:05:47

I went through your blog post and my issue is that the auth UI is just not coming up. I use terraform to deploy my user pool so I think I might have misconfigured something. Out of interest, did you also write this one?https://www.omnyway.com/add-serverless-aws-amplify-authentication-to-a-clojurescript-re-frame-app/ They seem to be very very similar 😄

Oliver George10:05:12

Hi Jakob. Are you trying out the new webpack feature? https://clojurescript.org/guides/webpack

Jakob Durstberger10:05:31

Uhm, not that I am aware of. I think the re-frame template doesn’t use webpack

Oliver George10:05:38

Using node deps involves a bit of work. The most recent release opened up a new way but it's always been possible.

Oliver George10:05:17

Assuming it's a recent enough version

Oliver George10:05:55

No personal experience. The cljsjs project is a manual effort to package up JS deps so they are easy for clojurescript projects to use.

Jakob Durstberger10:05:09

Adding math-random and using it was super easy, so I think it actually is an issue with aws-amplify

Jakob Durstberger10:05:07

I had a look at aws-sdk-js and it seems like that is for talking to AWS services. I am new to the whole amplify thing but I think it is something slightly different.

Oliver George10:05:30

yeah, sorry. Bad google.

Oliver George10:05:11

I wonder if you had the right dep. If it's a re-frame app perhaps you need @aws-amplify/ui-react

Oliver George10:05:01

For what it's worth those libs didn't immediately work for me via the webpack tutorial.

Oliver George10:05:04

No I lied. They seem fine.

Oliver George10:05:14

I'll post a little repro in case it's helpful.

Oliver George10:05:07

My test was to print to console confirming I could see stuff in both libs

Jakob Durstberger10:05:18

Thank you, I’ll have a look at your repo

Jakob Durstberger11:05:00

I reverted all my changes and started from fresh and interestingly enough if I just add aws-amplify I can’t even compile the project because http2 is missing. When I add that dependency I am back to it compiling but not running, just frustrating 😕

thheller11:05:26

@jakob.durstberger if you get an error about http2 missing then you need to bump your shadow-cljs version. that was fixed not too long ago.

Jakob Durstberger11:05:27

Interesting. I bumped the shadow-cljs version from 2.8.83 to 2.8.109. Now I just get

Syntax error (NoSuchFieldError) compiling at (shadow/cljs/devtools/api.clj:1:1).
ES3

Full report at:
/var/folders/02/3d17l0kx4gd8ywt0zgstlqmw08dm4y/T/clojure-13818416195260001911.edn
Error encountered performing task 'do' with profile(s): 'dev'
Suppressed exit

thheller11:05:53

thats a version conflict ...

thheller11:05:20

make sure the shadow-cljs version matches the clojurescript version it expects ... or just use shadow-cljs.edn to manage deps which takes care of things like these ...

thheller11:05:35

with .109 you should be using cljs 1.10.741

thheller11:05:06

you likely have an old one specified in deps.edn or project.clj (whichever you are using)

Jakob Durstberger11:05:03

yeah, there is an older one in my project.clj. I’ll try updating that too

Jakob Durstberger11:05:18

Ok, I updated shadow-cljs and clojurescript. Now it isn’t complaining about http2 but process

Jakob Durstberger11:05:39

Is that expected?

thheller11:05:44

do you have the shadow-cljs npm package installed in the project? so not just the global install?

Jakob Durstberger11:05:46

hmm yeah. I guess I should also update that one.

thheller11:05:55

you used a template right? which one? seems like I need to take a look at that one.

thheller11:05:29

version of that package isn't the issue here. it also bring in the node-libs-browser package which provides the process and other node built-in polyfills

Jakob Durstberger11:05:32

I ran lein new re-frame website +10x +cider +test +garden

thheller11:05:17

thanks, I'll take a look at that one

thheller11:05:14

picard-facepalm guess I'll need to have a word with the author

Jakob Durstberger11:05:20

Seems like it works now. I was able to import amplify and call (.configure Amplify config) Thank you so much @olivergeorge and @thheller for your help.

Oliver George11:05:36

👍 Thomas has your back. I didn’t realize you were using ShadowCLJS

Jakob Durstberger11:05:33

The whole clojurescript ecosystem + re-frame is new to me so I am not certain yet what is and isn’t important when I ask for help

Spaceman12:05:59

How do I create a non-blocking suggestions input bar? So basically I'm taking in input and then making a get request using that input. But this blocks the input itself, which I don't want. So when typing the input hangs until the get request is made. Here's the code:

(reg-event-db
 :update-address-zip-suggestions
 (fn [db [_ suggestions]]
   (prn "updating suggestions to" suggestions)
   (assoc db :address-zip-suggestions suggestions)
   ))

(defn update-address-zip-suggestions [suggestions] (dispatch [:update-address-zip-suggestions suggestions]))

(reg-event-db
 :user-address-suggestions
 (fn [db [_ zip]]

   ;; this seems to be blocking
   (go
     (let [response (<! (http/get (str (my-url) "/address-zip-suggestions")  {:query-params {:text (:user-address-zip db) :token "randomtoken"}}))
           suggestions (:body response)]

       (if (not (empty? suggestions))
         (update-address-zip-suggestions suggestions)
           
         )
       )
     )
   db
   ))
(defn user-address-suggestions [address-zip] (dispatch [:user-address-suggestions address-zip]))
(reg-event-db
 :user-address-zip
 (fn [db [_ zip]]
   (user-address-suggestions zip)
   (assoc db :user-address-zip zip :address-zip-suggestions-shown? true)
   ))

(defn user-address-zip [user-address-zip] (dispatch [:user-address-zip user-address-zip]))


(defn address-zip-field []
  [:input (tw style/text-input {:placeholder "Enter Address or Zip Code"
                                :on-change
                                #(user-address-zip (-> % .-target .-value))
                                  })])
How do I make it not block? So that the input doesn't hang or wait for the get request to finish?

nick16:05:05

What should I use for a new re-frame+leiningen+shadowjs project for adding npm dependencies? https://clojurescript.org/guides/webpack OR lein-cljsbuild OR lein-npm OR lein-shadow? This is rather confusing. Trying to follow various blog posts and it still fails to find a dependency: > The required JS dependency "@material-ui/core/Button" is not available, it was required by "foo/views.cljs".

dpsutton16:05:40

i wouldn't use a template. i would just start a simple shadow-cljs project

dpsutton16:05:41

the lein-shadow plugin lets you put the shadow-cljs stuff inside your project.clj file but all it does is just copy it right back out into a shadow-cljs.edn file. No real benefit from my eyes.

thheller16:05:45

@nfedyashev with shadow-cljs it is just npm install the-package and use it. nothing else. unfortunately some tempaltes try to move that functionality into project.clj via lein plugins which I do not recommend

jjttjj17:05:42

I've been trying to get a bootstrapped/self-hosted cljs repl in the browser with no server. I've found a few projects related to this: https://github.com/cgrand/cljs-js-repl https://github.com/arichiardi/replumb They both haven't seen commits in awhile, I'm curious if anyone knows if these type of approaches are still the way to go or if there have been any changes to cljs in the past few years that would make this easier or these approaches obsolete? On a more philosophical level, what is a repl exactly? Obviously read/eval/print. But it seems in clojure/script there's also the state related to namespaces which is separate from those steps. Also the ideas of an input/output stream. I'm having trouble building up intuition around this. I've started trying to read the related cljs source. Anyone happen to have any good reading material related to this?

Umar Daraz17:05:10

Hello clojurian, I m using shadow cljs in my journey to learn clojure/clojurescript. in development mode my server is running on port 3000 and shadow cljs server is at 8080. I m trying to proxy my api request to my server, here is what how i m trying to config proxy url. but it giving 404 error. Please help me with what im doing wrong?

:dev-http {8080 {
          :root "target/"
           :proxy-url ""}}

thheller19:05:21

why are you using a proxy in the first place? why not just have your server on :3000 serve the output files? its just static files you need to serve, nothing else.

Umar Daraz09:05:01

thanks you so much of shadow cljs @thheller , I m pleasantly surprise to get the answer from the greater of shadow cljs it self. Honoured Just one confusion about that how the hot reloading will work, if I serve the output of shadow cljs from my api server? thanks again for the answer.

thheller09:05:02

that is running over the default shadow-cljs server regardless. it connects over a websocket (normally running on :9630)

thheller09:05:12

the :dev-http is really just a static file server nothing else

thheller09:05:30

so you can just make your regular server serve the file. it does not affect hot-reload in any way

Umar Daraz16:05:23

Thanks @thheller I got it, will try it out.

dnolen19:05:50

@umardaraz4747 there's a dedicated #shadow-cljs channel for specific questions around shadow config, this is a more general channel

Umar Daraz04:05:42

Thanks @U050B88UR I m honoured to hear from you!

dnolen19:05:21

@jjttjj bootstrapped / self-host is a pretty advanced topic

dnolen19:05:52

if you have a lot of patience you could look at the ClojureScript source itself, those other projects depend on the fundamental support in ClojureScript so they're still relevant

dnolen19:05:12

the state stuff is compiler state, input/output stream are less relevant, bootstrapped ClojureScript works on strings

jjttjj19:05:11

understood about it being advanced. I've had it "working" for a bit for my eval needs, just trying to take my understanding to the next level and was wondering if I was missing anything in my google searches 🙂

jjttjj19:05:54

Will continue to keep reading the source though

sergey.shvets23:05:19

Hi! Is there an apply analogue for javascript functions? I found js-invoke but that can't be called with a vector of args. Thanks!

lilactown23:05:51

apply should work with JS functions

Umar Daraz09:05:01

thanks you so much of shadow cljs @thheller , I m pleasantly surprise to get the answer from the greater of shadow cljs it self. Honoured Just one confusion about that how the hot reloading will work, if I serve the output of shadow cljs from my api server? thanks again for the answer.