Fork me on GitHub
#clojurescript
<
2018-04-04
>
aleksandr05:04:55

Hello everyone! I write my own library, it is a reagent component. I use re-com and I want to catch errors from It, but I can`t. Can you explain how make this work? That is what I wrote https://pastebin.com/PfEipjLB As you see I want catch an error and return reagent element with info about the error

zaphodious05:04:16

From the look of it (and not knowing much about reagent specifically), it seems that there's nothing to throw an error there. That declaration just creates a data structure. You'll have to write a try/catch around the code that actually uses the structure.

aleksandr05:04:07

What can you advice how can I work with re-com errors?

zaphodious05:04:29

What's the error you're getting?

aleksandr05:04:36

When i pass invalid argument to the v-box component for example Error rendering component (in pozn_adaptive.views.main.main_panel > swipe.views.slider_component > re_com.box.v_box) --- Validation failed for argument ':height' in component 'v-box': Expected 'string'. Got '900' at pozn_adaptive.views.main.main_panel > swipe.views.slider_component > re_com.box.v_box --- Uncaught Error: Assert failed: (validate-args-macro v-box-args-desc args "v-box") ...

zaphodious05:04:17

It looks like you've got a type error. Try wrapping "height" in (str)

zaphodious05:04:03

{:height (str height)}

aleksandr05:04:27

Okay! I will look at this

gregg05:04:39

Also, it's best to be specific with the units, so I would recommend passing "900px" to :height rather than "900"

aleksandr05:04:44

Yes, you are right

gregg05:04:02

Regarding re-com errors, the message above is re-com trying to provide a "helpful" message when it gets an argument it doesn't accept

gregg05:04:50

So there's no need to provide try/catch around re-com components

aleksandr05:04:28

I agree about specific units. But why I was confused about errors is that If an user pass to the component an incorrect string, for example "100ggggg" How i can catch It? I can write my own validator, but why would I do it if re-com have this validators already?

aleksandr05:04:35

If I understood you correct you want to say that re-com just provide me info about incorrect arguments and not throw errors?

aleksandr05:04:49

Maybe I should rewrite a console.error function? And insert throwing error in it?

gregg05:04:24

Each component uses a {:pre ...} for validation

gregg05:04:40

In the case of v-box, here is the line that is throwing: https://github.com/Day8/re-com/blob/master/src/re_com/box.cljs#L300

gregg05:04:11

It's only meant to help stop developers from passing invalid args

gregg05:04:40

It will NOT cause an exception in your prod builds (it's stubbed out), but you will get unexpected behaviour

aleksandr05:04:00

Ok, thank you!

gregg06:04:10

No probs...the best place for re-com discussion is in the #re-frame channel

codonovan15:04:29

When using :npm-deps how do I require a modules sub-package? How do I require devtools in this example Using ES6

import { Controller, Module } from 'cerebral'
import Devtools from 'cerebral/devtools'
cljs
(ns app.core
  (:require
    ;; [cerebral/devtools]
    ;; [cerebral.devtools]
    [cerebral]))

justinlee15:04:16

@codonovan in shadow-cljs you can use string includes (:require "cerebral/devtools"). I don’t know if that works with npm-deps, but maybe give it a shot?

codonovan15:04:57

@lee.justin.m Was not aware of shadow-cljs. Will have a look see. Thanks

justinlee15:04:24

these are just my thoughts--not official

andrewboltachev16:04:29

Hello. I tried to use :npm-deps on ClojureScript 2.10.238 with this module ( https://github.com/Stanko/react-animate-height ) and include it into Reagent project, but with advanced opmtimization it didn't work. After few hours of debug it seemd that this line in React https://github.com/facebook/react/blob/master/packages/react/src/ReactBaseClasses.js#L26 was optimized away by Google Closure Compiler. Does that seem realistic?

juhoteperi16:04:06

It is possible, though it is not obvious why this would only happen with react-animate-height. I'm running tests with just React and no problems.

juhoteperi16:04:30

You might want to test with new Closure-compiler release (it works with current Clojurescript), it fixed one another problem: https://github.com/reagent-project/reagent/commit/35a04a612565419375bc0eab91774ac7a80aecef

esaikku16:04:36

Anyone know how I can find out what JIRA issue this attachment is part of? https://dev.clojure.org/jira/secure/attachment/17793/cljs-master-error.txt

richiardiandrea16:04:02

that's mine, don't remember the ticket, but I think it was solved.

richiardiandrea16:04:27

not sure though, will try to dig

rauh16:04:28

2543

👍 8
richiardiandrea16:04:43

nope, the error still seems to happen here

esaikku16:04:51

Great thanks! WIll check it out.

esaikku16:04:29

I'm getting the same error when trying to use aws-amplify 0.2.9 in :npm-deps.

richiardiandrea16:04:40

yes still getting the same error, it looks like the dependencies cannot be computed correctly here, no sure though

esaikku16:04:31

I don't understand how that ticket relates to the npm-deps error. I get my error when trying to build with leiningen cljsbuild.

richiardiandrea16:04:05

might be different then

richiardiandrea16:04:49

I would suggest you to reproduce it using the cli tool so that you exclude tool-specific problems

esaikku16:04:35

Which cli tool do you mean? npm or REPL?

richiardiandrea16:04:55

I have actually tried right now to put -c at the end of the command line invocation and magically it started to work:

clojure -Srepro -R:cljs-jvm -m cljs.main -O simple -t node -c ep-cloud.handlers

👍 4
esaikku16:04:43

Is there some guide on how to troubleshoot these compile/build errors using something like you did there?

esaikku16:04:58

I'm getting errors in build all the time and having a hard time troubleshooting them. Have to learn to isolate the issues somehow.

richiardiandrea16:04:22

the cljs.main feature is kinda new, I usually just enable :verbose and see what happens. In case of :npm-deps there is really little you can do, probably just report it here.

esaikku16:04:50

Do I put :verbose in the build parameters?

richiardiandrea16:04:10

yes or --verbose to the command above

👍 4
richiardiandrea16:04:55

I have actually tried right now to put -c at the end of the command line invocation and magically it started to work:

clojure -Srepro -R:cljs-jvm -m cljs.main -O simple -t node -c ep-cloud.handlers

👍 4
justinlee18:04:29

why do i sometimes get stack traces to things that look autogenerated? i have an error in a partial function application and part of the stack trace looks like

at G__29817__1 (core.cljs:4260)
    at G__29817 (core.cljs:4263)
. those two lines point to the implementation of partial. i just don’t quite understand where those G__29817 symbols come from

thheller18:04:21

those are gensym symbols. used in macros mostly when you need a "hygenic" variable name

justinlee18:04:39

@thheller what’s confusing is that there don’t appear to be any macros in the definition of partial

thheller18:04:44

yeah, but partial is a defn with multiple arities. those get unrolled. G__29817__1 is the function with one arg basically.

thheller18:04:21

might be that source maps are missing some info here which could be improved maybe

justinlee18:04:17

anyway thanks for the explanation. i forgot that defn itself is a macro

Shantanu Kumar18:04:37

Does any of the alternate CLJS runtimes (Lumo, Planck etc.) consider “reified vars” a priority? (I’m just curious about design considerations.)

mfikes18:04:52

@kumarshantanu Lumo and Planck simply act as shells to host self-hosted ClojureScript, from that perspective.

Shantanu Kumar18:04:32

Thanks for the pointer!

mattly19:04:14

when using npm-deps, how do I do the equivalent of import { foo } from "bar"

mattly19:04:03

I’ve tried (ns my-ns (:require bar)) (bar/foo), (ns my-ns (:require [bar :refer [foo]])) (foo) and whatnot

mattly19:04:09

and they all come up null

sveri19:04:04

Hi, I am using the advanced compilation of clojurescript with the infer-externsoption set to true. Now I get warnings like these:

Apr 04, 2018 6:52:47 PM com.google.javascript.jscomp.LoggerErrorManager println
WARNUNG: target/cljsbuild-compiler-2/inferred_externs.js:20: WARNING - name goog is not defined in the externs.
goog.fx;
^^^^
When I look into the resulting inferred_externs.js file I can see goog.fx added. Do I have to do something now or can I just ignore the warning?

dnolen19:04:59

please make something minimal against master and report if that problem still exists

dnolen19:04:09

I’ve been touching up externs inference stuff for the next release

sveri19:04:48

@dnolen Ok, I will ping you when I got it

dnolen19:04:04

@mattly if those are exported by default exports you made need access differently see https://dev.clojure.org/jira/browse/CLJS-2376

sveri19:04:56

@dnolen there it is: https://github.com/sveri/cljsinferrepro the compilation still shows one error like this, you can see that in the readme. I hope that is sufficient.

sveri19:04:08

@dnolen I missed the hint I should do it against master. How can I refer the master build in leiningen?

dnolen19:04:39

don’t use leiningen

dnolen19:04:45

use clj for this

dnolen19:04:03

and don’t link outside of the ticket

zaphodious20:04:17

For my clojurescript :advanced compiles, I seem to be consistently hitting 300k on the low end with a brand-new lein chestnut setup. That seems... oddly big? Is there a way to get that down?

dnolen20:04:17

what is it post gzip?

dnolen20:04:26

that’s all you should really care about

zaphodious20:04:13

gzipped with 7z is 78k. That seems better 🙂

sveri20:04:45

Is there a way to add infer-externs to the clj command?

dnolen20:04:37

-co can take a EDN file of build options

dnolen20:04:49

clj -m cljs.main -co build.edn -c some.ns

dnolen20:04:11

or if :main is in build.edn

dnolen20:04:20

clj -m cljs.main -co build.edn -c

sveri20:04:32

Thanks, I will try that

sveri20:04:38

Hm, using clj I cannot reproduce it with the latest stable version nor with the latest master version.

sveri20:04:52

But there is a difference in the generated inferred_externs. The stable version contains entries like: goog.isArrayLike; var goog;... while the master version does not and contains a few lines less. Maybe somehow I am not printing warnings during compilation?

akiroz21:04:27

Not sure if this is the right place to ask but I'm doing a write-up on cli scripting with cljs (lumo) and wonder if anyone wants to help me proof-read it before I publish...

akiroz21:04:47

Guess I'll leave a link to my draft here in case anyone's interested: https://medium.com/@akiroz/command-line-scripting-with-clojurescript-5e5567367713

richiardiandrea22:04:29

the require for fs can be simplified to

'[fs :refer [writeFileSync]]

richiardiandrea22:04:10

also this is only partially true at the moment: > Unfortunately, there isn’t an easy way to manage dependencies on the Clojure side just yet so for now we are stuck with manually installing JARs to your local maven repo.

richiardiandrea22:04:51

and you can use npm modules directly

richiardiandrea22:04:23

so you can use cljs packages published on npm by just adding them to your package.json

richiardiandrea22:04:41

at the moment no many on there, see the list

richiardiandrea22:04:55

good job overall 😄

akiroz22:04:40

Awesome, thanks for the feedback! 🙂

cljs 4
athomasoriginal18:04:35

Great article! Who is the audience? I feel it could be clojurists or JS developers, which is great 🙂 Just a few notes: > As you can see, the require function can now act like its JS counterpart and pull in JS modules as you would with the following code: For the above, perhaps illustrate the "counterpart" you are referring to. I mention this because it might gain a larger JS audience if they feel like you are speaking to them too. > Integrating with NPM This section is a little unclear to me. Does request not have to be npm installed? If yes, maybe show the steps? The concern is that a lot gets lost if steps are removed and then people become disgruntled and blame it on the technology 😞

akiroz02:04:58

> Who is the audience? A friend of mine who's getting started in the cljs world 😉 I'm not exactly sure how it ended up being an article half-way through.... > If yes, maybe show the steps? Got it, will make some edits today~

richiardiandrea22:04:14

@akiroz there is also a #lumo chan but here should be fine as well

richiardiandrea22:04:21

I will have a look

zaphodious23:04:11

I'm trying to use Google's Workbox. With cljs-oops, I call (oget js/self "workbox" "precaching"). Error! Great. I spent half an hour trying to understand why, before trying. (.-precaching (oget js/self "workbox")), which magically functions.

darwin23:04:36

@achythlook hm, maybe look at generated javascript and compare both cases?

darwin23:04:36

in repl you can use a trick with anon function and .toString on it, e.g. (.toString (fn [] (oget o "prop"))

zaphodious23:04:23

Welp, one is wrapping the call to "precaching" in a bunch of oops calls, and the other is straight dot access after the oops calls.

zaphodious23:04:16

Which means... I'll need externs? Or is there another way to sidestep them?