Fork me on GitHub
#clojurescript
<
2020-04-23
>
hoppy01:04:42

stupid question. first run using deps.edn, I'm trying to modify an alias to disable cljs optimizations, not having any luck

hoppy01:04:52

I just get seemingly crazy responses from 'clj' adding "-O" "none", etc.

kimim04:04:24

Hello, is there any good way to get restful API from client side in clojurescript

Spaceman04:04:25

is there a criterium-like alternative for cljs for benchmarking?

dpsutton05:04:36

not full featured like criterium but have you seen https://cljs.github.io/api/cljs.core/simple-benchmark?

Spaceman08:04:29

My use-fixture doesn't seem to work in my tests. I have this fixture defined in my namespace:

(use-fixtures :each db-refresh)
And db-refresh looks like:
(defn db-refresh [f]
  (do (dispatch [:initialize-db])
      (dispatch [:update-filter true "cat"])
      (dispatch [:update-filter true "cat1"])
      (dispatch [:show-products products])
      )
  (prn "all dispatched")
  (f)
  )
But when I run my tests, "all dispatched" isn't printed in the console, and db-refresh function seems to have not been run. Why might this be?

herald09:04:21

In ClojureScript, db-refresh is expected to be a map with :before and/or :after keys with function values. https://clojurescript.org/tools/testing#fixtures

herald09:04:03

I also burnt myself on this difference!

Spaceman10:04:07

@UCW9TUDNK does :each run for every (is ...) or for every deftest?

herald10:04:48

Pretty sure it's every deftest, otherwise I would have loads of failing tests..

Spaceman10:04:40

is there a strategy for resetting the db for every (is...)?

Spaceman10:04:13

other than sandwiching a reset function throughout?

herald10:04:14

Not that I know of

Spaceman22:04:03

I have the following:

(defn db-refresh []
  (dispatch [:initialize-db])
  (dispatch [:update-filter true "cat"])
  (dispatch [:update-filter true "cat1"])
  (dispatch [:show-products products])

  (prn "dispatched!!!!!!!!")
  )

