This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-23
Channels
- # announcements (3)
- # babashka (68)
- # beginners (297)
- # calva (13)
- # cider (4)
- # clj-kondo (8)
- # cljs-dev (10)
- # cljsrn (26)
- # clojure (100)
- # clojure-europe (4)
- # clojure-germany (1)
- # clojure-italy (9)
- # clojure-nl (5)
- # clojure-spec (9)
- # clojure-uk (41)
- # clojurescript (69)
- # conjure (70)
- # cursive (44)
- # data-science (20)
- # datascript (2)
- # datomic (55)
- # emacs (1)
- # exercism (3)
- # graalvm (2)
- # kaocha (11)
- # leiningen (6)
- # meander (9)
- # mental-health (1)
- # off-topic (73)
- # pathom (6)
- # pedestal (1)
- # re-frame (3)
- # reagent (52)
- # reitit (8)
- # rum (39)
- # shadow-cljs (152)
- # spacemacs (10)
- # tools-deps (28)
- # xtdb (5)
stupid question. first run using deps.edn, I'm trying to modify an alias to disable cljs optimizations, not having any luck
not full featured like criterium but have you seen https://cljs.github.io/api/cljs.core/simple-benchmark?
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?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
@UCW9TUDNK does :each run for every (is ...) or for every deftest?
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?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.
but calling (db-refresh) in the function explicitly works, so would dispatch-sync solve the problem?
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.
I'm not that fluent myself. Here's a good tutorial: https://www.braveclojure.com/writing-macros/
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
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?(str host "/some-route")
?
(http/get (str (:base-url config) "/some-route"))
and config map contains the whatever is the correct base-url
How do I separate config based on whether I'm in production or development? My production environment is a docker container running on heroku
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
or override specific environment specific bits in configuration: docker run -e SERVER_ENDPOINT=
thats with plain docker, I am not familiar with heroku. It most likely has a way to set environment variables.
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")
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?
I'd mainly like to do any npm script running necessary for a particular alias
those sound like almost the same thing to me
if you have a clojure program, I would create an alias with :main-opts and then clj -A:foo
if you have a shell script, just call the shell script
no reason to involve deps.edn for that
clj is a clojure program runner (clojurescript compiler being one such program)
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
I suppose the shell/npm script can call the alias along with any other ones
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.
@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?
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.
shadow-cljs has no support for wasm yet so you kinda can only load the JS like they intended which sort of means webpack
I'd just produce a separate .js
file that exposes some global variable and load it separately from the CLJS output
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.
“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.
Btw, it occurs to me that a good reason to combine them would be in order to produce a redistributable CLJS lib
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
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.
the last time I checked it was using some webpack specific features that shadow-cljs doesn't have
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.
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).
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
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)
I'm really not sure what to do here.