This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-07
Channels
- # aleph (3)
- # aws (7)
- # beginners (117)
- # boot (119)
- # cider (2)
- # cljs-dev (3)
- # clojure (193)
- # clojure-austin (1)
- # clojure-dusseldorf (4)
- # clojure-finland (5)
- # clojure-france (5)
- # clojure-italy (7)
- # clojure-portugal (1)
- # clojure-russia (204)
- # clojure-serbia (5)
- # clojure-spec (31)
- # clojure-uk (64)
- # clojurescript (288)
- # community-development (9)
- # core-async (54)
- # cursive (8)
- # datascript (18)
- # datomic (26)
- # dirac (8)
- # emacs (26)
- # figwheel (1)
- # hoplon (16)
- # jobs (2)
- # jobs-discuss (4)
- # juxt (1)
- # lein-figwheel (4)
- # leiningen (14)
- # london-clojurians (2)
- # lumo (17)
- # off-topic (44)
- # om (63)
- # om-next (2)
- # onyx (26)
- # perun (14)
- # planck (5)
- # portland-or (34)
- # proton (2)
- # protorepl (8)
- # quil (1)
- # re-frame (6)
- # reagent (16)
- # remote-jobs (4)
- # ring (7)
- # ring-swagger (10)
- # rum (1)
- # untangled (2)
Basically what happens is that your calls to require execute correctly on node, and when you compile with basic optimizations the times you call require stay in place
But browserify/webpack, as dnolen would be quick to point out, don't do a great job at optimizing and dead code eliminating generated clojurescript code
In browser, where code size is a big deal, you basically have to use advanced optimizations, which doesn't work with the require function, but instead with js externs and Google closure namespaces
Work is being done to make using code from node doable (both on the clojurescript team and the Google closure team)
For now just look on cljsjs for the js libraries you want to use and if you can't find what you need then come back here and someone will help you out
@msuess require
gets compiled away so probably something went wrong. The guide is clear you can鈥檛 use ES6 yet w/ Node modules support
but it鈥檚 a cutting edge feature so expect a bumpy ride unless you have a lot of patience and are OK with digging into how the feature actually works
Anyone have a line on how to do sha256 hashing in cljs? All the links I'm finding seem to be out of date. TIA
Hello, if I'm looking to use third-party react component from npm, is http://blob.tomerweller.com/reagent-import-react-components-from-npm a good guide to follow?
Specifically, the approach is to compile the react components with webpack, attach it to window
, and exclude react
and react-dom
from reagent.
hey all I have been playing witht the cljs.js/compile-str
and I noticed the library resolution function passes a string for the library name. I was wondering what would happen if there are two files name the same coming from different libraries? Anybody knows how collisions get resolved?
@yanglin That guide works iff you have the externs for the libraries you are using or you don't use advanced compilation
Anyone knows how to get around importing foreign libs that uses flow types ? I can't find anything about this and I am not familiar with flow type...
what library? usually projects that code with type annotations should be running their code through a compiler step to remove them; there might be another .js file in the package you should refer to instead
you should get the release builds instead, they'll have the compiled output as normal javascript in the lib/ folder
does cljs have access to spec.gen? I'm trying to (:require ,clojure.spec.gen :as gen] in a cljs file, and it can't find it
err, when I :module-type :es6 in my :foreign-libs it fails to find the :provides ["gl-react"] namespace (No such namespace: gl-react, could not locate gl_react.cljs...)
but when I remove the :module-type :es6 then it builds and later fails executing js cause it's a es6 module 馃槥
my foreign lib expects window.react to be defined when it's :required... Any idea how I could (set! js/React react) when I :require cljsjs.react ?
I could fix it by importing react in my index.html but there has to be a more idiomatic way...
I found this googling around for a better solution: http://blob.tomerweller.com/reagent-import-react-components-from-npm
I find it's an interesting option that I believe would fix my problem (foreign lib needs window.react define prior to :require) but I'd loose cljsjs... maybe there is an even better solution?
@sineer the :module-type
for :foreign-libs
is very much a work in progress, webpack should be more reliable for a while
how to write this in clojurescript: messages.indexOf(link.source) > -1 ? link.target : link.source
?
by this point i know that in the array it's only one of them that is present and one of them is always present
well, i wrote (if (> (.indexOf messages link.source) -1) link.target link.source)
hopefully it will work
ashnur read this http://squirrel.pl/blog/2013/03/28/two-ways-to-access-properties-in-clojurescript/
(if (> (.indexOf messages link.source) -1) link.target link.source)
this shouldn't work
(if (> (.indexOf messages link.source) -1) (.-target link) (.-source link))
use (.-property obj)
to access properties of objects
try it!
in lumo:
(doseq [x (into-array [:a :b :c])] (prn x))
@pesterhazy i don't understand
ah, I didn't understand then
here's the source of seq
: https://github.com/clojure/clojurescript/blob/47fa30dd95c850aa0643aae9c274c09bc202065c/src/main/cljs/cljs/core.cljs#L1113
as you can see it hands over to -seq
of ISeqable
can't find where ISeqable is defined for arrays though
ah wait it checks if it's an array in seq
then it creates an IndexedSeq of the array
here's the implementation: https://github.com/clojure/clojurescript/blob/47fa30dd95c850aa0643aae9c274c09bc202065c/src/main/cljs/cljs/core.cljs#L1510
it uses aget and keeps track of the index
@ashnur finding the anwer you were looking for?
(defn somefn [] (let [localvalue (.jsfunc js/somejsobj (fn [] ( ... how to access localvalue here? ... )))]))
localvalue
you're not showing the actual code
ah I see
the lack of identation threw me off
you can use an atom for that if you want
(let [!localvalue (atom nil)] (reset! !localvalue (do-something (fn [] (prn @!localvalue)))))
kind of thing. I'm not sure I balanced parentheses correctly there 馃檪
come again?
@ashnur deref
is just "give me the value of the thing now", basically a property access
@thheller so, i should do what @pesterhazy suggested to solve this situation? use an atom?
(let [timer-ref
(atom nil)
timer-fn
(fn [elapsed]
...
(.stop @timer-ref))
timer
(js/d3.timer timer-fn)]
(reset! timer-ref timer))
maybe that is clearer, you need to name for the timer before it actually exists, so timer-ref
is a placeholder basically. ie. there will be a thing in here when timer-fn
is called
hmm. i am having a brain freeze... how to have multiple expressions in a conditional? (do) ?
i am sure when i finish this i will see some ways to make it more idiomatic to clojurescript, but for now, it's not very nice ;D
const notCurrentEdge = (fe) => currentEdges.find((ce) => ce.index != fe.index)
how to have a predicate like this? currentEdges is an array of objects with index and i am trying to make sure that the object i am checking has an index that's not present. kinda obvious .. not sure what's the best way to do this
ashnur: you can emulate .find
with (first (filter #(not= (.-index %) (.-index fe)) currentEdges))
ah yeah, that works if you鈥檙e just trying to make sure find
finds nothing
ignore me, you are doing the right thing 馃檪
one thing is sure, this learning project is actually doing its job, i am running into a lot of weird stuff
https://gist.github.com/ashnur/910a4fdc3556a32f435f248c04108c8f#file-index-js-L75 this mutates the array currentEdges
what I see: cljs needs better JS libs support (which is a wip) and better marketing (wonder how this will end up)
^ 2nd may be a consequence of the 1st too
how do i write this in cljs? const inTheDark = (edge) => (messages.indexOf(edge.source) > -1 ) ^ (messages.indexOf(edge.target) > -1 )
馃槃
i checked, this works https://clojuredocs.org/clojure.core.logic/!=
if you want !=
as it is in JS use not=
. core.logic
is a logic programming library, an entirely different thing
i mean i thought that core.logic is just the part where logic stuff is separated but that doesn't mean i can't use it
i am fairly sure i can't do the hack from javascript to just use the bitwise oeprator instead, right?
ah ok, you want to call it without numbers but still have the a number as the result
@rauh i am not sure why would you say that as i just mentioned that i tried and it wants number inputs
yes, I get that ... just in my history whenever I used binary ops I used it on numbers. just ignore me .. I'm old.
https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/core.cljc#L1141
@jr that's cool, but if i try to use it with booleans it complains, guess i could cast the boolean into numbers
@ashnur it seems to be more common in the clojure world to use all
, some
, and
, or or
when doing boolean logic. Not that you can't use xor
if you want, just not overly common in clojure
@roman01la better marketing you mean for the staffing concerns?
@anmonteiro I think better integration with JS will have some impact - but I do think the marketing problem is a broader issue
as I鈥檝e said before nearly 60% of users come from Java/Python/Ruby so I think there鈥檚 a lot we can do here
i know that if it wasn't for the java tight coupling, i would've tried cljs 2 years earlier
although now that i said this, you probably want to tie it to java even more just to keep people like me away 馃槢
i am not sure how can that survey tell anything about this, but sure, as you said, doesn't matter much
but it would be crazy for you to have java high on that list because it would go against the tide where you perceive money comes
someone wrote a library for CLJS/CLJ macros to make it easier to generate platform specific code, anyone remember the name?
@ashnur no, just not a priority and unlikely to be - there鈥檚 just more important things to work on
@thheller I believe this is what you're looking for https://github.com/cgrand/macrovich
@anmonteiro thats the one, thanks
FYI, I discovered dirac (cljs repl for devtools!) two days ago and it rocks! Coolest repl I ever seen 馃檪 Check it out if you haven't already...
Also, I'm extremely happy to have a working gl-react canvas in devcards with om next 馃檪
@ashnur Well (not= true true), true false, false false, false true
are all equal to (xor a b)
@rauh, clever
(defn xor [a b] (not= (boolean a) (boolean b)))
@dnolen: I meant better marking for broader adoption
Has any seen the error
[Violation] Parser was blocked due to document.write(<script>)
in the browser, when running figwheel, I believe it related to CLOSURE complier injecting it's JS require (Maybe)... Anyhow any pointers would be great. (It odes not appear to be stopping the app from loading).I found cljs-http to do http get but I'm wondering if there's a simpler or more common way to load resource files? a simple blocking load would do...
browsers don't do sync 馃槥
@pesterhazy you can do a sync get but I don鈥檛 recommend it
yeah I was just thinking about that trying to think of a way if at all possible.. it's for devcards stuff and to defonce some shaders data..
@dnolen, really? you can send synchronous network requests from javascript in a browser?
I guess I'll just have to use cljs-http... Out of curiosity is there anything simpler (no core.async dep maybe) ?
yeah that's what I was looking for 馃檪 Thanks! I remember using something similar with react-native
From a cljs repl, is there any way to block until some async event happens?
I can do this:
cljs.user=> (def r (atom nil))
#'cljs.user/r
cljs.user=> (goog.net.XhrIo/send "" #(reset! r (-> % .-target .getResponseJson js->clj)))
#object[Object [object Object]]
cljs.user=> @r
but it would be neat if I could programmatically wait for the result (instead of manually checking the atom periodically)
@pesterhazy can you not use channels for that
@stbgz how would that work?
@sineer do you use any wrapper for gl-react or does it "just work" with om-next ? I鈥檓 a reagent user so not very familiar with om-next.
I'm working on a cljs lib/wrapper for gl-react it's just prototype yet but I'm making great progress 馃檪
I havent seen gl-react used with cljs anywhere but there isn't much to it... the hard work is getting the foreign libs to work
@pesterhazy I swear I鈥檝e seen that being done with channels, but I can鈥檛 find the doc anymore, I鈥檒l ping you if I find it
gl-react is just a react component so you can use it with plain react or which ever cljs wrapper you prefer 馃檪
@stbgz cool thanks
@stbgz maybe you're thinking of using <!!
i.e. blocking take, which is intentionally missing from the cljs implementation of core.async
does anyone know how to get goog.DEBUG
to end up false
in CLJS 1.9.229 ? I've tried :closure-defines {:goog.DEBUG false}
and :closure-defines {"goog.DEBUG" false}
to no avail.
@johanatan either 'goog.DEBUG false
or "goog.DEBUG" false
should work
what's the symptom you get?
I don't use cljsbuild, so I couldn't tell you
yep, lein cljsbuild once prod
is invoking the right build now. will see how that turns out. thx!
don't forget to add the ^boolean
type hint too
helps with DCE
use goog/DEBUG
, the js/goog.DEBUG
variant won鈥檛 work in .456:
https://github.com/binaryage/cljs-devtools/commit/4e368408986bf739b56aad64e064b854fd7989d2
hmm, my prod build seems to be broken with this cryptic stack trace:
java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.Named
at clojure.core$name.invokeStatic(core.clj:1546)
at clojure.core$name.invoke(core.clj:1540)
at cljs.closure$make_options.invokeStatic(closure.clj:263)
at cljs.closure$make_options.invoke(closure.clj:253)
at cljs.closure$optimize.invokeStatic(closure.clj:1266)
at cljs.closure$optimize.doInvoke(closure.clj:1259)
at clojure.lang.RestFn.applyTo(RestFn.java:139)
at clojure.core$apply.invokeStatic(core.clj:648)
at clojure.core$apply.invoke(core.clj:641)
at cljs.closure$build.invokeStatic(closure.clj:2020)
at cljs.closure$build.invoke(closure.clj:1927)
at cljs.build.api$build.invokeStatic(api.clj:199)
at cljs.build.api$build.invoke(api.clj:187)
at cljs.build.api$build.invokeStatic(api.clj:190)
at cljs.build.api$build.invoke(api.clj:187)
at cljsbuild.compiler$compile_cljs$fn__5973.invoke(compiler.clj:60)
at cljsbuild.compiler$compile_cljs.invokeStatic(compiler.clj:59)
at cljsbuild.compiler$compile_cljs.invoke(compiler.clj:48)
at cljsbuild.compiler$run_compiler.invokeStatic(compiler.clj:168)
at cljsbuild.compiler$run_compiler.invoke(compiler.clj:122)
at user$eval6110$iter__6146__6150$fn__6151$fn__6169.invoke(form-init7676291134357241625.clj:1)
at user$eval6110$iter__6146__6150$fn__6151.invoke(form-init7676291134357241625.clj:1)
at clojure.lang.LazySeq.sval(LazySeq.java:40)
at clojure.lang.LazySeq.seq(LazySeq.java:49)
at clojure.lang.RT.seq(RT.java:521)
at clojure.core$seq__4357.invokeStatic(core.clj:137)
at clojure.core$dorun.invokeStatic(core.clj:3024)
at clojure.core$doall.invokeStatic(core.clj:3039)
at clojure.core$doall.invoke(core.clj:3039)
at user$eval6110.invokeStatic(form-init7676291134357241625.clj:1)
at user$eval6110.invoke(form-init7676291134357241625.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:6927)
at clojure.lang.Compiler.eval(Compiler.java:6917)
at clojure.lang.Compiler.load(Compiler.java:7379)
at clojure.lang.Compiler.loadFile(Compiler.java:7317)
at clojure.main$load_script.invokeStatic(main.clj:275)
at clojure.main$init_opt.invokeStatic(main.clj:277)
at clojure.main$init_opt.invoke(main.clj:277)
at clojure.main$initialize.invokeStatic(main.clj:308)
at clojure.main$null_opt.invokeStatic(main.clj:342)
at clojure.main$null_opt.invoke(main.clj:339)
at clojure.main$main.invokeStatic(main.clj:421)
at clojure.main$main.doInvoke(main.clj:384)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:383)
at clojure.lang.AFn.applyToHelper(AFn.java:156)
at clojure.lang.Var.applyTo(Var.java:700)
at clojure.main.main(main.java:37)
Subprocess failed
I may have missed the correct syntax 馃檪
try 'goog/DEBUG
slash instead of dot
@johanatan in a macro you can have access to compiler options, and you can decide to emit clojurescript code or not, for example depending on the :optimizations
key
https://github.com/binaryage/cljs-oops/blob/276de0b73fbcef6a7ad43b31470ecaf2139da097/src/lib/oops/config.clj#L21-L23
the sharp edges were related to DCE, I expected it to happen and it silently didn鈥檛, once because of missing ^boolean
type hint, second time because of using js/goog.DEBUG
form
anyways :closure-defines is not widely used I would say, so there might be some quirks not only with DCE
Dead Code Elimination