(use-fixtures :each {:before db-refresh :after #()})
In my test file, but when I run the tests, the dispatches don't seem to occur, neither do I see the prn in the console, so essentially the db-refresh is not being run. Why would that be?

herald11:04:36

Could you try using dispatch-sync instead? If that doesn't help, it seems like there's something wrong with your deftests or test runner.

Spaceman12:04:36

but calling (db-refresh) in the function explicitly works, so would dispatch-sync solve the problem?

herald09:04:09

I understand that case takes compile-time literals for its tests, but is there anyway at all to inline a list of literals that are defined elsewhere (like you can with the C preprocessor)? ie. I have (def constraint-ops-single '("=" "!=" "<" "<=" ">" ">=" "CONTAINS" "LIKE" "NOT LIKE")) defined elsewhere, and I don't want to repeat the list of literals in my case expression.

p-himik09:04:47

I think it should work with a macro.

herald09:04:48

Could you provide an example? I'm not too familiar with writing macros.

p-himik09:04:45

I'm not that fluent myself. Here's a good tutorial: https://www.braveclojure.com/writing-macros/

herald09:04:55

Thanks. Looks like it was suprisingly easy!

user=> (def ops '("ONE" "TWO"))
#'user/ops
user=> (defmacro value-key [op]
`(case ~op
~ops :yay))
#'user/value-key
user=> (value-key "ONE")
:yay

đź‘Ť 4
Spaceman10:04:36

Is there a way to specify only the route and not the host in cljs-http? I'm making requests like so:

(http/get ""),
But the host changes in production. And so I have to manually change localhost:3000 to the production url, which is undesirable. I'm using the Luminus template, in which mat least cljs-ajax works without specifying the host, but trying with cljs-http didn't work. Is there a way to make it work with cljs-http?

nikolavojicic10:04:33

(str host "/some-route") ?

jsyrjala10:04:14

(http/get (str (:base-url config) "/some-route")) and config map contains the whatever is the correct base-url

Spaceman11:04:01

how to set up config?

Spaceman04:04:57

How do I separate config based on whether I'm in production or development? My production environment is a docker container running on heroku

jsyrjala09:04:39

You could for example pass a configuration file name via command line arguments or environment variables docker run image-name java myfile.jar /path/to/config-prod.edn or docker run -e CONFIG=/path/to/config-prod.edn

jsyrjala09:04:24

or override specific environment specific bits in configuration: docker run -e SERVER_ENDPOINT= -e DATABASE_ENDPOINT= image-name

jsyrjala09:04:37

thats with plain docker, I am not familiar with heroku. It most likely has a way to set environment variables.

jsyrjala09:04:47

Then you can construct the config map based on the environment. config is just a normal map. For example: (let [config {:server-endpoint (System/getEnv "SERVER_ENDPOINT")

theeternalpulse17:04:36

what would be the best way to run a script from a deps.edn alias. Would I just have to have a namespace with some tooling to call shell scripts and call it with the :main-opts, or can I somehow call main opts directly in a clojure alias?

theeternalpulse17:04:20

I'd mainly like to do any npm script running necessary for a particular alias

Alex Miller (Clojure team)18:04:07

those sound like almost the same thing to me

Alex Miller (Clojure team)18:04:43

if you have a clojure program, I would create an alias with :main-opts and then clj -A:foo

Alex Miller (Clojure team)18:04:55

if you have a shell script, just call the shell script

Alex Miller (Clojure team)18:04:06

no reason to involve deps.edn for that

Alex Miller (Clojure team)18:04:17

clj is a clojure program runner (clojurescript compiler being one such program)

Alex Miller (Clojure team)18:04:49

if your goal is to assemble many programs, some of which are not clojure programs, then I would look to something else (bash, make, whatever) to do that assembly

theeternalpulse18:04:22

I suppose the shell/npm script can call the alias along with any other ones

henrik19:04:51

Has anyone had any luck in calling WASM from CLJS? I have a non-toy, but reasonable sized experiment I’d rather tinker with from Clojure than JS.

thheller19:04:41

@henrik what kind of wasm do you have? most contains/requires some JS glue-code that you either need to load or run through something like webpack?

henrik20:04:12

Yeah, the auto-generated gunk from Rust. I’m happy to wrap it in something more palatable for shadow-cljs manually if that’s what it takes, I’m just not sure how.

thheller20:04:13

shadow-cljs has no support for wasm yet so you kinda can only load the JS like they intended which sort of means webpack

henrik20:04:18

Oh no, not webpack. Does shadow play well with webpack?

thheller20:04:21

I'd just produce a separate .js file that exposes some global variable and load it separately from the CLJS output

thheller20:04:37

you can combine them but don't really gain anything

thheller20:04:08

I haven't looked at the code rust generates in a while

thheller20:04:15

it used to change like every few days

thheller20:04:23

dunno if its more stable now

henrik20:04:17

It hasn’t changed for the month and a half I’ve been using it at least. But I guess WASM itself is evolving rapidly as well.

thheller20:04:44

yeah the wasm import spec is still not finalized I think

henrik20:04:04

“WebAssembly CG members representing four browsers, Chrome, Edge, Firefox, and WebKit, have reached consensus that the design of the initial WebAssembly API and binary format is complete… This consensus includes a JavaScript API and binary format accompanied by a reference interpreter.” Maybe we’ll see fewer changes now.

henrik21:04:56

Btw, it occurs to me that a good reason to combine them would be in order to produce a redistributable CLJS lib

thheller06:04:37

I meant this https://github.com/WebAssembly/esm-integration/tree/master/proposals/esm-integration which is still stage 2 and not implemented in any browser

thheller06:04:55

and that will also be rather complicated to support in CLJS

thheller06:04:05

so we'll see where all this goes I guess

henrik08:04:02

Yeah, bit of a PITA to have to load the file manually rather than via a script tag, but not a dealbreaker I would think.

thheller08:04:24

the question really is what the generated rust code does

thheller08:04:41

the last time I checked it was using some webpack specific features that shadow-cljs doesn't have

thheller08:04:24

using wasm from CLJS is easy .. the required JS glue-code is the issue

henrik10:04:35

So the problem is in consuming the exported functions from the glue code?

henrik10:04:06

My understanding is that WASM only supports sending (vectors of) ints and floats across the JS <-> WASM border. Therefore, it makes a bunch of helper functions that converts strings to vectors of ints (and vice versa on the WASM side), then creates an export function for every endpoint exposed by WASM, using the string conversion functions inside those where necessary.

henrik10:04:06

For data structures, I’m basically serializing, converting to string, reading the string, and deserializing into Rust. It’s like you’re talking to a server over a network (for goodness sake).

thheller11:04:24

yes, wasm is basically all byte arrays. so to support calling functions with string arguments and so on you need some JS gluecode that does the conversions back and forth

thheller11:04:52

thats all going to get better with WASI but thats still in development

Guillermo Ithier20:04:59

Hello everyone. I'm getting this error when I run a mies project by default by simply connecting to my namespace like so (require 'foo.core :reload). (require 'goog-sheets2.core) RangeError: Maximum call stack size exceeded (<NO_SOURCE_FILE>) cljs.core/= (out/cljs/core.cljs:1258:1) require__ (out/clojure/browser/repl.cljs:212:16) require__ (out/clojure/browser/repl.cljs:226:33) require__ (out/clojure/browser/repl.cljs:226:33) require__ (out/clojure/browser/repl.cljs:226:33) require__ (out/clojure/browser/repl.cljs:226:33) require__ (out/clojure/browser/repl.cljs:226:33) require__ (out/clojure/browser/repl.cljs:226:33) require__ (out/clojure/browser/repl.cljs:226:33) require__ (out/clojure/browser/repl.cljs:226:33)

Guillermo Ithier20:04:33

I'm really not sure what to do here.