Fork me on GitHub
#clojurescript
<
2017-08-04
>
kaosko06:08:00

so how do I debug a (reagent-based) site that spits out a js error in production but works perfectly in development mode? (app.js:1352 Uncaught TypeError: b.Xh is not a function)

lukas.rychtecky07:08:32

@kaosko try to set :optimizations :whitespace to :compiler https://github.com/emezeske/lein-cljsbuild#basic-configuration

kaosko07:08:45

thanks @lukas.rychtecky , looks like it's a missing extern causing it

raspasov07:08:38

question for everyone: I know this has been solved in many ways (elegant or not), and there’s paid solutions like Mixpanel, etc, etc but it’s probably worth asking: has anyone come up with an elegant, hassle-free approach to record analytics automagically from a mostly pure ClojureScript React app? (browser or React Native Cljs should not make much of a difference)

raspasov07:08:18

I would like to record as much data as possible without having to diff the whole state at every transition/transaction/swap! etc

raspasov07:08:59

I might be asking for impossible magic 🙂 I have done the diff-ing way and it created some performance problems (not critical but noticeable)

raspasov07:08:13

the “efficient” way is to simply sprinkle event calls everywhere… which always ends up a hassle to maintain and you always miss something important

raspasov07:08:20

basically I’m looking for a library-ish type thing that would do it “well”… aka I’m trying to avoid re-inventing the wheel if it exists already

kaosko08:08:41

@raspasov - well I'd think re-frame's interceptor concept would be as close to automagical as you can get - see for example how they do undo: https://github.com/Day8/re-frame-undo

pawel.kapala13:08:48

What is the best way to create externs for something like react-bootstrap-typeahead? I was looking for some modules at , but it seems rather complicated. Could it be generated, or do I need to have some knowledge about the module I write externs for? Thanks!

lukas.rychtecky13:08:46

@pawel.kapala not to use react-bootstrap-typeahead 😄 If you use Reagent, you can try to replace typeahead from Re-com.

pawel.kapala13:08:44

@lukas.rychtecky yep, I considered re-com, but as the disclaimer says it might not work properly in all browsers, so I went with support here. Thanks for the tip though!

lukas.rychtecky13:08:40

@pawel.kapala I see. I’ve tried to create externs, but I failed (none of given workflow worked) thus I’ve changed UI component to similar one with externs.

richiardiandrea13:08:32

generation depends on the lib, there should be a link to one, but in my experience you always need a manual retouch

liminal1814:08:44

I actually find the fact that there isn't an existing web assembly project for clojurescript (that I know of) to be rather surprising as many major sites are already struggling with performance issues with javascript. If elm or clojurescript could compile to web assembly and javascript it would provide a nice stop gap while letting bigger apps theoretically run more effectively. In other words if anyone is serious about clojurescript or elm taking on javascript wasm is s good strategy to have.

dnolen14:08:55

@liminal18 you realize the current major use case of WA is to port C++ games into the browser right 🙂

dnolen14:08:09

the current design is seriously deficient for anything else

curlyfry14:08:35

In JVM Clojure, I tend to put a bunch of repl convenience functions in user.clj. I would like to do the same in cljs, and have the file not be included in production builds. I'm using lein and the figwheel repl. Have you guys set up something like this?

dnolen14:08:01

@curlyfry you can use profiles + additional :source-paths to your CLJS build tool

curlyfry14:08:12

How do I make sure the functions in the file are automatically available when I start my repl?

dnolen14:08:24

@curlyfry you can have files without namespaces and they will be set to cljs.user - this should work but it’s not a heavily tested feature.

curlyfry14:08:05

@dnolen Oh, I didn't know that. Interesting, thanks!

liminal1814:08:56

@dnolen did not know, but that does make the c to wasm projects a bit more understandable. Was just thinking if a wasm version of a language could make dom updates and other things faster it would make sites written in it more desirable. Anyways good point. Keep up the good work :)

dnolen14:08:55

@liminal18 ClojureScript is a GCed language

dnolen14:08:13

you would need to reimplement GC

liminal1814:08:17

GC means garbage collected

dnolen14:08:20

and this GC would need to understand foreign pointers

dnolen14:08:34

anything outside this WA VM

dnolen14:08:47

other JS objects, DOM etc.

dnolen14:08:09

WA spec needs to be extended for GCed langs

liminal1814:08:55

Ok so basically WA is meant for games and other apps where garbage collection kicking in would cause frame rate drops etc.

dnolen14:08:29

I’ve been following this line since asm.js

dnolen14:08:41

I’ve been banging the GC drum since the very beginning with the designers

dnolen14:08:46

nothing has happened

dnolen14:08:50

I’m not holding my breath

dnolen14:08:58

my prediction was at least 5 years after initial WA spec, it’s been 2 already

liminal1814:08:02

Not to up on the ins and ous of gc so I will not comment although that does make me wonder how the haskell WA project will handle it.

dnolen14:08:08

but at this rate, it will like be 7 before there’s anything we can do

dnolen14:08:58

fwiw I found most of the attempts to port Haskell to the browser to be goofy

