Fork me on GitHub
#clojurescript
<
2018-06-10
>
roti08:06:31

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.

henrik08:06:22

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?

henrik08:06:02

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.

thheller08:06:10

@henrik short answer is use #shadow-cljs. someone went through this a few days ago: https://theiceshelf.com/log/2018-06-cljs-npm-deps/

henrik08:06:44

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?

thheller09:06:21

no that is not possible

thheller09:06:31

just including everything always is ok though

henrik09:06:19

Thank you, the happy news is it seems to work. Shadow-cljs seems to have much better defaults.

henrik09:06:55

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.

thheller09:06:02

what is the config you used?

henrik09:06:19

I discovered my error. I didn’t set output-dir properly for the client part.

thheller09:06:04

ah yeah that defaults to public/js

henrik09:06:09

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.

thheller09:06:22

geez that must have been painful to wait for :simple all the time

thheller09:06:50

but yeah shadow-cljs fixes many caching issues and related stuff

thedavidmeister10:06:07

@crisptrutski could you bump the snapshot of boot-cljs-test on clojars? i think it's a few commits behind...

kwladyka10:06:09

What is the best way to use cljs.spec and generate human readable errors? What do you use?

kwladyka10:06:03

Actually it would be nice to use the same rules for FE/BE to make it consistent.

kwladyka11:06:59

(s/def :ex/name string?)
(expound/defmsg :ex/name "should be a string")
(expound/expound :ex/name :bob)
This one looks really nice.

kwladyka11:06:39

Is it a way how you prefer to use it?

thheller11:06:00

it is used in shadow-cljs via expound.alpha/printer and that is it. no other special hooks.

kwladyka11:06:23

So not custom messages then? I want to use it to validate forms

thheller11:06:03

I'm not using it in CLJS at all no

kwladyka11:06:54

Hmm so how do you make error messages in forms for user?

kwladyka11:06:17

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 yet

kwladyka11:06:56

Keeping 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.

nenadalm11:06:12

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."

kwladyka11:06:25

Hard to say. It looks like expound do both, but I can’t be sure unless touch it on real case.

kwladyka16:06:21

you are probably right

thheller11:06:22

by writing 5 lines of code 😉

kwladyka11:06:57

hmm no cljs.spec for that purpose? Why?

thheller11:06:42

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 ...

kwladyka11:06:22

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.

thedavidmeister11:06:50

i've used spec for forms

thedavidmeister11:06:12

great for deciding if there is an error

thedavidmeister11:06:20

always seems to fall short when it comes time to explain to the end user

kwladyka11:06:21

Someobody use the same clojure.spec for BE and FE? If not, why?

thedavidmeister11:06:34

yes i used the same spec in BE and FE

thedavidmeister11:06:11

anything that uses the same predicates, or dispatches on predicates, for data validation and deciding what error message to show becomes awkward quickly

thedavidmeister11:06:30

fns are great for logic but not for explaining to humans, i found

thedavidmeister11:06:31

i found it more productive to do things like implement a new protocol on top of the data returned by spec's own explain

thedavidmeister11:06:51

there's a lot of good contextual info in there that you can use to decide what message to show

roti11:06:40

any ideas how to use html escape codes with react? (like "&copy;")

roti11:06:05

cool, thanks

roti11:06:21

any idea why they don't work by default?

roti11:06:01

for some reason they are not interpreted

thedavidmeister12:06:26

probably (.fromCharCode js/String 169)

dnolen13:06:01

@roti seeing collection in the debugger - Chrome + cljs-devtools

dnolen13:06:51

fwiw I’ve personally found that for a surprising amount of form validation via spec you don’t need anything but the path

dnolen13:06:24

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

roti13:06:33

@dnolen thanks, it seems I was missing the "enable custom formatters" option in chrome

kwladyka15:06:23

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

dnolen15:06:58

you need a dep on test.check, then you can require the spec testing stuff

kwladyka16:06:18

What about [cljs.spec.gen.alpha :as gen] vs [clojure.test.check.generators :as gen] ?

gfredericks20:06:50

you can probably start with the spec version

kwladyka21:06:45

But what is the difference?

gfredericks21:06:16

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

kwladyka21:06:07

ok, it sound like cljs.spec is wrapper of test.check without additional value. Just to make it consistent for the future changes.

kwladyka21:06:15

Am I right?

gfredericks21:06:20

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

gfredericks21:06:31

but it's definitely a wrapper, yes

Desmond16:06:42

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?

Desmond16:06:58

figured it out. I needed to close the app in the browser and reopen it.

Desmond16:06:11

why is that? do i need to do something to auto-update?

kwladyka16:06:09

Do you use multimethod?

bhauman16:06:29

@captaingrover it depends on your setup

cjsauer16:06:21

>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

🍺 4
cjsauer16:06:05

You normally only need the last failing spec in the path to display a proper error message

cjsauer16:06:52

The reagent component then just takes in the s/explain-data output

👍 4
dnolen16:06:57

@cjsauer yep, exactly 🙂

Mickey J Winters21:06:34

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?

Mickey J Winters21:06:01

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

theeternalpulse21:06:00

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

bhauman21:06:05

@theeternalpulse so you aren't requiring the library in the (ns declaration?

theeternalpulse21:06:55

no, I'm basically trying to inline them

theeternalpulse21:06:24

so from myns.core :as a and a/something I want to just use myns.core/something

theeternalpulse21:06:34

that causes issues

mfikes22:06:43

@theeternalpulse Hrm. In that case a/something and myns.core/something should resolve to the same var.

theeternalpulse22:06:17

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

thheller22:06:13

are you trying to "cheat" a circular dependency? if you don't have a require then it is not valid

theeternalpulse22:06:59

you know what...

theeternalpulse22:06:06

actually I don't think I am, let me trace the references

thheller22:06:55

you will need the require regardless. why do you not just add it?

theeternalpulse22:06:58

I think my plan of dynamically building these with a macro won't work

theeternalpulse22:06:01

but that was my intent

theeternalpulse22:06:25

since the functions I'm referencing share common namespace roots and names