This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-02-03
Channels
- # aatree (5)
- # admin-announcements (52)
- # announcements (1)
- # aws (2)
- # beginners (55)
- # boot (494)
- # braid-chat (17)
- # cider (2)
- # cljsjs (4)
- # cljsrn (8)
- # clojure (157)
- # clojure-austin (6)
- # clojure-czech (7)
- # clojure-denmark (1)
- # clojure-dev (102)
- # clojure-ireland (6)
- # clojure-japan (4)
- # clojure-miami (2)
- # clojure-poland (90)
- # clojure-russia (415)
- # clojurebridge (2)
- # clojurescript (143)
- # core-async (1)
- # datavis (4)
- # datomic (20)
- # devcards (5)
- # dirac (40)
- # emacs (9)
- # events (103)
- # gorilla (1)
- # immutant (122)
- # jobs (3)
- # ldnclj (20)
- # lein-figwheel (1)
- # mount (2)
- # off-topic (22)
- # om (170)
- # onyx (7)
- # overtone (6)
- # parinfer (100)
- # proton (2)
- # re-frame (5)
- # reagent (32)
- # ring-swagger (2)
- # spacemacs (6)
jlongster: goog.typeOf
also type
Weird...
I'm trying to define a macro and use it in cljs. I created the macro in a clj file (util.clj) in my clojurescript source directory. The compiler wasn't able to find the namespace. But when I added an empty util.cljs file in the same directory, the compiler was happy and everything worked. Is that expected, or am I missing something?
I thought I understood this, but now I’ve got myself confused. If I want to access the properties of a JS event under advanced compilation, should I use (.-target evt)
or (goog.object/get evt “target”)
or is there no difference?
I always use aget
with strings
(aget js-obj "foo" "bar")
The GClosure compiler never touches strings, so it's safe with advanced compilation
aget
isn’t recommended for access on objects https://groups.google.com/forum/#!searchin/clojurescript/aget/clojurescript/XJLWNnMR5ik/DcSY_yfnFgAJ, forgot to mention that
it's doubtful I will stop using it that way
@sashton: Do you have two different source directories for the two languages? Like src/clj
and src/cljs
?
I just read that thread; I see where David is coming from
@sashton: I tend to define my macros in a src/clj/app/macros.clj
and require them in my CLJS code with the :require-macros
ns
form.
@sashton: https://github.com/clojure/clojurescript/wiki/Differences-from-Clojure (macro section might be useful)
is this a bug in CLJS? https://gist.github.com/jlongster/d5f1ef9b89f8647e2579
@sonelliot I thought I read somewhere that the macro file needed to be in the clojurescript classpath, src/cljs/.../macros.clj
@sashton: I haven't heard of that sorry 😕 It's my understanding that macros need to be done in a separate compilation phase. Although this may be different with self-hosted CLJS.
@jlongster: I think case
only works w/ literals — e.g. js/
variables won’t work. It also doesn’t work with vars; it has to be ints, chars, strings, etc
Option {:keywordize-keys true}
for js->clj
function doesn’t seem to work as expected for me. This is an output from my repl
cljs.user=> (get (js->clj (clj->js {:a 1}) {:keywordize-keys true}) :a)
nil
cljs.user=> (get (js->clj (clj->js {:a 1}) {:keywordize-keys true}) "a")
1
cljs.user=> (get (js->clj (clj->js {:a 1}) :keywordize-keys true) :a)
1
cljs.user=> (get (js->clj (clj->js {:a 1}) :keywordize-keys true) "a")
nil
Do you spot any obvious mistake I have made?
[Update]
Nevermind. I saw a patch here http://dev.clojure.org/jira/browse/CLJS-1540@acron: in Garden, attributes are given in a map, but sometimes you need multiple defs of an attribute, in which case can't do that in a map because duplicate keys
@octo221: in Garden for multiple attribute values you use a nested vector, e.g. {:border [[(px 1) :solid :red]]}
@acron, no multiple definitions of the same attribute
e.g. "image-rendering=pixelated image-rendering=moz-crisp-edges ..."
because different browser use different defs
see examples here: https://developer.mozilla.org/en-US/docs/Web/CSS/image-rendering
that's for values I think
same attribute defined multiple times, can't be expressed with a map
unless maybe it can take vectors as keys as well as for values
need to read the source
@acron: found a workaround: add spaces like this [:.class {"attr" 7 " attr" 8 " attr" 9}]
oh yeh good point
on a second thought, one could write a JS parser to automatically generate the extern file of any library?
I think existing extern generators evaluate the JS code on Node (or such) and check the created JS object to create the extern
Easier than writing parser (or using one) directly
I'm trying to create a bootstrapped browser clojurescript evaluation environment with a namespace which has some macros/fns :use
d available in the evaluation state. My problem is - I cannot call macros. Should it be at all possible?
E.g.:
;;;;;;;;;;;;;;;;;;;;;;;;;; my-ns.cljs - the context of evaluation
(ns my-ns
(:use-macros [javelin.core :only (cell=)]
(:require [javelin.core :refer (cell)])))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; eval.clj - evaluator helper to preload the ns into compiler state
(ns eval
(:require [cljs.env :as env]
[cljs.analyzer :as ana]))
;; ---- mimics how the cljs.core ns is loaded
(defmacro dump-my-ns []
(let [state <@U095WMJNR>/*compiler*]
`(quote ~(get-in state [::ana/namespaces 'my-ns]))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; eval.cljs - provides the environment
(ns eval
(:require [my-ns]))
(def state (empty-state (fn [state] (assoc-in state [::ana/namespaces 'my-ns] (dump-my-ns)))))
(defn eval [forms]
(eval state forms {:eval js-eval, :ns 'my-ns, :def-emits-var true} println))
(eval '(def x (cell 1))) ;;; works
(eval '(def y (cell= x))) ;;; fails to find the "javelin.core$macros" ns when resolving the cell= macro
@dm3: Have you set up a load function? (That way, :require
, etc. can load the required code.)
@dm3: You may be able to also dump javelin.core
and javelin.core$macros
(it is not clear to me exactly how to do that, but I suppose you can imitate what the compiler does with core
), but while that takes care of the analysis metadata, there’d be the issue of loading the actual code that implements the cell=
macro.
@dm3: cljs.js
is designed to compile macro code as a result of (dynamically) loading it via the load function. Perhaps you are wanting to AOT transpile the macro code so that its JavaScript is available.
tools.reader says ::ana/namespaces
is not a valid token… but it’s in the cljs source https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/js.cljs#L116 — is there some extra config I need to set to make it parseable?
@jaredly: If you control the source you are trying to evaluate in bootstrap, you could consider working around it by using :cljs.analyzer/namespaces
I’m actually working on making a parser, and benchmarking it against tools.reader by reading all of the cljs source, but then I ran into something tools.reader couldn’t handle 😄 so I’m confused
:ana/namespaces
in cljs.js
would be properly resolved/expanded by the regular JVM-based ClojureScript compiler. Bit, in bootstrapped ClojureScript, there is probably a bug or shortcoming.
(If you aren’t in bootstrap, it is probably still just a shortcoming of that library.)
I think that corner cases like this one, and recently syntax quoting of symbols, are just bugs being discovered and sorted.
To list them off:
`x
didn’t work until recently. But then there are issues like
`catch
inadvertently not being treated as special. Then there is
#{1 2 1}
not throwing. So, I think the inability to handle ::alias/name
is likely just another of these corner cases.@jaredly: If you report a bootstrapped issue against ClojureScript—I took a stab at documenting the special considerations when doing that: https://github.com/clojure/clojurescript/wiki/Reporting-Bootstrap-Issues
Using these instructions (https://github.com/cljsjs/packages/tree/master/nvd3), I’m trying to use nvd3 packaged by cljsjs like this (https://gist.github.com/sooheon/10a7de8ea0c8c654c2f3). With advanced compilation, the functions still get mangled. Am I doing anything obviously wrong?
@sooheon: it shouldn’t be happening as the objects you are using have externs. could you try turning on :pseudo-names
in compiler options to see which ones are getting mangled? details here: https://github.com/clojure/clojurescript/wiki/Compiler-Options#pseudo-names
@sooheon: hmm…the error should which name is missing. whats the shape of line-chart-data
in your code? perhaps i can help you debug this
could you give me an example of how to add, say axisLabel to externs? Not sure of what class it belongs to and so on… do I just have to look at the nvd3 docs?
you can certainly add nv.models.lineChart.axisLabel = function(){}
to the bottom of the extern file
yeah it’s a really one off case, so I don’t doing it by hand, just not sure of the js syntax
Ok, thanks. Actually, something completely different, but how would you add externs to use these dropdowns from semantic-ui? http://semantic-ui.com/modules/dropdown.html#/examples
The function is just .dropdown, but somehow it seems like doing .dropdown = function(){}
would not work
have a look here: https://github.com/cljsjs/packages/blob/master/jquery-daterange-picker/resources/cljsjs/common/jquery-daterange-picker.ext.js
@gzmask: have a look at this project for generating externs automatically: https://github.com/jmmk/javascript-externs-generator
@gzmask: the above project will not be able to handle something like this
var Person = function(name) {
this.name = name;
this.greet = function() {
.....
}
}
i think to generate externs for this may require you to get the information from the AST. but don’t hold me to it.
actually @gzmask also raised this issue a few hours ago. but yup, (i think) this is the reason why the nvd3 externs aren’t complete
yea, this extern thing is starting to get out of hand when dealing with large and complicated libraries. I might just give up advanced optimization and go with simple.
If you're doing this for browser that might not be a good idea - non-optimised Clojurescript application can be in megabytes.
if you don’t use advanced optimization you don’t get fancy stuff like dead code elimination etc.
ClojureScript with advanced optimizations starts around 20K gzipped and goes up from there, depending on what you’re doing
externs aren’t related to dead code elimination - it just prevents advanced optimization renaming
you don’t need to worry about anything you don’t actually call, or property you don’t actually access
that's what I have been doing, everytime I do JS interop I have the extern file open for updating
wait, if every time we do (js/sth) an extern sth should be generated, then extern generation could still be automated ?
anybody can work on it, though probably worth getting in touch with Maria Geller to see if she started down some particular path
excited! when cljs has built-in dead-code-elimination, it will just become a unicorn ; )
it’s not a particularly a hard task - if it’s going to happen somebody who cares should work on it
(we’re unlikely to bother with much DCE of our own, Closure Compiler is works perfectly well)
on the externs inference bit happy to show anyone who is serious about tackling what needs to be done
but yes inferring js/foo
+ js
type hint should cover most typical non-Closure JS interop
Howdy! I had a question about bundling JS libs into my compiled Closurescript. I’ve added the libs that I want such as JSTZ to my project.clj
like so…
:foreign-libs [ {:file ""
:file-min ""
:provides ["jstz”]}
but I don’t see any changes with my compiled code. I’ve checked in Figwheel, using lein cljsbuild once
and in my compiled jars just to be safe. I’m definitely missing something, thanks!killion: https://github.com/clojure/clojurescript/wiki/Dependencies#bundling-foreign-javascript-code
you need to require it (and possibly even call it) in order for it to be prepended to your output file
@gzmask: I would say that the auto extern generation task is halfway complete. Functionality for parsing existing externs and emitting externs for simple js interop, like (.-foo bar)
already works. Still need to add extern generation for more complex js interop, e.g. let bindings. I’ve pushed my progress to a separate branch here (https://github.com/mneise/clojurescript/tree/CLJS-1074). Help is always welcome
Nice @maria, I’ll see if the externs I’m calling are missing any interop types that your branch doesn’t support.
btw, when is ClojureScript 1.8 is planned?