Fork me on GitHub
#clojurescript
<
2017-08-24
>
coetry02:08:34

Does anyone know why I can’t get garden into my Boot repl?

coetry02:08:48

Nvm, it doesn’t work when I enter the browser repl, but works from boot.user

fdserr09:08:09

Hi people. I've been looking for a way to implement class MyComp extends Component ES6 jargon, since React is removing createClass from its API (I know it's available separately). The tricky part is to initialise state (or any non-fn member), since getInitialState is also a thing from the past. This is what I came up with, it seems it works, but I'd like feedback if there's a better way? Many thanks!

(defn MyComp [p]
  (let [c (React.Component. p)]
    (set! (.-state c) #js {:value "STATE"})
    (specify! c
     Object
     (render [o] (React.createElement
                  "div" #js {}
                  (.-text (.-props o))
                  (React.createElement
                   "div" #js {}
                   (.-value (.-state o))))))))

(defn my-comp [p]
  (React.createElement MyComp (clj->js p)))

(defcard
  ""
  (my-comp {:text "PROP"}))

;=> shows "PROP" and "STATE"

roklenarcic12:08:34

Hm how do you guys debug clojurescript? Do you use a special debugger or something?

roklenarcic12:08:39

yeah I've been using prn a lot too

roklenarcic12:08:14

chrome debugger is nearly 100% useless, and repl stops working when you're stopped at a breakpoint

pesterhazy13:08:42

chrome debugger should work I think, but I don't use it at all

pesterhazy13:08:06

@fdserr you can probably use some functions from google closure to inherit from Component

pesterhazy13:08:37

also my understanding is that createClass is not deprecated, just moved to a separate library, so it's still fine to use

roklenarcic13:08:26

can't really inspect or manipulate clojurescript datatypes with chrome debugger

roklenarcic13:08:52

also when there are multiple breakpoint possibilities on the same line, it doesn't allow me to select any but the outermost expression

sundarj13:08:42

@roklenarcic have you looked at Dirac?

roklenarcic13:08:35

I have but I didn't go through all the thing with installing a special chrome for it

sundarj13:08:00

it's well worth it imo

roklenarcic13:08:10

I'll look into it again

sundarj13:08:50

you can also just use cljs-devtools, which works with your normal chrome version

pesterhazy13:08:14

@fdserr your snippet is nice actually. So the problem is that you can't specify a constructor?

pesterhazy13:08:10

I'd be interested if that's the best way in ClojureScript to extend an ES6 class

thheller13:08:55

@pesterhazy @fdserr that’s what I have been using for my components (wrapped in a helper function)

thheller13:08:49

you can add add #js {:render (fn [] ...) to the goog.extend call to add methods to the class

souenzzo14:08:36

(.log js/console (str [my-bugged-var])) also helps. http://blog.cognitect.com/blog/2017/6/5/repl-debugging-no-stacktrace-required It's usefull. but it a bit tricky on cljs.

au-phiware15:08:04

I discovered that I had to npm install "@cljs-oss/module-deps"

au-phiware15:08:02

Now, my question is how come this @cljs-oss/module-deps isn't packaged with cljs?

pesterhazy16:08:39

@thheller, I'm trying out your snippet. Maybe i'm being daft but what does component-fn refer to https://gist.github.com/thheller/7f530b34de1c44589f4e0671e1ef7533#file-es6-class-cljs-L18 ?

pesterhazy17:08:50

@thheller should that line be (set! (.. my-component -prototype -constructor) my-component)?

thheller17:08:16

@pesterhazy yes sorry. my-component is correct. took that example from my code and forgot to change that reference

thheller17:08:42

don’t to the extend in the constructor

thheller17:08:03

just add the #js as an extra arg to the gobj/extend below

richiardiandrea18:08:14

in ClojureScript, is there a particular macro/function to iterate and additive add to fluent interfaces like this: https://github.com/archiverjs/node-archiver/blob/master/test/archiver.js#L282?

richiardiandrea18:08:04

I know I could reduce, and pass the instance from one call to another, but I wonder if there is a better way, like doto but iterating

pedrorgirardi18:08:32

Hi..is it possible to link inside an HTML a CSS that is “bundled” with a cljsjs dependency?

pedrorgirardi18:08:44

In my case the dependency is antd and I can see that the CSS file is under cljsjs/antd/development/antd.inc.css

pesterhazy18:08:05

I guess the whole thing could be wrapped in a Class Constructor function?

pesterhazy18:08:13

(def my-component (make-component (fn [this] :constructor-goes-here) #js{:render (fn [] ..)}))

pedrorgirardi18:08:52

thank you @juhoteperi, I will try that

thheller18:08:18

@pesterhazy yes, thats what I do.

pedrorgirardi18:08:27

@juhoteperi it worked, and thank you for Less4clj!

tiagoantao18:08:48

I ended up going back to http://github.com/cljsjs/packages . I will wait until it becomes more stable

Garrett Hopper18:08:26

How would I go about importing a clojurescript project in a situation where the normal document.write script tags won't work? (React native) Since the goog library doesn't provie an es6 module.

anmonteiro18:08:03

@au-phiware you probably just forgot to add :install-deps true to your compiler options

john20:08:49

is all the new cljs.loader and modules work compatible with lein cljsbuild?

souenzzo20:08:37

With these new clojurescript 1.9.9?? is possible/easy/there is an explanation how to have nested js/cljs files in same project? (I have a big project, I want to start port components to clojurescript)

john20:08:16

well, the code splitting tutorial definitely works for me. When trying from a lein-cljsbuild/figwheel project though, (resolve ... is not resolving my symbols.

pesterhazy20:08:44

@thheller @fdserr, I've turned @thheller's snippet into a make-component function that supports display-name and an optional constructor fn: https://github.com/pesterhazy/feigenrad/blob/master/src/feigenrad/core.cljs#L13

john21:08:04

hmmm. By putting (loader/load :my-mod ... outside of my handler function, it started somewhat working.

john21:08:54

Getting Uncaught TypeError: Cannot read property 'EvaluateCodeEvent' of undefined but the module loaded and the function executes.

anmonteiro21:08:58

@john are you calling set-loaded! in your module entry points?

john21:08:08

@anmonteiro yes, I've got set-loaded! at the bottom of my core namespace in an upstream project, which has the function in question. Then I have it also at the bottom of the core namespace of my downstream project. That ns calls a function called instrument-btn' in my widgets` namespace of the downstream project, which causes the button to, when clicked, execute the function from my upstream project.

john21:08:09

And my downstream project's cljsbuild compiler options have a module map that describes both the downstream and upstream modules

anmonteiro21:08:16

does the “downstream project” require the “upstream project”

john21:08:04

it has the upstream project as a dep in the project.clj but does not require it from the widget ns

anmonteiro21:08:24

happy to look at a minimal case

john21:08:00

Okay. I'll try to whip something up. Thanks!

john21:08:41

Other than that error though, it is functioning.

anmonteiro21:08:16

I’ve seen that error before when set-loaded! is called too early I think

anmonteiro21:08:21

which is why I’m asking

john21:08:40

understood

john21:08:51

another question: should we be able to mix modules from upstream projects and within one project all together? So, something like

:modules {:upstream {:output-to "resources/public/js/compiled/upstream.js"
                       :entries #{upstream.transmit.core}}
            :widgets {:output-to "resources/public/js/compiled/widgets.js"
                      :entries #{downstream.widgets}
                      :depends-on [:upstream]}
            :core {:output-to "resources/public/js/compiled/core.js"
                   :entries #{downstream.core}
                   :depends-on [:widgets]
                   }}

john21:08:21

and then, from my downstream.core ns, do (l/load :widgets ((resolve 'downstream.widgets/instrument-btn)))

john21:08:14

and where instrument-bn does (l/load :upstream ((resolve 'upstream.transmit.core/send) ... ??

john21:08:57

And I assume downstream.core should not be requireing downstream.widgets since it is split off and brought in via the module loader. Does that all sound sane?

anmonteiro21:08:43

@john if you really want to grok how all this works you should read “Closure: The definitive guide”

john21:08:11

I've been meaning to buy that actually

au-phiware21:08:24

I did have that option but now I'm using lein-npm and I've explicitly added @cljs-oss/module_dep to my devDependencies.

john21:08:44

@anmonteiro well, I made a minimal project with a similar setup, but I'm getting an error I was getting earlier, rather than the EvaluateCodeEvent error. But here it is: https://github.com/johnmn3/modrepro

john21:08:26

modrepro is the upstream project, a subdirectory submodrepro has the project which consumes modrepro

john21:08:04

so I do a lein install on the parent dir to pull it into the subdir with the project deps

anmonteiro21:08:33

this is not minimal at all

anmonteiro21:08:48

can you make something without multiple projects and without Lein

anmonteiro21:08:55

it should be reproducible that way

anmonteiro21:08:58

otherwise too many variables.

john21:08:48

I'm sorry. Rgr, I'll try. My hunch is that lein-cljsbuild/figwheel may be causing the error, because following the directions to create a minimal build using the tutorial all went fine.

john21:08:07

I'll try to boil it down further.

au-phiware22:08:10

@john you're not having the problem I had are you? What's the output of lein do clean, cljsbuild once?

au-phiware22:08:51

Note, I was unable to figure out how to make a minimal build to reproduce my problem... so frustrating...