Fork me on GitHub
Kasey Speakman01:08:24

For form validation in CLJS app, am I right in thinking I will need: • spec step for raw input strings - e.g. required but blank • transform step - e.g. "asdf" can't convert to number • spec step for converted data (not in range or otherwise logically invalid)


So this is how it can be done with spec in cljs

Kasey Speakman14:08:54

Ok, cool. Thanks.

Dmytro Bunin07:09:28

this is another cool library which can help you out

👍 3
Kasey Speakman01:08:09

Or I guess just not sure what is good practice there. Previously in F#, I wrote a very small lib to compose validations and/or type conversion. (Failing to type-convert as a validation error.)

Kasey Speakman02:08:40

Hmm, looks like maybe spec-tools or something like it is a common answer.

Bediako George06:08:56

Hi! Question regarding best practice around configuring values/constants based on deployment. I want to have a different value for variable/constant based on whether the clojurescript app is running in DEV v TEST v PROD. I am running re-frame. Any suggestions or pointers?

Pete Parker00:09:25

Is there a distinction in shadow-cljs between a test release and a prod release? The only options seem to be :dev and :release, which means all release builds will use the same values.


If your test build must be sufficiently different from the dev build, then you can just add a new build configuration specifically for testing.

Pete Parker18:09:33

It’s different only in the :closure-defines so it would be too much duplicate configuration to have the test as its own config.


I don't know shadow-cljs that well to give a better answer - you should definitely ask in #shadow-cljs


anybody know how the clear the browser dev console from ClojureScript?




tried that, it fails (console is not a function)


console is not expected to be a function? sounds like you maybe tried (js/console)?


thought i'd add it to the :before-jsloadfigwheel hook


it's weird, "my" js/consoleonly has error, info, log, and warn methods available


I think you either have a very strange browser or something overrides the global console object.


must be something with how or when Figwheel calls my on-jsload function. If I just add (js.console/clear)to my "main" method it works


So I just added some specs into a clojurescript project, that uses (st/instrument) to instrument the specs in dev. This is in a browser, and the spec errors are almost unusable in the console — like far worse than clj is. I’m currently using the binaryage/cljs-devtools, and suspect that might be contributing to making them worse. How do people get useful errors out of spec instrumentation in cljs?


I already include expound actually, thanks - i’ll give it a try


@rickmoynihan This ticket includes some code for an error formatter for devtools.

👀 3

ahh it’s the same as what I’ve already taken from the README 🙂 Thanks for the heads up though

👍 3

If that doesn’t work for you, I’d be curious to see what you end up doing. I am interested in expanding the Expound documentation to include some additional ideas on this topic.


Looks fine for now, but I’ll let you know if I think of anything

👍 3

Hmmm I swear this was working yesterday, but today my spec errors aren’t being pretty printed 😕


I have:

(ns myapp.error-formatter
  (:require [cljs.repl :as repl]
            [expound.alpha :as expound]
            [cljs.spec.alpha :as s :include-macros true]))

(set! s/*explain-out* expound/printer)

(println "error formatter set")

(def devtools-error-formatter
  "Uses cljs.repl utilities to format ExceptionInfo objects in Chrome devtools console."
      (fn [object _config]
        (println "custom formatter called")
        (when (instance? ExceptionInfo object)
          (let [message (some->> (repl/error->str object)
                                 (re-find #"[^\n]+"))]
            #js["span" message])))
      :hasBody (constantly true)
      :body (fn [object _config]
              #js["div" (repl/error->str object)])})
(defonce _
         (some-> js/window.devtoolsFormatters
                 (.unshift devtools-error-formatter)))
in a namespace, and shadow-cljs incuding this via a preload:
:preloads [devtools.preload
                              myapp.error-formatter ;; <- pretty print spec errors with expound
                              myapp.front-end-specs ;; <- spec instrumentation


Ok I seemed to have an out dated install of cljs-devtools… upgrading seems to have fixed this

👍 3

hmm… just tweaked a spec, and now getting:

Var clojure.test.check.generators/simple-type-printable does not exist, clojure.test.check.generators never required
reporter.cljs:32 In CLJS DevTools 1.0.0, an exception was raised during value formatting.

 Error: Var clojure.test.check.generators/simple-type-printable does not exist, clojure.test.check.generators never required
    at eval (alpha.cljs:74)
    at Object.eval [as cljs$core$IDeref$_deref$arity$1] (alpha.cljs:22)
    at Object.cljs$core$_deref [as _deref] (core.cljs:686)
    at Object.cljs$core$deref [as deref] (core.cljs:1475)
    at Function.eval [as cljs$core$IFn$_invoke$arity$variadic] (alpha.cljs:74)
    at Object.cljs$spec$gen$alpha$simple_type_printable [as simple_type_printable] (alpha.cljs:74)
    at eval (alpha.cljs:90)
    at Object.eval [as cljs$core$IDeref$_deref$arity$1] (core.cljs:10572)
    at Object.cljs$core$_deref [as _deref] (core.cljs:686)
    at Object.cljs$core$deref [as deref] (core.cljs:1475)

Please report the issue here: 


I’m assuming this is because I have some fspec s on some functions that are used in an fdef


I’d thought that cljs had stopped requiring you to use clojure.test.check generators 👀

rickmoynihan14:08:51 ahh I guess you do require them if you have an fspec?


though I don’t define any :ret specs


yeah ok just adding a require for clojure.test.check fixes this