dnolen14:08:26

if they’re pursuing the WA line, then they’re still barking the wrong trees IMO

curlyfry14:08:19

Hmm, can't seem to get the files without namespaces feature to work. Figwheel reacts to changes in the file so it seems that it's loaded OK. I don't have access to the function in the file in the REPL though.

dnolen14:08:56

@curlyfry examine the compiled file

dnolen14:08:32

oh actually I know, it’s not going to be automatically loaded

dnolen14:08:16

you might want to see if Figwheel has a feature for that?

dnolen14:08:02

we should probably add this feature to ClojureScript

curlyfry14:08:48

@dnolen It does have that feature, but it requires a namespace! 🙂 > Figwheel will not load or reload files that haven't been required by your application. If you want to force a file to be loaded when it changes add the follwoing meta-data the namespace declaration of the file:

curlyfry14:08:08

(ns ^:figwheel-load example.core)

dnolen14:08:13

@curlyfry ah right, maybe try calling the file cljs/user.cljs and make figwheel load cljs.user ns?

curlyfry14:08:20

Yeah, it would be cool to have the same behaviour for user as in JVM clojure

dnolen14:08:45

@curlyfry agreed, I just don’t think anyone has requested it before so hasn’t been a priority

dnolen14:08:59

also we just didn’t support files w/o namespaces for years so hard to make it work

dnolen14:08:19

it should be relatively easy now

curlyfry15:08:49

Putting (ns ^:figwheel-always cljs.user) at the top of the file works for now anyways

richiardiandrea17:08:41

Has anyone any advice for cljs on AWS lambda? I tried but I am running against a couple of issues. The one is that the artifact is huge (> 20 MB, same code with JS is 9 MB). I was thinking of :advanced, did not get far but also did not try that hard. The second problem is bigger. Basically functionally the same code in CLJS fills up the lambda's memory and the lambda gets even killed 😱

qqq17:08:16

@richiardiandrea : I'm running CLJ on lambda, and it's working fine; also you can increase mem limits (which iirc, also increases cpu proportionally) if your cljs is too large

richiardiandrea17:08:15

I tried bumping to 128 - 256 - 512 - 1024, memory usage follows and peaks and AWS kills the lambda

qqq17:08:34

https://www.youtube.com/watch?v=GINI0T8FPD4 <-- was also a great talk on clojure on aws lambda

qqq17:08:53

@richiardiandrea : what does your cljs code do?

qqq17:08:04

I'm running clojure lambda fine on 512 MB lambdas

qqq17:08:14

and the JVM should be heavier than whatever node.js is doing

thheller17:08:26

@richiardiandrea how do you get a 20MB js file? how much code do you have? 🙂

richiardiandrea17:08:55

cljs is a requirement so no clj 😉

richiardiandrea17:08:03

(ns logpoc.core
  (:require [cljs.pprint :as pprint]
            [cljs-lambda.macros :refer-macros [deflambda]]
            [cljs-lambda.context :as context]
            [cljs-lambda.local :as local]))

(def bunyan (js/require "bunyan"))
(def log (.createLogger bunyan #js {:name "bunyan-lambda-cljs"}))

(deflambda ^:export bunyan-lambda-cljs [event ctx]
  (js/console.time "bunyan-lambda-cljs")

  (.info log "AWSrequestID =" (:aws-request-id ctx))
  (.info log "functionName =" (:function-name ctx))
  (.info log "invokedFunctionArn =" (:function-arn ctx))
  (.info log "remainingTimeInMillis =" (context/msecs-remaining ctx))

  (dotimes [i 1000]
    (.info log #js {:index i} "Time: now" (.toISOString (js/Date.))))

  (js/console.timeEnd "bunyan-lambda-cljs"))

thheller17:08:04

but :advanced seems like the way to go

richiardiandrea17:08:19

that's all it does

thheller17:08:29

how does that produce 20mb?

qqq17:08:47

what is bunyan ?

qqq17:08:57

doesn't closure do dead code elimination ?

richiardiandrea17:08:38

logging lib for js.., probably something not obvious is going on

richiardiandrea17:08:10

I have :optimizations :simple now

qqq17:08:39

does any of the logging make sync network calls? doing it 1000 times could blowup the exec time

richiardiandrea17:08:13

yes that is the point of my POC 😄

richiardiandrea17:08:32

funny thing is that it does not happen with straight JS

qqq17:08:54

is it possible that locally it writes to file system, but on lambda, it writes to s3 ?

qqq17:08:04

if lambdas are stateless, where is your log being written to?

richiardiandrea17:08:48

no it is writing to stdout

mengu17:08:52

hi all, i've updated my reagent to 0.8.0.beta and i get this error now: No such namespace: react, could not locate react.cljs, react.cljc, or Closure namespace "react"

mengu17:08:09

i think it started using new cljs require thing for npm packages

mengu17:08:16

but it cannot find it

mengu17:08:38

oh, let me update clojurescript as well

thheller17:08:40

@mengu did you also update the CLJS version?

mengu17:08:50

im just doing that

noisesmith17:08:58

I must say I’m amused that a logging library named “bunyan” is absurdly large

richiardiandrea17:08:13

but that is not even the problem...I am really scared about memory consumption

thheller17:08:21

@richiardiandrea cljs.pprint is pretty huge and you don’t use it. maybe you can remove that

mengu17:08:48

alright, that error is gone

mengu17:08:55

now i get React.createClass problems

mengu17:08:56

looks like re-agent also fixed that problem

qqq17:08:23

@richiardiandrea : if you don't mind, please document how you cut the size down for aws lambda; there's alot that may be useful

richiardiandrea18:08:45

I think I just need to work out the :advanced magic. I found @thheller's shadow-cljs check an awesomely amazing tool for that. Example:

------ WARNING #45 -------------------------------------------------------------
 File: ~/.m2/repository/funcool/promesa/1.6.0/promesa-1.6.0.jar!/promesa/impl/promise.cljc:162:20
--------------------------------------------------------------------------------
 158 |             p)))
 159 | 
 160 | (defn rejected
 161 |   [v]
 162 |   #?(:cljs (.reject Promise v)
--------------------------^-----------------------------------------------------
 Property reject never defined on Promise
--------------------------------------------------------------------------------
 163 |      :clj (let [p (CompletableFuture.)]
 164 |             (.completeExceptionally p v)
 165 |             p)))
 166 | 
 167 | #?(:clj
