This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
I am really bugged by the fact that I can't properly see the clojure collections in the browser debugger. I wish there was a plugin for that.
Is it theoretically possible to require JS stuff installed via NPM in the namespace declaration when compiling with the browser as target? Or is this for :target :nodejs
only?
Oh, and either way I get this error:
Error: Cannot find module '@cljs-oss/module-deps'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at [eval]:3:13
at ContextifyScript.Script.runInThisContext (vm.js:50:33)
at Object.runInThisContext (vm.js:139:38)
at Object.<anonymous> ([eval]-wrapper:6:22)
at Module._compile (module.js:652:30)
at evalScript (bootstrap_node.js:466:27)
So I have to add @cljs-oss/module-deps
to node_modules
or ClojureScript blows up.@henrik short answer is use #shadow-cljs. someone went through this a few days ago: https://theiceshelf.com/log/2018-06-cljs-npm-deps/
Thank you, I’m trying it out. My builds don’t all share the same :source-paths
, do you happen to know if it’s possible to scope :source-paths
to a specific build in shadow-cljs?
https://code.thheller.com/blog/shadow-cljs/2018/02/08/problem-solved-source-paths.html
Thank you, the happy news is it seems to work. Shadow-cljs seems to have much better defaults.
I’m compiling a server (in Node), and a client (browser), with coded shared between them to do SSR. The server works just fine, the browser reports that it is compiled, but doesn’t actually output a JS file.
With the vanilla cljs compiler I’ve been forcing it to do :simple and put the temp files somewhere else. This was necessary because it behaves very differently under :none and :advanced. Shadow-cljs doesn’t seem to be as brittle.
@crisptrutski could you bump the snapshot of boot-cljs-test on clojars? i think it's a few commits behind...
What is the best way to use cljs.spec and generate human readable errors? What do you use?
(s/def :ex/name string?)
(expound/defmsg :ex/name "should be a string")
(expound/expound :ex/name :bob)
This one looks really nice.it is used in shadow-cljs via expound.alpha/printer
and that is it. no other special hooks.
I've never tried, but https://github.com/alexanderkiel/phrase looks nice.
Looks ok, but my first impression about expound is better. I don’t like in phrase this:
(s/def ::password
#(<= 8 (count %) 256))
(defphraser #(<= min-length (count %) max-length)
But it could be some advantage which I don’t know I would like to use yetKeeping separated msg and spec like this:
(s/def :ex/name string?)
(expound/defmsg :ex/name "should be a string")
(expound/expound :ex/name :bob)
Make better impression for me.As I understand it, expound tries to make messages better for programmers while phrase tries to provide way to make messages better for users of the app. example of a message from expound readme:
;; -- Spec failed --------------------
;;
;; {:city ..., :state :CO, :country ...}
;; ^^^
;;
;; should satisfy
;;
;; string?
example of a message from phrase readme:
;;=> "The year has to be a positive integer."
Hard to say. It looks like expound do both, but I can’t be sure unless touch it on real case.
overkill? also cljs.spec didn't exist when I wrote most of my form validation stuff. don't see a need to rewrite that just cause ...
I would like to use the same clojure.spec rules on BE and FE to make it consistent, easy, simple. At least it is my idea. I can use exactly the same code for validation then.
i've used spec for forms
great for deciding if there is an error
always seems to fall short when it comes time to explain to the end user
yes i used the same spec in BE and FE
anything that uses the same predicates, or dispatches on predicates, for data validation and deciding what error message to show becomes awkward quickly
fns are great for logic but not for explaining to humans, i found
i found it more productive to do things like implement a new protocol on top of the data returned by spec's own explain
there's a lot of good contextual info in there that you can use to decide what message to show
probably (.fromCharCode js/String 169)
fwiw I’ve personally found that for a surprising amount of form validation via spec you don’t need anything but the path
path is enough to choose a reasonable error message - the big benefit I saw from spec is that you get enough stuff (i.e. all form errors at once) that you don’t need to bother with some other form validation dep
What are correct libraries for cljs? cljs.spec.alpha
, cljs.spec.gen.alpha
, clojure.test.check.generators
?
alpha.cljs:73 Uncaught Error: Var clojure.test.check.generators/simple-type-printable does not exist, clojure.test.check.generators never required
What about [cljs.spec.gen.alpha :as gen]
vs [clojure.test.check.generators :as gen]
?
you can probably start with the spec version
A) spec ns mostly aliases test.check ns B) but spec ns uses 0-arg-functions that return generators where test.check has just generators C) spec ns is intentionally lazy-loading so that you don't need test.check on the classpath to compile the code, just to actually run tests/generators
ok, it sound like cljs.spec is wrapper of test.check without additional value. Just to make it consistent for the future changes.
no, if you want the lazy loading then it adds value, and if you're intending to use s/with-gen
or any of the other spec<->generator APIs, then it can be easier to use the spec.gen namespace because it already provides things as 0-arg functions instead of generators
but it's definitely a wrapper, yes
i'm having trouble with the figwheel repl caching some old version of my files. the compiled js file is correct but when i use (in-ns 'my.namespace)
and then call a function I get the old version of it. any ideas?
@captaingrover it depends on your setup
>fwiw I’ve personally found that for a surprising amount of form validation via spec you don’t need anything but the path To add to this, here's a proof of concept that I've used for form validation in the past that demonstrates the "path" idea: https://gist.github.com/cjsauer/10735e7a93af7d4eb1ff9f39b2fc5eea
You normally only need the last failing spec in the path to display a proper error message
In js if the property name is the same as a variable name you can just do {prop} instead of {prop:propVar}. Is there a similar way to do this in clojurescript?
I could write my own function to do it but it would be cool to know if there was some util function/macro that does it
I'm trying to refer to a fully qualified def in one of my files but keep running into Use of undeclared Var
when I quote it it works fine, but I am not sure how to get the actual def the name represents
@theeternalpulse so you aren't requiring the library in the (ns
declaration?
no, I'm basically trying to inline them
so from myns.core :as a
and a/something
I want to just use myns.core/something
that causes issues
@theeternalpulse Hrm. In that case a/something
and myns.core/something
should resolve to the same var.
I'm confused as well, I'm using shadow-cljs but I figure since it's using the clojurescript compiler it may just be a generic issue
are you trying to "cheat" a circular dependency? if you don't have a require then it is not valid
you know what...
actually I don't think I am, let me trace the references
I think my plan of dynamically building these with a macro won't work
but that was my intent
since the functions I'm referencing share common namespace roots and names