Fork me on GitHub
#clojurescript
<
2018-06-11
>
tony.kay01:06:58

does anyone know of a way to get the compiler to use the “production” cljsjs dependencies in development mode? I’m trying to diagnose a problem that only happens when using production react (minified), but will be much faster to deal with if I can work through it with hot code reload and incremental compile

tony.kay01:06:26

all I can think to do is “roll my own” react cljsjs dep, which is doable, but annoying

dnolen01:06:48

@tony.kay you can always override foreign deps

dnolen01:06:29

if you supply a foreign dep in your build EDN with an identical :provides whatever you specify will override the dep’s foreign spec

dnolen01:06:00

old feature actually - quite useful 🙂

tony.kay01:06:41

nice…thanks David

dnolen01:06:54

@www.w.com123 can’t do that in Clojure (and thus ClojureScript)

dpsutton02:06:31

@www.w.com123 there was discussion of that on clojureverse (https://clojureverse.org/t/shortand-clojure-syntax-for-properties-on-hashmaps/1918). There was a provided macro if you were interested

henrik04:06:44

I’m looking at Firebase Functions, and in the examples they provide, they want you to do stuff like this:

exports.app = functions.https.onRequest(app);
What is exports and how would I attach something like (. (.-https functions) onRequest app) to it? Running (js/console.log js/exports), exports doesn’t seem to be an object available by default.

thheller14:06:28

@henrik https://shadow-cljs.github.io/docs/UsersGuide.html#target-node-library :exports {:app your.ns/app} (def app (.. https -functions (onRequest ...)))

henrik08:06:02

Thanks @thheller, I ended up recreating my entire project from scratch. Now I have a fairly working combination of shadow-cljs + re-frame + Firebase + Flamelink (headless CMS) + server-side-rendering, which is a fair amount of moving parts to get right. To me, dev in the JS ecosystem feels a lot like shaking a box of Legos really hard and hoping that a castle pops out.

thheller08:06:41

yeah absolutely agree. I recently started some experiments for azure functions using shadow-cljs https://github.com/thheller/shadow-cljs/issues/297. want to do the same for firebase functions eventually. coding them should just feel natural and let the build take care of all the boilerplate

dnolen14:06:34

@henrik that sounds like Node-ism to me? If you can sort out what they mean by exports attaching stuff to that is trivial

dnolen14:06:00

(goog.object/set js/exports "app" ...)

henrik08:06:04

Thanks, I ended up recreating the project from scratch, then setting module.exports instead of exports (which didn’t work previously), and it works fine now. I love non-deterministic programming.

jaydeesimon15:06:07

question about invoking a clojurescript function from javascript…

jaydeesimon15:06:15

let’s say I have this function def

jaydeesimon15:06:20

(ns jaydeesimon.core)

(defn ^:export make-str [{:keys [x y]}]
  (str x y))

jaydeesimon15:06:39

how do i invoke that from javascript?

jaydeesimon15:06:44

jaydeesimon.core.make_str({x: "hello" y: "world"}); ?

jaydeesimon15:06:16

doesn’t seem to work…i tried looking at the transpiled source for clues but it wasn’t obvious

thheller15:06:36

you are calling it correctly but you are calling it with a JS object

thheller15:06:45

which cannot be destructured like that

jaydeesimon15:06:28

gotcha. so what would i need to pass in?

thheller15:06:14

(defn ^:export make-str [^js obj]
  (str (.-x obj) (.-y obj)))

jaydeesimon15:06:59

thank you. is there a way to invoke the function using the original signature (passing a clojure map)?

thheller15:06:30

you can use js->clj to convert the obj to a cljs map

jaydeesimon15:06:53

got it. thanks for clarifying!

dnolen15:06:21

also there are plenty of useful Closure Library fns for dealing with JS data - if that’s more natural for your program I would avoid marshalling back and forth - haven’t heard enough about your goals to know which makes more sense

Bravi15:06:47

is there a tool for cljs that will automatically format code?

dnolen15:06:07

if you already have a bunch of code using Clojure data structures then what @thheller suggests is best

dnolen15:06:43

@bravilogy maybe parinfer can do that? \cc@shaunlebron

jaydeesimon15:06:28

@dnolen, i would love to be pointed to any Closure Library fns you think are related. i’m in exploration mode right now. i’d like to write some clojurescript functions and know how to use them from javascript. i was playing around with it and realized I had written a function passing in a map (and was destructuring it) and then couldnt figure out how to call it 🙂

jaydeesimon15:06:24

i ended up rewriting it so that I was just passing in the map values as args but I figured I should hear from the experts

shaunlebron15:06:08

@bravilogy check out cljfmt, zprint, and parlinter

Bravi15:06:48

actually I just found out there’s aggressive indent mode 😄

shaunlebron15:06:57

parlinter doesn’t insert/remove newline, and the others do

Bravi15:06:57

I’m using spacemacs and that’s what it does, automatically

Bravi15:06:12

thanks for suggestions

aengelberg16:06:36

Is there any way to run unit tests in ClojureScript without explicitly naming all the namespaces I want to test? I'd like to write an internal utility (e.g. a leiningen alias) to make it easy to automatically run clojurescript tests in any of our clojurescript-compatible projects, but the necessity of a "test runner" that explicitly depends on namespaces to test is preventing me from making such a thing.

dnolen16:06:53

you need to come up with some way to enumerate test nses

dnolen16:06:19

once you do that then eval’ing to run those isn’t difficult

dnolen16:06:44

pretty sure someone already did this

kwladyka17:06:10

Not sure if it is possible in cljs, but in Clojure you can do like that: project.clj

:test-selectors {:default (complement :integration)
                   :integration :integration
                   :all (constantly true)}
test file
(deftest ^:integration orders-test
    (testing "orders"
      (is (= order-36205 (get-order hc 36205))
          "one order")))

richiardiandrea23:06:43

If I compile two ClojureScript artifacts to two separate index.js files and require them in the same node process, am I going to have problems generally with the spec global registry? Or any global for that matter?

richiardiandrea23:06:31

Has anybody tried something like that?