--------------------------------------------------------------------------------

darwin18:08:46

@liminal18 if you really wanted to get some clojure code running in WA today, I think you would have to use ferret[1] and compile the transpiled C-source using emscripten or WA toolchain. By default the code would be using reference counting instead of GC, so you would have to be careful about not creating cycles in your data structures.

mengu18:08:28

thank you @thheller, i've successfully upgraded my react native project to 0.47, re-agent, re-frame, fighweel, clojurescript and clojure

wilkerlucio19:08:23

hello, I'm trying to use the new npm load stuff, but I'm unable to use the library

wilkerlucio19:08:54

my compiler options have:

wilkerlucio19:08:57

:install-deps         true
:npm-deps             {:react-codemirror "1.0.0"}

wilkerlucio19:08:32

and in my code I'm doing: (:require [react-codemirror :as code-mirror])

wilkerlucio19:08:56

different from the example on the news article, the thing I want to access is at the root of the project, it exports a class

wilkerlucio19:08:32

but seems like cljs is handling the code-mirror as a namespace only (it doesn't fail to require, but trying to eval just code-mirror gives me nil)

wilkerlucio19:08:18

I had tried to use as ["react-codemirror" :as code-mirror] too, but this gets me this error: java.lang.AssertionError: Assert failed: cljs.analyzer/foreign-dep? expected symbol got "react-codemirror" (symbol? dep)

wilkerlucio19:08:37

any though on how to handle this case?

anmonteiro20:08:23

@wilkerlucio works for me with current master

wilkerlucio20:08:41

I'm using with the build 1.9.854

anmonteiro20:08:13

there might be a bug that was fixed in the meantime

wilkerlucio20:08:29

how you did the require? string or symbol? and to use it, just eval the name on as?

wilkerlucio20:08:41

just trying to get the full info, so I can try myself 🙂

anmonteiro20:08:44

(ns foo.core
  (:require react
            react-dom
            react-codemirror))

wilkerlucio20:08:08

and then how you access it, just react-codemirror?

anmonteiro20:08:29

(println "react-codemirror:" react-codemirror)

wilkerlucio20:08:31

cool, thanks, I'll try to use master here

anmonteiro20:08:38

react-codemirror: #object[Function]

anmonteiro20:08:54

@wilkerlucio let me know if you run into any issues

wilkerlucio20:08:25

sure, did you know if there are known issues regarding npm deps + figwheel?

anmonteiro20:08:02

not that I know of

anmonteiro20:08:08

put something together that I can try

anmonteiro20:08:11

and I’ll look at it

anmonteiro20:08:31

not a repo, a single build.clj + source file should be enough to repro

wilkerlucio20:08:12

ok, I'll going to try inside my current setup (with figwheel), if that doens't work I'll try standalone

wilkerlucio20:08:10

@anmonteiro working on master 😉

wilkerlucio20:08:11

@anmonteiro now I'm having issue to require a namepace that needs to be a string, on this case: (:require ["codemirror/mode/clojure/clojure"])

wilkerlucio20:08:23

got that analyzer error: java.lang.AssertionError: Assert failed: cljs.analyzer/foreign-dep? expected symbol got "codemirror/mode/clojure/clojure" (symbol? dep)

anmonteiro20:08:51

@wilkerlucio I can repro

anmonteiro20:08:53

looking into it

anmonteiro20:08:30

Juho has some pending work trying to fix those cases

wilkerlucio20:08:16

in any case, thanks for looking that up

anmonteiro20:08:07

I just asked Juho that in #cljs-dev

ayidi23:08:11

Hi! Is it possible to create a macro in .clj that uses the js namespace? Found it https://cljs.github.io/api/cljs.core/defmacro