This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-11
Channels
- # aleph (1)
- # architecture (18)
- # beginners (57)
- # boot (13)
- # cider (47)
- # cljs-dev (28)
- # cljsjs (13)
- # cljsrn (39)
- # clojure (258)
- # clojure-greece (16)
- # clojure-italy (2)
- # clojure-miami (1)
- # clojure-nl (9)
- # clojure-poland (15)
- # clojure-russia (369)
- # clojure-spec (53)
- # clojure-uk (49)
- # clojureremote (3)
- # clojurescript (135)
- # core-matrix (1)
- # cursive (11)
- # datascript (3)
- # datomic (4)
- # emacs (12)
- # figwheel (13)
- # hoplon (7)
- # interop (7)
- # jobs-discuss (33)
- # lumo (28)
- # off-topic (15)
- # om (7)
- # onyx (26)
- # pedestal (10)
- # perun (1)
- # planck (10)
- # re-frame (54)
- # reagent (16)
- # ring (5)
- # ring-swagger (50)
- # rum (2)
- # spacemacs (2)
- # unrepl (125)
- # untangled (12)
@thheller @tankthinks i use goog-define for this https://www.martinklepsch.org/posts/parameterizing-clojurescript-builds.html
https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L123
Not sure if {"my-app/var" :env}
will work
@thedavidmeister for what?
Hi! #js {:foo 1}
produces {"foo": (1)}
, is there any way to emit {foo: (1)}
(to allow Closure renaming) instead or should I use deftype
?
I don't quite get that in the repl. Is that what gets dumped to file? What about (js-obj "foo" 1)
?
@thheller but but but naming is hard (and I suck at it), I just wanted some local anonymous state 😢
(doto #js {} ; no I won't use a deftype, I'm nomatophobic
(-> .-s (set! ""))
(-> .-exhausted (set! true))
(-> .-idx (set! -1))
(-> .-cbs (set! #js []))
(-> .-sentinel (set! nil)))
@john what you see in the REPL is the printed representation after evaling the source, it is not the source
@thheller for putting environment variables into cljs from clj
is there a problem with figwheel? I tried starting a new project with it with lein new figwheel proj -- --om
, and get a ton of errors in the console and the repl doesn't connect
oh so I just cleared chrome browser cache and now it all works...
@alex_lynch there is an option on chrome dev tools to do not save caches while devtools are open. I usually do that, saves me tons of time figuring out problems. :)
trying inferred externs. during advanced compilation I get:
WARNING: out/inferred_externs.js:14 WARNING - name goog is not defined in the externs.
that line of externs has:
goog.string;
goog.string.StringBuffer;
goog.string.StringBuffer.prototype.append;
how do I coax it into inferring var goog;
?@devth you do not need externs for anything goog
, thats a bug if the infer emits that
Hi, anyone got time for what I think is probably a bit of a dumb question? I’m doing a bit of work with P5.js. I instantiate with (js/p5. (fn[_]))
and set the setup function on the object with set!
. The setup function gets called but that in turn calls other functions which use things like map. The problem is that these cljs.core functions aren’t found. I know it’s got something to do with closures and namespaces, but any clues as to why that is?
in devtools console you should be able to check if the cljs.core namespace is present and it has expected methods/members there
it is as far as I can tell, it’s just that the functions are not available from within this function. Could it be something to do with a javascript function calling this ClojureScript one?
ok, this could be a bit of a mess!
`
(defn create-sketch [options]
(let [^js/p5 sketch (js/p5. (fn [_]))]
(set! (.-setup sketch)
(:setup options)
)
(set! (.-draw sketch)
(with-sketch sketch (fn [] (:draw options))))
sketch
)
)
So I’m playing about with stuff there, but this is the function that creates the p5 object
(defn create-world [w] (let [bodies (map create-body (:bodies w)) bodies-map (#(zipmap (map :id %) %) bodies) get-by-id (fn [id] (get-in bodies-map [id :body])) ] {
why don’t you test some minimal repro case? e.g. in create-sketch
replace setup
with #(js/console.log (map inc [0 1 2]))
your problem might be in this (#(zipmap (map :id %) %) bodies)
but I don’t understand it, so I cannot comment
it could be. The idea is to take an array and produce a map where the key is based on 🆔
that probably does keep things cleaner! As you might have guessed I’m still fairly new to this
I think at this point you should identify exact first place where your map
(or similar) call does not work
yeah I think you’re right. I’m debugging more and I’m starting to think it’s not that map isn’t defined but something that’s undefined as map is called.
hi - wondering if anyone has experience with clojurescript + react native... in particular, interested in how you managed to set up unit tests. There doesn't seem to be a straightforward way of accomplishing this.
@acgt, check out #cljsrn for react-native specific discussion
@pesterhazy ah, thanks - didn't see that there.
@darwin turns out it was bad argument to concat
deep in the code. It caused something to be nil and just created a very confusing error! Thanks again for you help. It was useful talking it through and you got me out the dead end I was in
looking at concat
is always a good idea when looking for bugs
for some reason bugs are drawn to concat
like moths to the flame
The style guide at https://github.com/bbatsov/clojure-style-guide recommends using alter-var-root
to change the values of vars, but CLJS doesn't seem to have that. What is the idiomatic way to do this in CLJS?
@tech_hutch it’s just JavaScript so (set! my-ns/my-var 42)
works
Okay.
And it's in the same ns, so I would assume I could omit that.
I wonder why it mentions alter-var-root as something to use instead of def at runtime, but no mention of intern? moot here as cljs has no intern
or maybe using intern is as bad as def
if I had written the style guide it would have something like “any alteration of vars at runtime that isn’t done by a dev-only tool is a code smell”
Clojure core has vars that are designed to be rebound at runtime, though.
That's what the "earmuffs" notation is for.
that's not for redefining the var, that's for local binding - in fact if you used binding and someone else used def it could easily break your code
Say, if I have a constructor (js/Foo.)
, can I apply
it like (let [args [0 1 2]] (apply js/Foo. args))
? I seem to be getting undefined back, not sure if there's some interop syntax I'm missing
(let [ctor (js/Function.prototype.bind.apply js/Date #js [nil 2014 1])] (ctor.))
#inst "2014-02-01T07:00:00.000-00:00"
Pretty!
I almost think it would be more legible just to manually get the positions out of my vector and pass them to the constructor (js/Foo. (nth args 0) (nth args 1) (nth args 2))
js/Date
is a function, though, so it has the Function .apply method on it.
so you could shorten js/Function.prototype.bind.apply
to .apply
.
wouldn't that be js/Function.prototype.apply? Why .bind.apply?
hi, are there any vanilla js light wrappers around clojure data structures? say, one passes clojurescript data to a react component, I was looking for something similar to immutable js API to access clojure immutable data from js.. would mori
serve as a API wrapper for this use case? (not sure if slack is the place for this sort of question..)
More concretely, this is what I'm trying to instantiate with a my vector of three constructor args: https://github.com/mrdoob/three.js/blob/master/src/math/Euler.js
Oh, right.
You can't use .apply with new
, I forgot.
If I'm not mistaken, you can use the Clojure apply
with JS functions, although I don't know if it works with constructors.
Yeah, I've used it with functions before. The constructor case seems to be different though
it can be done succinctly in ES6 with the spread operator new Date(...args)
, but my CLJS-foo still isn't quite there yet
I could be wrong, but I believe Clojure has a spread operator. (Different syntax, though.)
Well, regular Clojure I would probably use (apply)
or maybe use destructuring. But I can't figure out how to get the constructor as a fn to pass to apply. Actually, for this specific thing I can (let [get-rot (fn [[x y z]] (js/THREE.Euler. x y z))] (get-rot [0 1 2]))
which works ok
....and there's also a fromArray()
method in that specific code. Still curious if there's an (apply)
that works with constructors though
How would that work in ES3 code, which CLJS outputs, though? I believe there's a way, but I don't remember it.
yes, Date
can also take an array. We're just using Date
as an example; the original question was about using apply
on js/Foo.
It's a known problem that you can't .apply
a constructor in ES5 I think
Kind of a bug in the language
Relevant.
Hmm, interesting
strangely now calling the defonce
ed var from the figwheel repl throws a Use of undeclared Var my.ns/my-var
error. It still returns the correct value though. It's just a spurious warning.
Just wanted to encourage some upvotes on an annoying quirk of keyword parsing and reading. There's a better error waiting at the end of it which will leave you with more time for your family and friends. The error thrown when cljs.reader/read-keyword encounters an invalid symbol (say one starting with a number) is not very helpful. It's particularly difficult to know where the reader failed when dealing with a big data structure. For example, this command
(cljs.reader/read-string (str (keyword "3asdf")))
Returns this error
TypeError: Cannot read property '0' of null
The null is easily detected to return a more meaningful error like:
Error: Can't create keyword from :3asdf
I'm conflicted about the fact that the cljs reader errors on this - the docs specify this should be an error, so actually throwing an error is legit. And it bugs the hell out of me that people working on my app have set up code that creates such keywords. But then again we do create such keywords (thanks to mongo not supporting numbers as keys, and everyone loving keywords so much that they cast all keys coming back from mongo to keywords) so this would break my app.
There a few related JIRA tickets.
just hit this one. And it is even less helpful that sometimes you can create keywords with just numbers.
This is the ticket
Please upvote
do :pre and :post work in clojurescript?
K. I must have something else going on. Sadly not worth the effort to ferret out 😕