Fork me on GitHub
#shadow-cljs
<
2019-01-28
>
aisamu13:01:44

Hi! check is giving me a warning that I'm not sure how to address:

helpers.cljs:
101:     if (isa? (type p) clojure.lang.MapEntry)
------ WARNING #56 -------------------------------------------------------------
 File: .........../helpers.cljs:101:24
 Property lang never defined on clojure

thheller13:01:17

@aisamu that should be cljs.core/MapEntry. clojure.lang.MapEntry does not exist in CLJS

thheller13:01:11

better yet use (map-entry? p)

👍 5
thheller14:01:59

does that not produce a warning during normal compilation?

thheller14:01:01

wow indeed it produces no warning

thheller14:01:11

thats a bug I'd say

aisamu14:01:36

Oh, thanks a lot!

yuhan14:01:09

What's the simplest way to get my clojurescript app to read some text from a file and display it on the web page?

idiomancy14:01:49

is shadow cljs a figwheel-like autoreloading situation for browser apps?

yuhan14:01:45

Seems like a really basic task but I've been struggling with it for the past hour - maybe there's some fundamental concept that I'm not understanding ?

yuhan14:01:43

I have a Clojure library that processes inputs and outputs images and text files, trying to get the simplest possible thing together with Clojurescript for a browser-based dashboard to the functions

yuhan14:01:54

enter something in a text field, and the backend runs and shows the generated image and text from the clj script on the browser page

idiomancy14:01:13

@qythium clojure library? dumb question maybe, but its built for clojure script right?

yuhan14:01:42

Yes, as far as I understand the usual model is to have a cljs frontend which somehow interfaces with a clj backend

idiomancy14:01:39

intersting, so its a client/server combo?

thheller15:01:06

@idiomancy shadow-cljs does far more than figwheel. but yes for browser builds it does offer the same features that figwheel does including life reload and css reload

idiomancy15:01:32

okay, outstanding

thheller16:01:07

@qythium that is not an easy question to answer. you'll need a HTTP server. the client would send a POST request to the server which would then reply with the results. gets a bit trickier with images since the browser can't send a POST request for images. sounds really basic but really isn't. 🙂

yuhan16:01:08

With images at least I can have a [:img {:src ...}] tag and have the clj code write directly to the source location.. is that a completely wrong way of going about things?

yuhan16:01:32

and why does there seem to be no equivalent way of displaying text from a source file?

thheller16:01:32

get the notion of source file out of your head 🙂

thheller16:01:43

in a web context you don't want browser randomly accessing your files 🙂

thheller16:01:03

so yeah you can simply serve some text if that is all you want

thheller16:01:18

[:iframe {:src ...}] would do the same as the :img above

thheller16:01:30

but that is rarely the solution you want

thheller16:01:02

depends on your app of course but for text sending a XHR is generally preferred

yuhan16:01:28

oh.. alright

yuhan16:01:40

sorry, I'm really not experienced at all in the web dev side of things

yuhan16:01:22

is there a minimal example of a client/server app with that sort of communication that I can look at?

thheller16:01:43

pretty much all examples that have some kind of server code

yuhan16:01:52

hmm, I'll go and look around again

yuhan16:01:32

I assume you meant the Compojure / Ring libraries which do the message handling?

thheller16:01:26

any kind of server will do. I would use fulcro/pathom but that is probably major overkill for what you want

thheller16:01:53

not sure if there are any reagent/re-frame examples with server side code

thheller16:01:02

there should be I just don't know any

yuhan16:01:04

I find that most of the tutorials and examples out there seem to assume a full working knowledge of the javascript ecosystem and web architecture, can be pretty overwhelming 😕

thheller16:01:19

lots of moving parts but yeah the "getting started" experience overall is still pretty bad for clojure

yuhan16:01:41

I tried Luminus some time ago and it seemed really overkill for what I had in mind, there were so many different interconnected parts spread over many files - is that really the sort of minimal setup needed?

thheller17:01:15

oh no that is really really far from minimal

yuhan17:01:18

Ah, thanks for all the pointers! I'll try working my way up from there 🙂

thheller17:01:13

I just pushed [email protected]. One thing I tried to tweak is how warnings are handled in the console. So if you have lots of warnings in libraries you don't control they should be less annoying now.

thheller17:01:33

please try it and let me know if you have any ideas how to improve it further

👍 15
wilkerlucio18:01:59

@thheller just tried 2.7.18, but getting this:

------ ERROR -------------------------------------------------------------------
 File: jar:file:/Users/wilker.lucio/.m2/repository/org/clojure/clojurescript/1.10.439/clojurescript-1.10.439.jar!/cljs/spec/gen/alpha.cljs:35:3
