Fork me on GitHub
#clojurescript
<
2018-04-24
>
darwin00:04:33

assuming you are using Figwheel or some other hot reloading scheme those two can bring you a bit closer to “classic” IDE-centric debugging experience

neupsh00:04:23

I realized that i had not included dirac as dependency on my project.. and definitely not in nrepl as middleware. This may be the reason for the issue i mentioned above

neupsh00:04:32

I will go through them and try again

darwin00:04:14

no, you were just missing the REPL feature of Dirac, but the debugging part should work independently

darwin00:04:49

unfortunately there are some bugs in source-mapping support in DevTools and some more complex clojurescript-generated javascript code causes confusion in DevTools debugger UI, like this https://github.com/binaryage/dirac/issues/53, also generated code which tends to produce long lines with a lot of javascript statements tends to hit DevTools debugger limits and UX issues (e.g. placing breakpoints to proper locations)

javi10:04:22

is there a cljs pair programming channel?

burke12:04:23

I'm using some foreign-libs (bundled by webpack) in my cljs project. Is there any way to let the compiler do tree-shaking/dead code elimination on the foreign js? For example, I'm using only 4 components from materialize-css and don't need the code of the other components.

fbielejec12:04:06

@burke shadow-cljs does DCE on npm modules. If that's not a option you could just bundle what you need, for example create a webpack project with an entry point index.js:

import { foo , bar } from "foobar-lib";
var exports = {};
exports.foo = foo;
exports.bar = bar;
module.exports = export;
then use webpack to get a production build e.g. bundle.js containing just what you need. Than in :foreign-libs:
:foreign-libs [{:file "libs/bundle.js"
                 :provides ["foobar-lib"]}]

👍 4
burke13:04:24

@fbielejec I think I will try shadow-cljs. Tweaking the webpack entry point seems too manually.

thheller13:04:40

@burke @fbielejec shadow-cljs does not do much DCE of node_modules. only :simple optimizations are applied to npm sources. you'll still get better result that webpack probably but it mostly depends on what you require.

burke14:04:24

I hope that It'll be worth the effort. My project is a mix of cljsjs and webpack-bundle(everything that was not available in cljsjs). Unfortunately the cljsjs packages I used aren't in shadow-cljsjs 😫

pesterhazy14:04:05

@burke what do you hope to gain from this? bundle size reduction?

burke14:04:18

@pesterhazy yes I think so.

pesterhazy14:04:55

personally I'm thinking that running non-closure-aware js libs through GCC is a bit risky. I'd rather have slightly larger bundles and things guaranteed to work (as in the "double bundle" method)

burke14:04:23

I thought that this is one of the main features of the gcc. I dont know.. is it okay to have cljs app of >2mb?

pez14:04:31

How do I eval code in a different namespace w/o switching to that namespace?

pesterhazy14:04:07

@burke is that post-gzip? it's the size after gzip that counts

pesterhazy14:04:15

I'm not arguing against using gcc for your cljs deps, only raising a question about applying it to foreign libs

burke14:04:22

@pesterhazy its pre-gzip. Download time is okay because of gzip compression. But it feels like wasting memory and processing time if the js-interpreter on the client has to interpret 30% that isnt needed in the app. I thought that gcc is able to optimize it, but maybe you're right; better have a working app than a small app

thheller14:04:27

stop talking about GCC as if it only did one thing. running things through GCC can mean many things. 🙂

thheller14:04:20

@burke which cljsjs packages in particular are you using?

burke14:04:57

codemirror, quill, katex, chartjs. I've added the necessary namespaces and use your shadow-cljsjs. So the compiler is happy now

thheller14:04:46

if you control the namespaces using those you can directly use the npm packages via (:require ["codemirror" :as cm]) as well. no need to go through the cljsjs wrappers

juhoteperi14:04:14

Some Cljsjs packages (like Codemirror) also provide npm-style name (`codemirror`) so you could update your app or libs to use that name, so it will work with both shadow-cljs/cljs npm-deps/cljsjs

