Fork me on GitHub

I got an error about trying to import malli.instrument in cljs, and in fact I see that in the malli repo we have only a instrument.clj file. Does this mean that I can't do instrumentation in cljs?


have you tried malli.instrument.cljs? It's apparently seen some bugfixes since the last release so I don't know if it works, but I happened upon it a few days ago

🙌 1

Thank you, you're right! Here's how I missed that: I looked at this folder and I could only find the clj version. So I wrongly assumed that was the only available possibility!


How does the naming schema in the instrument folder work? I have never seen something like this!


I'm guessing that malli.instrument contains functions for the clojure impl. the cljs impl must be implemented via macros (but otherwise with the same names), so a new namespace malli.instrument.cljs was created.


I'm still getting this at times, though:

------ REPL Error while processing ---------------------------------------------
(ns couperin.user
  (:require [portal.web :as p]
            [malli.core :as m]
            [malli.instrument :as mi]
            [ :as dev]))
The required namespace "malli.instrument" is not available, it was required by "couperin/user.cljs".
"malli/instrument.clj" was found on the classpath. Maybe this library only supports CLJ?


Same thing for the namespace


hey, I contributed the cljs support, it's in need of some documentation. When using the instrumentation for cljs the namespaces should be: [malli.instrument.cljs :as mi] [ :as md] and there is kondo support but it must be executed at runtime (because the schemas aren't available during compilation (macroexpansion)) and prints to the console, with the intention being you copy it to a kondo config file. the js console errors need some work (the pretty one is designed with terminal emulators in mind, not js web console) but if you execute an instrumented fn via nrepl in an editor the error output there is better.

🙌 1

Thank you @U051V5LLP, I'm a bit confused on how instrumentation works on cljs. Even after importing:

(:require [portal.web :as p]
            [malli.core :as m]
            [malli.instrument.cljs :as mi]
            [ :as dev])
and adding:
(m/=> -add [:=> [:cat :int :int] :int])
(defn -add [x y]
I can still execute calls like:
(-add 1 "a")
getting "abcd" as my answer (and I see that I have the instrumentation message in the browser console:
{ns: 'couperin.user', name: '-add', str: 'couperin.user/-add', _hash: 150786855, _meta: null, …}
just not any error whatsoever


Ok, if I call (dev/start!) just before a call to -add, then I get the errors, but if I then modify the definition of -add , the instrumentation is not redone automatically


instrumentation works by replacing the function implementations so when hot reload happens the original functions will be replace the instrumented code. you'll want to call instrument! or start! after the hot code reload runs (usually something like (defn ^:dev/after-load refresh [] (md/start!)...) for shadow.cljs


Thank you, would you still advice to do ? I can get it to check something but it's clearly confused by namespaces. Is there a particular place the refresh function you just mentioned should live?