--------------------------------------------------------------------------------
  32 |   (apply @quick-check-ref args))
  33 |
  34 | (def ^:private for-all*-ref
  35 |   (dynaload 'clojure.test.check.properties/for-all*))
---------^-----------------------------------------------------------------
StringIndexOutOfBoundsException: String index out of range: -1
	java.lang.String.substring (String.java:1931)
	clojure.core/subs (core.clj:4986)
	clojure.core/subs (core.clj:4981)

wilkerlucio18:01:11

(I didn't had this in 2.7.15, trying versions in the middle to see if I can find where it stopped working

wilkerlucio18:01:35

2.7.17 works fine, 2.7.18 doesn't compile

thheller20:01:17

what the heck

thheller20:01:31

thanks I'll fix it

thheller20:01:35

hmm weird. I do not get that error when compiling that namespace

hoopes20:01:16

sorry to +1 that, but i got it as well

thheller20:01:01

do you have the rest of the stacktrace or does it cut off there?

wilkerlucio20:01:16

@thheller maybe you have to require spec?

thheller20:01:37

+ the test.check stuff

thheller20:01:33

ok its clear where the error happens. just not sure why I can't reproduce it

thheller20:01:35

@wilkerlucio @hoopes should be fixed in 2.7.19. thanks for the report.

thheller20:01:01

still no clue why it doesn't happen for me though

wilkerlucio20:01:41

maybe some weird dep we have

hoopes20:01:44

checking now

wilkerlucio20:01:49

checking here too

thheller20:01:09

I could reproduce the error manually. just no idea why it didnt' happen when compiling those files

wilkerlucio20:01:14

I noticed something, in the past I had some highlight.js warnings and they used to came in yellow color, now they are white, not sure if was intentional, but other than that the compilation is good now! thanks man!

hoopes20:01:39

yeah, it compiled - i got more warnings on this run, but no giant error

thheller20:01:44

that is intentional. warnings you can't "fix" should be de-emphasized now

hoopes20:01:46

thanks very much!

wilkerlucio20:01:58

------ WARNING #1 - :undeclared-var --------------------------------------------
 Resource: common_core/schema.cljc:121:32
 Use of undeclared Var common-core.schema/clojure
--------------------------------------------------------------------------------
and a lot of those now ^^^ 😛

thheller20:01:58

so warnings in files you don't control only show with source excerpts once

thheller20:01:28

those may be actual real errors

wilkerlucio20:01:51

probably, this is an internal lib but most people don't try it with cljs, so I have to go there an fix it

thheller20:01:04

hmm how many warnings do you have? 🙂

wilkerlucio20:01:03

real ones seem 6

thheller20:01:38

can you check what it warns about? might be some clojure.lang.... symbol

hoopes20:01:03

------ WARNING #5 - :undeclared-var --------------------------------------------
 Resource: bide/core.cljs:176:36
 Use of undeclared Var bide.core/EventType
--------------------------------------------------------------------------------

thheller20:01:06

it didn't warn about clojure.lang.MapEntry which I wanted to fix

wilkerlucio20:01:07

------ WARNING #1 - :undeclared-var --------------------------------------------
 Resource: cljs_time/internal/parse.cljs:139:27
 Use of undeclared Var cljs-time.internal.parse/Interval
--------------------------------------------------------------------------------

------ WARNING #2 - :undeclared-var --------------------------------------------
 Resource: cljs_time/internal/parse.cljs:340:31
 Use of undeclared Var cljs-time.internal.parse/Interval
--------------------------------------------------------------------------------

------ WARNING #3 - :undeclared-var --------------------------------------------
 Resource: cljs_time/coerce.cljs:29:18
 Use of undeclared Var cljs-time.coerce/UtcDateTime
--------------------------------------------------------------------------------

------ WARNING #4 - :undeclared-var --------------------------------------------
 Resource: common_core/schema.cljc:121:32
 Use of undeclared Var common-core.schema/clojure
--------------------------------------------------------------------------------

------ WARNING #5 - :undeclared-var --------------------------------------------
 Resource: common_core/schema.cljc:122:32
 Use of undeclared Var common-core.schema/clojure
--------------------------------------------------------------------------------

------ WARNING #6 - :undeclared-var --------------------------------------------
 Resource: pushy/core.cljs:88:39
 Use of undeclared Var pushy.core/EventType
--------------------------------------------------------------------------------

hoopes20:01:36

which then became a runtime error in the app...

hoopes20:01:44

ReferenceError: EventType is not defined

thheller20:01:58

ah hehe crap.

thheller20:01:07

I know why that one happens ...

hoopes20:01:55

i got the same first three as @wilkerlucio too - cljs-time warnings

thheller20:01:30

I'll add those to the test build I guess 🙂

thheller21:01:29

ok those warnings are fix. apart from the common-core.schema/clojure. Those are probably some invalid clojure classes like clojure.lang.MapEntry was so the warnings are probably legit

hoopes21:01:02

by fixed, do you mean 2.7.20? (sorry, not sure what you mean by "fixed")

thheller21:01:05

should be fixed in 2.7.20

wilkerlucio21:01:48

@hoopes I also found that same runtime error you described, is that fixed as well @thheller?

thheller21:01:58

the cljs.spec.alpha.gen should be fixed

wilkerlucio21:01:38

awesome, thanks

thheller21:01:53

@wilkerlucio if you get a chance please check what your internal lib uses. good chance the warnings are actually legit but would like confirmation.

thheller21:01:18

I'd like to add something to CI that catches things like that but not sure how

thheller21:01:46

all my builds went through without error or warnings 😞

wilkerlucio21:01:20

I'm pretty sure they are legit 🙂

wilkerlucio21:01:37

like I told you, this is a cljc file, but 90% of the people only try it in clj

wilkerlucio21:01:45

I keep fixing things there

thheller21:01:57

yeah but the bidi and pushy weren't so would be nice to catch those issues in CI

wilkerlucio21:01:13

let me do a quick check here

wilkerlucio21:01:23

actually, this is what I found in the line looking at the sources:

wilkerlucio21:01:25

clojure.lang.IPersistentVector
                               clojure.lang.IPersistentSet

thheller21:01:29

maybe I'll just add top10 most used CLJS libs and include their main namespaces

wilkerlucio21:01:37

are those supposed to be available on cljs? I'm not sure

thheller21:01:38

ok those are legit warnings then

thheller21:01:51

no, those are java interfaces for CLJ only

wilkerlucio21:01:59

ok, makes sense then

thheller21:01:14

would be cljs.core/PersistentVector and Set in CLJS

thheller21:01:48

those did not cause errors at runtime?

thheller21:01:07

blank use of clojure.lang.MapEntry caused runtime errors

thheller21:01:26

maybe the code isn't used in CLJS