Fork me on GitHub
#clojurescript
<
2018-02-01
>
Ryan Radomski00:02:49

I'm getting some strange behavior with cljs.

(gobj/get cljs-react-material-ui.reagent "app-bar")
(gobj/get cljs-react-material-ui.reagent "paper")
With these two statements, the first returns nil and the second returns the object I want. I aliased the ns to rui and
rui/app-bar
rui/paper
both of these statements return the objects I want. When I console.dir the namespace, app-bar isn't in it, but I can still access it

Ryan Radomski00:02:57

What could cause something like this to happen?

Ryan Radomski00:02:37

My suspicion is the google closure compiler. I have advanced compilation turned on

Ryan Radomski00:02:54

in the library, both objects are also defined the same way

Ryan Radomski00:02:50

Alright I found out in order to do dynamic access, I need to use app_bar instead of app-bar anybody know why?

noisesmith00:02:24

(defn app-bar [...] ...) creates a thing called app_bar

noisesmith00:02:38

see the munge and demunge functions

Ryan Radomski00:02:08

I discovered that when I started dumping vars to the console. I feel really stupid now because I totally knew js doesn't support kabab cased names

Ryan Radomski00:02:32

I just never put two and two together

noisesmith00:02:39

+user=> (munge 'foo-bar!?!)
foo_bar_BANG__QMARK__BANG_
+user=> (clojure.main/demunge (str *1))
"foo-bar!?!"

Ryan Radomski00:02:02

Hey that's pretty handy

noisesmith00:02:17

oh wait, those are the clojure versions, checking for cljs

noisesmith00:02:59

with the cljs demunge it's in cljs.core (accessible normally in other words) and you don't need to convert symbol to string to round-trip

Ryan Radomski00:02:13

Thanks for the pointers. I'm pretty sure you answer like 4/5 of my questions. You deserve a cookie or something

noisesmith00:02:28

haha no I'm trying to lose weight, thanks though

kenbier01:02:04

awhile ago i wrote a cljs wrapper for a cljsjs library. it took some react components and made clojurescript looking functions that generated those componenets

kenbier01:02:18

keeping conventions with kebab case etc…

kenbier01:02:04

i am curious, would the closure compiler be smart enough to strip away the vars I don’t use in my application?

kenbier01:02:00

stripping away both the unused JS vars and my generated cljs vars?

richiardiandrea02:02:54

does the testing macro works for async tests? it does not seem so

richiardiandrea02:02:49

probably I have positioned it wrong

noisesmith02:02:47

it should work as long as the testing form does not exit until the async operation does

noisesmith02:02:01

(and the wrapping deftest naturally)

noisesmith02:02:26

iirc the right way to do this is (deftest foo-test (testing "some thing about foo" (async ...))

richiardiandrea02:02:37

yep I also found I needed an additional take! https://stackoverflow.com/a/30781278

richiardiandrea02:02:46

thanks for answering!

richiardiandrea02:02:14

having worked with mocha for a while, I gave that as a given 😄

sooheon05:02:36

Does anyone know of some examples of implementing file download with cljs?

mikerod15:02:56

If you’re trying to support lots of browsers and versions, you may want to consider using the FileSaver.js library, which has a recent enough version in cljsjs

blackawa05:02:05

This is a snippet from my personal application. You can do like send-pdf-to-browser if you want to download file with cljs.

sooheon06:02:53

@blackawa Thanks, I will check this out

sooheon07:02:05

What is the dom/ namespace?

blackawa07:02:22

Let me check…

blackawa07:02:07

dom/ == goog.dom from google closure compiler

sooheon07:02:36

Ah thanks.

blackawa09:02:29

@timok You can do like this.

(def debug? ^boolean js/goog.DEBUG)
(def endpoint (if debug? "localhost:3000" ""))

joelsanchez09:02:08

replied in beginners

Miloslav10:02:18

Hi everyone! I have a problem with Closure Compiler externs. I use pouchdb alongside with socket-pouch and pouchdb-authentication and it's obvious that I get an error with :advanced optimizations flag. As far as I know, I need externs to solve the problem. So how should I do it? Both pouchdb and pouchdb-authentication are present in cljsjs, but there's no socket-pouch available there

Miloslav11:02:12

any further reading?

Jakub Holý (HolyJak)11:02:59

See https://clojurescript.org/guides/externs for autogenerating them. It is also easy to write by hand if you only use a small part of the api

Miloslav11:02:57

so how do i enable them?

Jakub Holý (HolyJak)11:02:26

U put them in the root dir of your project or on the classpath and in the :compiler section of cljsbuild config refer to them

Miloslav11:02:16

what shoud I do after I've generated them?

Miloslav12:02:12
replied to a thread:so how do i enable them?

Wow, thanks!

Miloslav13:02:59

yep. I declared libraries as their own externs and disabled extern validation as mentioned at purelyfunctional tv, and it worked just neat

Miloslav13:02:40

thank you guys, who knows how much time i'd spent digging it by myself

tomaas16:02:25

hi, how can I appende to a re-com component the :component-did-update logic for example?

fbielejec16:02:42

hi @tomaas, you just pass a map to reagent/create-class with react lifecycle methods as functions

(defn my-component []
    (reagent/create-class
     {:reagent-render (fn [args]
                         [:div args)
      :component-did-update (fn [props] (prn "component did update!"))}))

tomaas16:02:10

yes, I know

tomaas16:02:42

but I was looking how to hook this to a re-com component

tomaas16:02:43

I may wrap the re-com component with (r/create-class..) but if in the render function I dont deref the atom I pass to a re-com's component this does not work

fbielejec16:02:32

Haven't used it but I suppose as usually with such frameworks re-com functions return only hiccup forms, so the render method.

gganley23:02:35

How often do you add more than one build to the :cljsbuild :builds in the project.clj

nenadalm06:02:06

Hi. Always 🙂 When I have Clojure + Clojurescript project, I have build for dev, test and prod (different in optimization level and with possible additional dependencies for e.g. test). When I have CojureScript at both frontend and backend, then I have 6 builds instead of 3 🙂. You can see example template for Macchiato, where there is dev build for backend: https://github.com/macchiato-framework/macchiato-template/blob/master/resources/leiningen/new/macchiato/project.clj#L52 and dev build for frontend: https://github.com/macchiato-framework/macchiato-template/blob/master/resources/leiningen/new/macchiato/project.clj#L32 (each within their own profile)

gganley17:02:33

Ok, I'm editing CIDER to be able to detect what REPL you would want during dev, so in this case I would look for :builds :dev :compiler :target and see that you want to use nodjs and automatically suggest to change the REPL backend to node

gganley23:02:02

I’m writting something that tries to detect if someone is targeting a particular platform and I realized it only works if there is one element in the :builds array

thheller23:02:19

in case of cljsbuild always. since you'll need one build for development and one for optimized release builds.

gganley23:02:00

how would they be differentiated? dev vs prod that is

thheller23:02:33

:optimizations mostly, :none vs :advanced

gganley23:02:48

Sorry to put the burden of effort onto you but could you post an example project.clj that includes these two builds?

thheller23:02:19

given that I'm the developer of shadow-cljs I don't use lein-cljsbuild at all but pretty much every lein template out there has those

thheller23:02:51

lein new fulcro my-app for example has multiple builds

gganley23:02:16

I was using a project.clj that had one build

gganley23:02:21

my apologies

thheller23:02:58

thats fine for development but for the "production code" you really want an optimized build