juhoteperi14:04:40

And it should be easy to update other cljsjs packages to also provide npm-style names

burke14:04:42

Its a dependency that is also one of my projects, but I dont want to change every project when I'm not sure if this switch to shadow-cljs will be successful. @U061V0GG2 I will try this, good to know.

juhoteperi14:04:41

@burke ClojureScript / Closure JS Module support can allow transpilation of CJS/ES6 modules to Closure modules which allows Closure optimizations. This is what ClojureScript uses when using Node Modules. But as mentioned by @pesterhazy, this can have problems (not many npm packages work yet) and the feature is experimental.

juhoteperi14:04:41

Cljsjs packages could also use Closure module transpilation but none currently do.

pez15:04:03

In clojure I seem to be able to do this:

(binding [*ns* (the-ns 'foo.bar)] (eval '(foo)))
But clojurescript does not like neither the-ns, nor eval.

orestis15:04:50

I remember some discussion about eval in ClojureScript, I think Planck recently added it, but it’s not an option for the non-self-hosted version…

mfikes15:04:23

You can mess with eval in ClojureScript but it ends up needing self-hosted ClojureScript to do it. This might be of interest: https://gist.github.com/mfikes/66a120e18b75b6f4a3ecd0db8a976d84

pez15:04:37

@mfikes, that at least gave me a pointer to find-ns. 😃

pez15:04:53

Executing code in another namespace like that is not possible without eval?

pez15:04:29

Self-hosted seems to be unavailable as an option for my use case.

thheller15:04:00

what is the go-to react component when I need a data table (preferably with collapsible rows) these days?

pez15:04:24

Yes, that looks very nice. Some of the examples breaks and some get a lot of complaints in the console, but that could be the demo that is out of sync, I guess. Most of it seems to work.

jthibaudeau15:04:26

Hi guys, I am wondering what is the idiomatic way of updating a js array within an js object? I have been reading that I should use goog.object/get and goog.object/set for js objects and use aset and aget for js arrays. For example:

#js{:k1 #js [1 2 3] :k2 "v2"}
I want to update index 0 of :k1 I can do (aset obj "k1" 0 "new val") but that does not seem to fit with not using aset on objects.

pez16:04:39

@jamesthibaudeau I think I would do (aset (.-k1 obj) 0 "new val") or maybe (-> (.-k1 obj) (aset 0 “new val”))

jthibaudeau17:04:29

I want to get away from the .- way to avoid unexpected symbol munging in advanced compile, but it does makes sense to use goog.object/get to get the array and aset to change a value in the array.

pez19:04:07

I don’t think I’ve ever seen symbols I use like that munged, but that is good to know!

mfikes16:04:28

In this problem, is the original object actually meant to be the following?

#js {:k1 #js [1 2 3] :k2 "v2"}

👍 4
pez16:04:39

Well, at least it actually works then, @mfikes 😃

mfikes16:04:58

We can probably assume so as "js array" was used

pesterhazy16:04:13

@thheller I reviewed the different options a while ago and didn't come up with a clear winner

pesterhazy16:04:46

react-virtualized supports very large tables but isn't a full datatable solution

thheller16:04:08

react-table seems to work well for what I want

thheller16:04:03

ah, just used what came up in google. that list might be useful though. thx.

jthibaudeau16:04:44

@mfikes yeah that was what I meant sorry

mfikes17:04:11

It’s too bad there is no goog.object/setValueByKeys, but I suppose you can compose a goog.object/getValueByKeys with a goog.object/set to mutate something deeply nested in a JavaScript object.

justinlee18:04:28

disregard. it occurs to me I should be able to accomplish almost the same thing with promesa/alet

montanonic19:04:26

I required a nodejs library, (require '["crypto" :as crypto]), and now I want to be able to print all of the functions within this namespace. How do I get them? Within the repl, stuff like (ns-publics crypto) are returning {}.

montanonic19:04:44

Using lumo repl and clojurescript 1.9.x

anmonteiro20:04:03

@montanonic

cljs.user=> (require 'crypto '[goog.object :as gobj])

cljs.user=> (filter (comp fn? (fn [x] (gobj/get crypto x))) (js/Object.keys crypto))

anmonteiro20:04:17

one way of doing it

montanonic20:04:37

Okay, interesting. Thank you. I'll play with that.

montanonic20:04:49

Is this more work because it's a foreign import?

montanonic20:04:05

I'm guessing yes.

anmonteiro20:04:58

crypto is a Node.js module, not a CLJS namespace

👍 4
alice20:04:28

This is very strange... I can't :require any namespaces I've created

clojure.lang.ExceptionInfo: voke.state.events does not exist
Errors in the figwheel repl, I know for a fact the namespace exists and I've tried making other namespaces too

timo09:04:42

@alice since weeks I am trying to figure out this exact same problem. I am totally lost here. Did you find anything?

danielglauser20:04:21

One simple thing to check is that your ns declarations match your filesystem paths. Not that I’ve ever made that mistake…I ah…know other people who have.

4
alice20:04:35

They definitely do

joelsanchez20:04:29

that's a jvm exception and your files are cljs

4
alice20:04:39

0.0!? good point

alice20:04:04

The repl itself is definitely cljs, though? :thinking_face:

joelsanchez20:04:28

eval (class 'map) for example

joelsanchez20:04:34

in cljs "class" is not a thing

alice20:04:47

voke.core> (class 'map)
----  Compiler Warning on   <cljs form>   line:1  column:2  ----

  Use of undeclared Var voke.core/class

  1  (class 'map)
      ^--- 

----  Compiler Warning  ----
#object[TypeError TypeError: voke.core.class$ is undefined]
nil

alice20:04:51

Looks right

alice20:04:57

So why tf am i getting jvm exceptions??

joelsanchez21:04:57

how are you requiring?

alice21:04:31

(ns voke.core (:require [voke.state.events])

joelsanchez21:04:04

have you tried requiring from the repl?

joelsanchez21:04:10

(require 'voke.state.events)

alice21:04:22

Same jvm exception

joelsanchez21:04:57

something weird I notice is that I can't get that error message in any environment I've tried

alice21:04:19

The rest of the error message comes back to piggieback and figwheel

alice21:04:22

I'll paste the whole thing

alice21:04:31

clojure.lang.ExceptionInfo: voke.state.events does not exist
 at clojure.core$ex_info.invokeStatic (core.clj:4739)
    clojure.core$ex_info.invoke (core.clj:4739)
    cljs.repl$ns__GT_input.invokeStatic (repl.cljc:202)
    cljs.repl$ns__GT_input.invoke (repl.cljc:198)
    cljs.repl$load_namespace.invokeStatic (repl.cljc:217)
    cljs.repl$load_namespace.invoke (repl.cljc:208)
    cljs.repl$load_dependencies.invokeStatic (repl.cljc:245)
    cljs.repl$load_dependencies.invoke (repl.cljc:241)
    cljs.repl$evaluate_form.invokeStatic (repl.cljc:547)
    cljs.repl$evaluate_form.invoke (repl.cljc:484)
    cljs.repl$eval_cljs.invokeStatic (repl.cljc:672)
    cljs.repl$eval_cljs.invoke (repl.cljc:665)
    clojure.lang.Var.invoke (Var.java:396)
    figwheel_sidecar.repl$catch_warnings_and_exceptions_eval_cljs.invokeStatic (repl.clj:286)
    figwheel_sidecar.repl$catch_warnings_and_exceptions_eval_cljs.invoke (repl.clj:278)
    clojure.lang.Var.invoke (Var.java:396)
    cljs.repl$repl_STAR_$read_eval_print__6536.invoke (repl.cljc:957)
    cljs.repl$repl_STAR_$fn__6542$fn__6551.invoke (repl.cljc:998)
    cljs.repl$repl_STAR_$fn__6542.invoke (repl.cljc:997)
    cljs.compiler$with_core_cljs.invokeStatic (compiler.cljc:1285)
    cljs.compiler$with_core_cljs.invoke (compiler.cljc:1274)
    cljs.repl$repl_STAR_.invokeStatic (repl.cljc:960)
    cljs.repl$repl_STAR_.invoke (repl.cljc:839)
    cemerick.piggieback$run_cljs_repl.invokeStatic (piggieback.clj:169)
    cemerick.piggieback$run_cljs_repl.invoke (piggieback.clj:155)
    clojure.lang.AFn.applyToHelper (AFn.java:171)
    clojure.lang.AFn.applyTo (AFn.java:144)
    clojure.core$apply.invokeStatic (core.clj:661)
    clojure.core$apply.invoke (core.clj:652)
    cemerick.piggieback$evaluate.invokeStatic (piggieback.clj:259)
    cemerick.piggieback$evaluate.invoke (piggieback.clj:255)
    clojure.lang.Var.invoke (Var.java:381)
    cemerick.piggieback$wrap_cljs_repl$fn__36179$fn__36181$fn__36182.invoke (piggieback.clj:291)
    cemerick.piggieback$enqueue$fn__36165.invoke (piggieback.clj:247)
    clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__32431.invoke (interruptible_eval.clj:190)
    clojure.lang.AFn.run (AFn.java:22)
    java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
    java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
    java.lang.Thread.run (Thread.java:748)

joelsanchez21:04:48

I have no idea, maybe put all in a public repo so that someone can give you a hand

alice21:04:06

Well shit, yeah I'll do that later tonight if I can't fix this on my own

alice21:04:14

Why do I always get the weird errors

alice21:04:54

Thanks for trying

timo09:04:50

@alice since weeks I am trying to figure out this exact same problem. I am totally lost here. Did you find anything?

joelsanchez21:04:17

everyone gets the weird errors from time to time 🙂

sova-soars-the-sora23:04:47

Could someone please explain why I see double vector brackets on some anonymous functions?

sova-soars-the-sora23:04:05

hunting for one ...

sova-soars-the-sora23:04:01

Okay, the Matchbox (cljs firebase connector) quick spin has..

sova-soars-the-sora23:04:15

`(m/listen-children root [:users :mike :friends] (fn [[event-type data]] (prn data)))`

alice23:04:26

That's argument destructuring

😀 4
alice23:04:46

[[event-type data]] means the function takes a vector argument with two members, event-type and data respectively

sova-soars-the-sora23:04:17

Cool. Makes sense. So the arity is technically one, and that one thing is a vector with 2 elements

sova-soars-the-sora23:04:32

awesome. high five

alice23:04:50

destructuring can get a lot more complicated and useful too though

alice23:04:49

One example from my code, [{:keys [filename tempfile size]} image]

alice23:04:55

I do that to get three keys from the image in one line

alice23:04:04

there's a ton you can do with it

sova-soars-the-sora23:04:28

so in that case, image is a map and you're grabbing :filename, :tempfile, and :size ?

sova-soars-the-sora23:04:07

okay, while i have your attention, do you know what the heck is going on here..

alice23:04:14

https://clojure.org/guides/destructuring Here's the corresponding bible verse to today's lesson

sova-soars-the-sora23:04:03

lol corresponding bible verse

alice23:04:35

I want to say it has something to do with spec, tbh i'm unfamiliar

sova-soars-the-sora23:04:47

cool. thanks for taking a look anyway.

sova-soars-the-sora23:04:08

just one of those things it's impossible to google for

sova-soars-the-sora23:04:19

my name is backslash colon hyphen the 3rd

alice23:04:14

If you figure out what that is let me know

sova-soars-the-sora23:04:54

when* i figure out what it is. >=)

sova-soars-the-sora23:04:49

well I found the actual code on the repo

sova-soars-the-sora23:04:20

woo, here it is! (in the reframe reg-sub code) "syntactic sugar"

timo09:04:50
replied to a thread:Thanks for trying

@alice since weeks I am trying to figure out this exact same problem. I am totally lost here. Did you find anything?