Fork me on GitHub
#clojurescript
<
2018-02-12
>
holyjak10:02:19

Hi! In ES6, having 3 variables, I can do { msg, status, env } and get { msg: msg, status: status, env: env }. Is there a similar trick for clj(s) (other than writing my own macro or defining a record with these field) to do that or do I need to manually write { :msg msg, :status status, :env env }? Thanks! #DRY

juhoteperi14:02:12

You can use a macro: https://github.com/metosin/potpuri/blob/master/src/potpuri/core.cljc#L72-L77 (I recommend copying this to your own util ns if you choose to use this)

thheller10:02:08

nothing like that in standard CLJ/CLJS no

joelsanchez10:02:09

if you can do that, it means that data is already somewhere. if that "somewhere" is a map, do this: (select-keys data #{:msg :status :env})

holyjak11:02:12

the data is in local bindings from let 😞

holyjak12:02:05

Is cljs.spec.alpha a part of latest clojurescript and I can just require it or is it a separate lib? Couldn't find it on clojars/maven?

beetleman12:02:36

(ns some.cljs.project
  (:require [clojure.spec.alpha :as s]))

holyjak13:02:17

clojure., not .cljs? From http://cljs.github.io/api/cljs.spec.alpha/ I would expect cljs...

beetleman14:02:06

i dont remember from which version but clojurescript should "translate" namespaces from cljs to clojure

holyjak22:02:58

Thank you so much!

beetleman12:02:41

works for me:D

thheller12:02:57

@holyjak it is part of cljs itself yes

pablore13:02:09

How do I work with js functions that return promises in cljs?

roman01la14:02:39

@pablore just handle the promise as in js (-> p (.then do1) (.then do2))

sggdfgf19:02:08

how to translate this into clojurescript document.querySelector ('.app') ?

thheller19:02:05

(js/document.querySelector ".app")

justinlee21:02:38

I was thinking about using the expectations library in an atom validator during development. Question: what’s the normal (simple) way of ripping the library and validators out of production?

justinlee21:02:07

i guess it’s sort of a dumb question. in node, there is a de facto practice of setting NODE_ENV=production and lots of libraries follow that. my question is really: is there a similar practice here?

holyjak06:02:55

There is goog.DEBUG variable. And :advanced would remove unused code.

justinlee17:02:52

interesting that the cljs assertion library doesn’t use that

noisesmith21:02:39

does clojurescript allow turning assertions off in the same way clj does?

noisesmith21:02:06

oh, you want to remove the whole library too?

justinlee21:02:51

that would be nice given that code size matters

justinlee21:02:09

obviously i could just cook up something myself by setting a variable and not using the library. i could then either hope that the optimizer kills the unused code or figure out some kind of reader macro thing to remove the require statement (i have no idea how to do that so that’s why i’m asking if there’s an obvious easier way)

noisesmith21:02:43

if it doesn’t exist yet it would be really cool to see it implemented

justinlee21:02:17

well the cljs assert macro uses *assert*, which is set with a compiler option, to remove assertions. it says not to use “manually” but I think that means don’t set it manually. reading it to do development-only validations makes sense to me.

qqq22:02:43

#js is a reader macro right? what cljs function is closest in functionality ?

Ryan Radomski22:02:10

is clj->js what you're looking for?

tomc22:02:12

I'm seeing some cljs compilation behavior that I don't understand, hoping someone here can help me out. With clojurescript 1.9.946 and tools.reader 1.1.0, I'm seeing the "no reader function for tag Inf" problem described here: https://stackoverflow.com/questions/48039878/cljs-core-cljs-line-988-col-14-no-reader-function-for-tag-inf. I upgraded tools.reader to 1.2.1 and that issue went away. Now I'm getting the invalid js output issue described here: https://dev.clojure.org/jira/browse/CLJS-2352. I'm not sure what I've got wrong, since the dependency versions are right. I verified dependency versions using lein deps :tree - if there's a better way to check the versions please let me know.

tomc23:02:46

nvm, blowing away target directory solved the problem.