This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-04
Channels
- # aleph (2)
- # beginners (80)
- # boot (18)
- # cider (6)
- # cljs-dev (14)
- # cljsrn (5)
- # clojure (114)
- # clojure-android (5)
- # clojure-dev (8)
- # clojure-greece (6)
- # clojure-italy (9)
- # clojure-russia (108)
- # clojure-uk (82)
- # clojurescript (158)
- # css (1)
- # cursive (21)
- # data-science (1)
- # datomic (66)
- # emacs (9)
- # ethereum (3)
- # fulcro (26)
- # graphql (7)
- # hoplon (25)
- # juxt (2)
- # keechma (34)
- # lein-figwheel (4)
- # leiningen (2)
- # off-topic (4)
- # om (5)
- # onyx (14)
- # parinfer (2)
- # pedestal (17)
- # planck (3)
- # portkey (14)
- # re-frame (23)
- # reagent (12)
- # ring (8)
- # rum (1)
- # shadow-cljs (506)
- # spacemacs (2)
- # vim (11)
- # yada (6)
@bhauman Very cool! Was actually trying last week trying to get devcards to work with a re-frame application, but gave up and doing it in doo/karma/cljs.test instead. Is there an example app that works with React that I can try copying from? Thanks again for all your great work!
@genekim there is the devcards lein template lein devcards my-project
.. but I don't recommend devcards as your primary test suite. I do recommend it for building a library of components that you can work on in isolation.
Hmm. It seems to be a controversial subject. Maybe I'm just googling using the wrong terms. I want to create JS libraries/utilities but code them in ClojureScript. Is it just a bad idea?
The scenario is that I have a big JS-based project, but want to start doing some parts in CLJS
@johanmynhardt depends. are they going to be used in node or the browser?
@thheller in the browser
It's a PolymerJS project that I want to use it in.
this might work for you https://github.com/thheller/shadow-cljs/wiki/ClojureScript-for-JS-Devs
ooh, I'm going to have a look, thank you @thheller š
Thanks again @bhauman. FWIW, it was your clojureconj west talk on figwheel that made me jump in and try ClojureScript. Watching the video made me laugh uproariously, and later, cry as I went back to doing things the old way with TypeScript,, React and Gruntfiles. :) Keep up all the amazing work!
I have dev, stage & prod
builds in leiningen
and each of them declares some goog.VARS
, but prod
ends up overriding stage
. Any idea why that can happen?
Having a hard time getting Cljs to recover from an error. If I do anything invalid like refer to an undefined symbol, boot-reload will load in the corrected script, but trying to render anything throws `Cannot read property āgetNativeNodeā of nullā Any idea how to get Cljs to recover from exceptions?
@petrus IIRC: That's Reacts error. Re-mount your entire react app upon reload and it should work.
(defn mount []
(prn "mounting")
(reagent/render-component [parent-component (:app @!system)]
(.getElementById js/document "app")))
I can see āmountingā printed on a changeWhat can I do until Reagent supports React 16 as per https://github.com/reagent-project/reagent/pull/308?
Wrap the render-component
call in a try-catch?
@petrus, to elaborate on what @rauh said, the problem (if it is your problme) occurs when an exception is thrown during a render fn
React normally doesn't recover from exceptions in render functions
(defn mount []
(prn "mounting")
(reagent/render-component [parent-component (:app @!system)]
(.getElementById js/document "app")))
I can see āmountingā printed on a change@hkjels by goog.VARS
, do you mean :closure-defines
? I don't have a ton of experience with that feature, but I wonder if you might run into what you describe if you don't clean between switching builds
@mfikes closure-defines
yes. However I run it using lein do clean, cljsbuild once stage
@hkjels Is the separation at the project.clj
(top-level) :profiles
level, or at the :builds
level (inside of :cljsbuild
)
That might be the problem. (I have my builds separated as :profiles
) Curious: Do you have different :output-dir
settings for each?
I'm not an expert on this, but my setup is the template from re-natal https://github.com/drapanjanas/re-natal/blob/master/resources/project.clj
re-natal, for example uses :builds
to produce one each for iOS, Android, for example, for a given :dev
or :prod
profile
Hrm... well, I'm only speculating at what proper behavior should be here is. I would dig into lein or cljsbuild's code to see how things are merged together
yeah, Iāll get back at it this evening. Right now I have to pick up some kids š Thank you!
What can I do until Reagent supports React 16 as per https://github.com/reagent-project/reagent/pull/308?
Wrap the render-component
call in a try-catch?
@petrus I don't do reagent, but rum. But try to call unmount-comp
on reagent before mounting. That's what I do and it properly recovers
(reagent.core/unmount-component-at-node my-element)
? https://github.com/reagent-project/reagent/blob/master/src/reagent/core.cljs#L78
(reagent.core/unmount-component-at-node my-element)
? https://github.com/reagent-project/reagent/blob/master/src/reagent/core.cljs#L78
Does not seem to work (in mount):
(let [elem (.getElementById js/document "app")]
(reagent/unmount-component-at-node elem)
(reagent/render-component [parent-component (:app @!system)] elem))
Still the same error? I use v16 and they also changed the defautl behavior (see: https://reactjs.org/blog/2017/07/26/error-handling-in-react-16.html#new-behavior-for-uncaught-errors ). Can you upgrade to 16?
how do I upgrade to React 16 without problems? This doesnāt seem to cut it:
[reagent "0.6.0" :exclusions [cljsjs/react cljsjs/react-dom]]
[cljsjs/react "16.0.0-0"]
[cljsjs/react-dom "16.0.0-0"]
I get TypeError: reagent.impl.util.react.createClass is not a function
Does not seem to work (in mount):
(let [elem (.getElementById js/document "app")]
(reagent/unmount-component-at-node elem)
(reagent/render-component [parent-component (:app @!system)] elem))
@petrus you could try this: https://github.com/pesterhazy/recalcitrant#error-handling
reminder: please vote and share. trying to get some numbers on required JS interop work. https://twitter.com/thheller/status/914427680690405378
how do I upgrade to React 16 without problems? This doesnāt seem to cut it:
[reagent "0.6.0" :exclusions [cljsjs/react cljsjs/react-dom]]
[cljsjs/react "16.0.0-0"]
[cljsjs/react-dom "16.0.0-0"]
I get TypeError: reagent.impl.util.react.createClass is not a function
@petrus React 16 doesn't have createClass
, you'll need to use Reagent 0.7+ and add create-react-class
dep
@genekim - Any chance you are running into this? https://github.com/bensu/doo/issues/49
Oh @genekim your snippet of plugins says ālein-doo 0.1.7ā (which matches the screencast but youāre downloading ālein-doo 0.1.8"
Looks like you have some kind of mismatch. doo 0.1.8 was just released - a couple days ago it looks like based on github - and if you make sure your project.clj is referencing 0.1.8 I think you might be in luck. I just set it up on an existing project a few minutes ago and it worked the first try. Earlier I was having problems with 0.1.7, so it may be an error in that version.
Hi, noob question: anyone know how to get puppeteer
working for node cljs? I wanted to use it with promesa
Async/Await Syntax. Doesn't seem to work, why?
(ns app.main
(:require [promesa.async-cljs :refer-macros [async]]
[promesa.core :as p]))
(def puppeteer (js/require "puppeteer"))
(async
(let [browser (p/await (.launch puppeteer))]
(js/console.log (p/await (.version browser)))))
Unhandled rejection Error: kill ESRCH
at exports._errnoException (util.js:1022:11)
at process.kill (internal/process.js:173:13)
at killChrome (/home/cljs-test/target/node_modules/puppeteer/lib/Launcher.js:122:19)
at Function.launch (/home/cljs-test/target/node_modules/puppeteer/lib/Launcher.js:108:7)
...
i'm starting figwheel + cljs REPL from EMACS/CIDER and I get
Failed to compile "target/js/compiled/pickle.js" in 3.218 seconds.
---- Could not Analyze src/pickle/sources.cljs ----
No such namespace: whatwg-fetch, could not locate whatwg_fetch.cljs, whatwg_fetch.cljc, or JavaScript source providing "whatwg-fetch"
in my project.clj:
:cljsbuild {
:builds [{:id "dev"
:source-paths ["src"]
:figwheel true
:compiler {
:main pickle.core
:asset-path "target/js/compiled/dev"
:output-to "target/js/compiled/pickle.js"
:output-dir "target/js/compiled/dev"
:target :nodejs
:optimizations :none
:source-map-timestamp true
:npm-deps {:whatwg-fetch "2.0.3"}}}
{:id "prod"
:source-paths ["src"]
:compiler {
:output-to "index.js"
:output-dir "target/js/compiled/prod"
:target :nodejs
:optimizations :simple
:npm-deps {:whatwg-fetch "2.0.3"}}}]}
have you tried adding https://clojurescript.org/reference/compiler-options#install-deps ?
that worked š thanks @U61HA86AG!
does anyone know of any queiscent apps out there where i could read the source? The todo-mvc quieiscent app is quite strange it seems. making a channel for each property of state and having to create its own request render function. seems overly complicated unless that's just what you're supposed to do
maybe a stupid question, is *ns*
bound at runtime or compile time for Clojurescript? Can I use it in my logs?
uhm, self-answer...it is runtime, but probably not if I am using it inside a macro
*ns*
always exists, but the current value is determined by the context of the call, not the context of the definition (dynamic var)
also I wouldnāt expect *ns*
to be useful in cljs, outside of macros
so what I would like to do is (defonce log (.child l/parent-logger #js {:ns *ns*}))
at the top of my file, but I don't think this works
@richiardiandrea that would end up using the *ns*
of the code that invoked the macro
yeah I am afraid so
and macros in cljs happen in another world entirely š
right, and cljs doesnāt really have useful namespaces the way clj does
(at runtime - they arguably exist in some form but itās a trickier story)
in lumo
they exists in form of compiler state at the repl...but actual compilation is another kettle of fish
probably I could create a macro that expands to a read to the compiler state?
@richiardiandrea what are you trying to do?
like big picture, do you just want the code to know what namespace the calling code was in?
replace the *ns*
above with the actual namespace name
wouldnāt it be easier to a) make it a macro, then the caller of the macro would fill in the *ns*
properly, or b) make the ns an explicit argument?
for sure it is a macro, but that info only exists at compile time probably
right but if *ns*
is part of the macro expansion, and the macro is called in ns foo, then *ns*
will expand to foo
I am trying smth out š
so basically I don't see in the compiler a way to say "I am compiling X namespace", which is basically what I want to extract, I will dig more and just hardcode the namespace as string now in there
@richiardiandrea what about (defmacro my-ns [] *ns*)
that would work in functions even
no it does not work, I have tried
there might be some lumo
problem however, not sure
at the time of the macroās expansion *ns*
should have the value of the one using the macroā¦
I have:
(defmacro current-ns
[]
*ns*)
š(ins)cljs.user=> (defmacro my-ns [] *ns*)
true
(ins)cljs.user=> (ns foo.bar)
nil
(ins)foo.bar=> (.log js/console (cljs.user/my-ns))
{ obj: {},
name:
{ ns: null,
name: 'foo.bar',
str: 'foo.bar',
_hash: 1702737123,
_meta:
{ meta: null,
cnt: 5,
arr: [Object],
__hash: null,
'cljs$lang$protocol_mask$partition0$': 16647951,
'cljs$lang$protocol_mask$partition1$': 8196 },
'cljs$lang$protocol_mask$partition0$': 2154168321,
'cljs$lang$protocol_mask$partition1$': 4096 },
'cljs$lang$protocol_mask$partition0$': 6291456,
'cljs$lang$protocol_mask$partition1$': 0 }
nil
oh ok, well it works for sure in the repl
sorry, I did not specify that I am compiling down to JS
I am trying with vanilla cljs now just to see if it is a lumo
issue
If you have a Var in your namespace, say x
, then perhaps you can statically get what you want with an expression like (namespace (.-sym (var x)))
oh, nice hack š
If you don't want to depend on .-sym
you could perhaps do something more complicated like (let [s (pr-str (var x))] (subs s 2 (- (count s) 2)))
well no I think I am fine with that
will try for completeness
compiles to: processor.log = logging.parent_logger.child(({"ns": cljs.core._STAR_ns_STAR_.name}));
so it should work?
or maybe not just a sec
yep at compile time
@rauh no lumo
compilation was failing but there might be a lumo
problem there
@rauh actually your version works!
so only (defmacro current-ns [] *ns*)
fails the compilation, we where on the right path @noisesmith
thanks both for your suggestions
actually all three š
very useful, btw also (str *ns*)
works
(defmacro loader
[component arguments sub]
`(let [show-loading? (reagent/atom false)]
(reagent/create-class
{:component-did-mount
(fn component-did-mount [_]
(when-not @show-loading?
(js/setTimeout #(when-not @sub
(reset! show-loading? true))
500)))
:reagent-render
(fn [] ~component)})))
(println (loader [:div [:div]] [] [1 2]))
(cljs.core/let
[test.common.loading/show-loading? (reagent.core/atom false)]
(reagent.core/create-class
{:component-did-mount
(cljs.core/fn
test.common.loading/component-did-mount
[test.common.loading/_]
(cljs.core/when-not
@test.common.loading/show-loading?
(js/setTimeout
(fn*
[]
(cljs.core/when-not
@test.common.loading/sub
(cljs.core/reset! test.common.loading/show-loading? true)))
500)))
:reagent-render (cljs.core/fn [] [1 2])}))
@rnagpal : I think you got confused by the fact that you are calling a macro as a function this is possible in cljs repls, macros are functions with two extra hidden parameters, that is why your component is actually unexpected 3-rd arg
@rnagpal I don't fully understand it, but dug this for you: https://github.com/anmonteiro/lumo/issues/30
btw. (println (loader [:div [:div]] [] [1 2]))
should not give you what you wanted even if loader macro was expanded properly as expected
you want to do (macroexpand-1 '(loader [:div [:div]] [] [1 2]))
<- note the quote
I don't think I understand how lein decides which version of a library to use.
I picked up an old tools.reader version. com.taoensso/encore wanted 0.10.0 and org.clojure/clojurescript wanted 1.1.0
My fix was to use lein :exclusions to ignore encore's dep.
Sounds like I need to get a handle on hard/soft deps. From lein FAQ... Q: I specified a dependency on version X but am getting version Y; what's up? A: One of your dependencies' dependencies has declared a dependency on a hard version range, which overrides your "soft" declaration.
nothing should be using hard versions - two libs specifying different hard versions makes your build fail
(in regular maven at least)
I can't find a definition of hard dependencies. I presume it's not :depencencies in lein's project.clj
I donāt know if lein even has a way to do it
Fair enough.
Any idea why I'd get the older tools.reader when I have two dependencies wanting different versions?
@olivergeorge have you looked at the output of lein deps :tree
?
Yes, that's what confirmed the situation.
fwiw this is mavenās DSL (Iām not sure how lein maps to it, it might use the same strings?) https://maven.apache.org/pom.html#Dependency_Version_Requirement_Specification
Interesting
you should be able to look at the pom.xml file for the tricky dep (the one :tree blames) and see how it specifies
that would quickly confirm or rule out of hard vs. soft deps have any part to play here
the pom.xml will be next to the jar in question under your .m2/repository/
Thanks, I'll try that. Here's a gist showing the interesting bits of lein deps :tree
.
https://gist.github.com/olivergeorge/0ee8d39896d52e7c84dabf6eb0625c9b
What I didn't expect was clojurescript not having a dep in the first case. Presumably lein said "well I have that dep already so let's not mention it" or something similar.
I showed both cases
the second one has the exclusion
(updated gist, there was a bad copy / paste)
I see that now - isnāt it claiming to get the right version now?
It is with the exclusion
So I have a work around.
What worries me is that any dep could demand an earlier version and break my build unless I keep manually excluding them.
Just seems odd.
doesnāt lein prefer deps earlier in the list over later in the list? so specifying your tools.reader dep closer to the top should help
it looks at each dep in the list, depth first, make the version you want show up first
pom deps don't seem strange on the surface
<dependencies>
<dependency>
<groupId>org.clojure</groupId>
<artifactId>tools.reader</artifactId>
<version>1.1.0</version>
</dependency>
and
<dependencies>
<dependency>
<groupId>org.clojure</groupId>
<artifactId>tools.reader</artifactId>
<version>0.10.0</version>
</dependency>
@noisesmith Interesting. If that's the case I can work with it.
I'll test the theory
Yep, that's it.
Serves me right for sorting my deps in string order.
Thanks for the help @noisesmith
glad I could help