Fork me on GitHub
#clojurescript
<
2020-08-24
>
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)

kwladyka08:08:04

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 https://github.com/alexanderkiel/phrase

👍 1
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. https://cljdoc.org/d/metosin/spec-tools/0.10.4/doc/spec-coercion

restenb10:08:58

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

thheller10:08:41

(js/console.clear)

restenb10:08:58

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

thheller10:08:26

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

restenb10:08:01

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

restenb10:08:25

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

p-himik10:08:07

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

restenb10:08:09

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

rickmoynihan13:08:13

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?

rickmoynihan13:08:14

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

rickmoynihan14:08:11

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: 

rickmoynihan14:08:11

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

rickmoynihan14:08:37

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

rickmoynihan14:08:51

https://clojurescript.org/news/2019-01-31-release ahh I guess you do require them if you have an fspec?

rickmoynihan14:08:09

though I don’t define any :ret specs

rickmoynihan14:08:24

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