Fork me on GitHub
#clojurescript
<
2018-01-23
>
justinlee02:01:17

does anyone use spyscope with clojurescript? even though I’ve added it to dependencies, the compiler can’t find it when I require spyscope.core. generally what debugging libraries do people like to use? i’m just using lots of prints

mikerod03:01:57

I’ve used scope-capture some and have liked it. I used it a pretty basic level, but it was helpful to me for capturing locals environments at runtime

mikerod03:01:38

In the CLJS via figwheel + cider + piggieback repl I am getting an “analysis error” “at line 1" with really no information when trying to expand a macro:

----  Could not Analyze  <cljs form>   line:1  column:1  ----
this same thing used to work. Not sure what changed. That part is somewhat irrelevant to my question though. My question is, what can be done to troubleshoot something like this?

mikerod03:01:54

The cljs repl analysis happening here seems opaque and it doesn’t give stacktraces or anything

conan17:01:13

I'm having trouble making a re-frame app run my init function when I load the page. How can I tell it what it should run first?

conan17:01:40

I have a function with ^:export metadata but it is ignored

conan17:01:03

I don't really want to put side-effects in my namespaces

noisesmith17:01:36

who calls the function?

noisesmith17:01:09

the point of :export is that something can now call it from the outside - I use a script tag in my shell html that calls the init to start the webapp

noisesmith17:01:15

(after all the scripts are loaded of course)

noisesmith17:01:47

and yes, not calling init from the top level of the ns is good - for example that makes testing more straightforward

fabrao17:01:35

hello all, what do you use in :optimizations to do not give problems with external js libraries?

mfikes18:01:07

@fabrao Anything but :advanced

shaun-mahood18:01:20

@conan: Happy to help over in the #re-frame channel

Jakub Holý (HolyJak)18:01:40

Any tip how to remove the duplication from

(AWS.Credentials.
      (ggo/get creds "AccessKeyId")
      (ggo/get creds "SecretAccessKey")
      (ggo/get creds "SessionToken"))
? I tried
(apply new AWS.Credentials 
   (map 
       #(ggo/get creds %) 
      ["AccessKeyId" "SecretAccessKey" "SessionToken"]))
but apply new evidently does not work 😞

noisesmith18:01:55

right, apply doesn't work with constructors or methods

noisesmith18:01:06

you can use a macro though

Jakub Holý (HolyJak)18:01:58

Yeah, that is always a valid answer in clojure(script) 🙂 Thanks!

noisesmith18:01:05

(defmacro make-creds [& sources] `(AWS.Credentials. ~@(map (partial ggo/get creds) sources))

noisesmith18:01:01

or maybe the ggo/get has to happen in the cljs at runtime, which means constructing it differently

noisesmith18:01:00

(defmacro make-creds [creds & sources] `(AWS.Credentials. ~@(map #(list 'ggo/get creds %) sources)))

mac0102119:01:34

Can anyone point me to an example of code that uses the cljs API (and specifically cljs.analyzer.api/analyze-file) to produce javascript from a cljs file?

thheller19:01:37

@mac01021 cljs.compiler.api/compile-file does that

mac0102119:01:52

Thanks @thheller! But is there no way to get JS out as a string without using the filesystem?

thheller19:01:36

you can yes but I don't think there is any official API for this.

thheller19:01:42

what are you trying to do? compiling one file won't work since it will require a few others to also be available

mac0102119:01:36

I want to be able to take any cljs file on my classpath and obtain the corresponding javascript as a string (to serve as a web response, most likely) This weekend I very quickly got to the point where I had

(with-core-cljs nil (fn []
                        (analyze-file "us/quartyard/wat.cljs")
                        (println(all-ns)) ;; prints essentially what I expect.
                        (now what???)))
But then I spent all day trying to figure out how to get the AST back out of the compiler state so that I could call emit on it. Couldn't figure it out. The API docs are pretty sparse.

thheller19:01:31

things are slightly more complicated than just serving one file though

thheller19:01:53

to get the actual AST you’ll need the analyze result

thheller19:01:04

analyze-file is mostly about populating the compiler env

mac0102119:01:05

But analyze expects a single form, while my namespace consists of a series of forms that should (I think?) all be incorporated into the same JS script.

mac0102119:01:04

There's no way to populate the compiler state and then extract the various analyzer results from it to emit the JS for each piece?

thheller19:01:04

not sure what the actual API is but you'd usually open a tools.reader instance, read one, analyze, emit, repeat

mac0102119:01:22

interesting.

mac0102119:01:25

And then use some other mechanism to emit the JS for the core namespace (which any other script will have to rely on)?

thheller19:01:28

forms-seq should help

thheller19:01:31

things are slightly more complicated since everything has to be loaded on the client side in order

thheller19:01:40

so you can't load one ns without having loaded cljs.core first

mac0102119:01:51

That's fine, as long as I can find a way to serve a copy of cljs.core so that the browser can load it

thheller19:01:54

and things get way more complicated when including JS dependencies

mac0102119:01:18

I should be able to gather all the dependency cljs files and then analyze/`emit` them all, concatenating all emissions into a single JS file, right?

mac0102119:01:51

oh JS dependencies

mac0102119:01:59

not cljs dependencies, got it

mac0102119:01:33

Ok. I'll give it a shot. Thanks for the pointers!

escherize21:01:39

Is there a spec for javascript datastructures (aka json)?

escherize21:01:51

something like #js [1 2 3]

mfikes21:01:58

@escherize For your particular example array? 🙂

escherize21:01:20

derp! 👌:skin-tone-3:

mfikes21:01:31

Also, throw in a bit of js/goog.isArrayLike for taste.

escherize21:01:43

🍻 thanks Mike

escherize22:01:36

now I have another one, I need to check that #js [1 2 3] === #js [1 2 3]. I know it’s not js/==.

escherize22:01:43

ERROR in (get-works) (zzz/api_test.js:86:46)
expected: (js/== n #js [1 2 3])
  actual: #object[ReferenceError ReferenceError: Can't find variable: _EQ__EQ_]

escherize22:01:06

Maybe (= (js->clj a) (js->clj b)) is good enough

mfikes23:01:48

@escherize goog.array/equals might fit the bill

mfikes23:01:38

^ In short, avoid js->clj if perf is important