This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-26
Channels
- # announcements (6)
- # babashka (29)
- # babashka-sci-dev (2)
- # beginners (129)
- # calva (9)
- # clara (16)
- # cljdoc (49)
- # clojure (125)
- # clojure-bay-area (3)
- # clojure-europe (55)
- # clojure-france (1)
- # clojuredesign-podcast (8)
- # clojurescript (85)
- # conjure (3)
- # core-logic (2)
- # cursive (1)
- # events (1)
- # honeysql (61)
- # jobs-discuss (23)
- # lsp (69)
- # malli (14)
- # nrepl (3)
- # off-topic (16)
- # portal (11)
- # re-frame (8)
- # releases (1)
- # ring (2)
- # shadow-cljs (12)
- # vim (42)
- # xtdb (18)
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 https://github.com/metosin/malli/blob/master/src/malli/instrument/cljs.clj
Thank you, you're right! Here's how I missed that: I looked at this folder https://github.com/metosin/malli/tree/master/src/malli 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]
[malli.dev :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?
ah it's probably a weird interaction with shadow-cljs https://clojureverse.org/t/problem-using-malli-clojurescript-instrumentation-and-shadow-cljs/8612/3
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]
[malli.dev.cljs :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.
https://github.com/metosin/malli/blob/400dc0c79805028a6d85413086d4d6d627231940/src/malli/clj_kondo.cljc#L203
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.
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]
[malli.dev.cljs :as dev])
doing
(comment
(dev/start!))
and adding:
(m/=> -add [:=> [:cat :int :int] :int])
(defn -add [x y]
"abcd")
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:
..instrumented
{ns: 'couperin.user', name: '-add', str: 'couperin.user/-add', _hash: 150786855, _meta: null, …}
just not any error whatsoeverOk, 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.
https://shadow-cljs.github.io/docs/UsersGuide.html#_lifecycle_hooks
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 https://clojureverse.org/t/problem-using-malli-clojurescript-instrumentation-and-shadow-cljs/8612/2 ? 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?
just the standard setup you'd have for any cljs (utilizing react) app: https://github.com/day8/re-frame/blob/69cf39552715fa410e7007b7fcbc894097d8db1f/examples/todomvc/src/todomvc/core.cljs#L57