Fork me on GitHub
#clojurescript
<
2018-02-07
>
richiardiandrea00:02:40

For andare users, is alt! working for you? I have:

(async/alt! 
  (step-chan :attempt-commit ...) ([value] value)
  (async/timeout *stm-default-timeout*) (timeout-error-state state errors history)
  :priority true)
But I keep getting both clauses called (timeout AND vale)

richiardiandrea00:02:25

I am worried I am not getting the syntax right

noisesmith01:02:27

when you say you are getting both, does the alt! call return both? or do you just mean that both are realized?

richiardiandrea01:02:35

No it returns the timeout error

richiardiandrea01:02:00

but if I use <! only the call is not timing out

richiardiandrea01:02:23

and I see println from step-chan so it is executed as well

richiardiandrea02:02:33

Maybe the problem is not core.async but the code converting from a promise to a channel actually

xiongtx02:02:22

@dnolen Given the compiler state, is there a way to macroexpand a cljs form from the clj side? cljs.analyzer/macroexpand-1 needs an env; is that part of the compiler state? This is related to tooling: https://github.com/clojure-emacs/cider/issues/2099#issuecomment-363274445

royalaid06:02:25

Hey all I am trying learn how use :npm-deps. I am trying to replicate the example using react but whenever I try to load my page with reagent using the :npm-deps react my page fails to load complaining that process isn't defined however I have explictly enabled :process-shim. Any ideas?

royalaid02:02:01

So upon further investigation it seems that react, more specifically emptyobject.js (which checks process), fails to load and causes react to fail to do so. Anyone else encountered this?

dnolen08:02:41

@xiongtx pretty sure you just need to supply an analysis environment

dnolen08:02:29

isn’t there a cljs.analyzer.api/macroexpand thing-y?

xiongtx08:02:56

There’s no cljs.analzyer.api/macroexpand. There’s cljs.analyzer/macroexpand, but I’m not sure how to get the analysis environment.

dnolen14:02:56

Please fill out the survey if you haven’t already 🙂

orestis16:02:53

So I’m struggling to figure out how to do a server-based (node) CIDER session with ClojureScript. I’m basically looking to evaluate s-exps within my editor and get results back. It seems though that most REPL solutions for CLJS are via figwheel?

richiardiandrea17:02:20

The node story is quite poor to be frank, I am using lumo for that but no cider, I am using inf-clojure

orestis17:02:25

Ah. Thanks.

dehli17:02:09

I’ve been using lumo (however I don’t have it hooked into cider). I think there’s some work with getting it hooked using inf-clojure

dehli17:02:08

Does anyone know why the following test will fail to apply the redef?

(deftest download-file-fail-throws-error
  (async done
    (with-redefs [project.s3/download-file #(js/Promise. #(%2 "error")
                  project.util/delete-file-sync identity]
      (-> (upload-pdf)
          (.catch (fn [error]
                    (is (= error "error"))
                    (done)))))))

joelsanchez17:02:50

in js, async tests conflict with with-redefs

dehli17:02:45

Gotcha, is there any workaround?

joelsanchez17:02:15

well...you're pretty much f*cked but there are hacks that work in some cases, like that macro that used set!...

dehli17:02:25

Thanks for the link! I’ll check it out 🙂

joelsanchez17:02:42

actually, the last link is the one with the set! macro 😂

dehli17:02:11

Haha, that could be a short term solution!

dehli17:02:30

I see that it’s resolved as not a bug. Do you happen to know why that was?

joelsanchez17:02:49

I remember something like "intented behavior" from someone important 🙂

noisesmith17:02:02

the best thing to do is replace code that needs with-redefs with code that doesn’t need with-redefs because the thing you would redefine is a first class argument to the function (this applies even when with-redefs doesn’t break, on cljs or clj)

joelsanchez17:02:07

yeah, @dnolen says it's not a bug

dehli17:02:19

Ahhh, that makes sense. So it encourages better structure

noisesmith17:02:20

an optional argument or something that uses partial to construct the function used in actual code are options to keep that function elegant to use, but providing something as an arg instead of redefining globally avoids a lot of pain

noisesmith17:02:46

oh, and a third way to make it easier to use is to pass in an implementation map (this combines nicely with libs like stuartsierra/component that provide you a map of implementations of things that rely on initialized state)

joelsanchez17:02:08

of course the other option is to rethink the test to avoid asynchrony, for example you could move the code that does the server request out of the "upload-pdf" fn, and simply ensure it executes the other fn with proper args

noisesmith17:02:56

that’s true as well - in general isolating channel usage and talking to outside entities are both big wins when making something you can test and reason about

dehli17:02:06

Thanks you all! Will rethink some of the testing

rnagpal19:02:45

I have a multi module clojurescript project

rnagpal19:02:13

Local checkout and refreshing the project doesn’t work

rnagpal19:02:34

I mean when I modify the project, another project which imports the jar, doens’t see the changes right away

justinlee20:02:31

@rnagpal maybe try #leiningen ?

justinlee20:02:55

I’ve been puzzling over a clojurescript-specific problem something for over a day now: I have an upload function called upload-async that uses cljs-http to upload a file to a server. I would like to limit its concurrency, to, say, 4 uploads at once. This seems super simple, but I cannot wrap my head around it to save my life. I’m even thinking about using an atom, a watcher, and a queue to solve this problem but I can’t help but think there must be something simple to accomplish this. Any thoughts?

noisesmith21:02:53

have a function that produces a go-block that reads a shared request channel to get a URI, then uses cljs-http to upload, then loops - call it 4 times

noisesmith21:02:32

(that’s one way to do it at least - not smart for larger concurrency, but 4 parallel uploads seems reasonable that way)

noisesmith21:02:18

oh wait - it’s not that simple - it needs to park on the chan cljs-http returns, then loop

justinlee21:02:14

@noisesmith that’s pretty close to where i’m going: a concurrency atom + queue. the function checks concurrency and dump the uri into the queue if concurrency is too high, then basically the first 4 calls to the function will drain the queue by parking on the cljs-http channel then checking the queue

noisesmith21:02:44

if you take input from a channel you get the queue management for free

noisesmith21:02:29

I might think differently if you aren’t already bought into core.async, but cljs-http makes that decision for you

justinlee21:02:19

i’m probably being dense here, but how does that work? right now i just do a (upload-file js-file-object). Are you suggesting that I change that to (put! global-upload-channel js-file-object)?

noisesmith21:02:53

right, or you can define a function that does the put! if you want to leave the API unaltered for consumers

justinlee21:02:19

that makes sense. thanks!

royalaid02:02:01

So upon further investigation it seems that react, more specifically emptyobject.js (which checks process), fails to load and causes react to fail to do so. Anyone else encountered this?