This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-08-29
Channels
- # admin-announcements (2)
- # beginners (20)
- # boot (139)
- # cider (6)
- # clara (1)
- # cljs-dev (7)
- # cljsrn (4)
- # clojure (160)
- # clojure-berlin (1)
- # clojure-canada (6)
- # clojure-gamedev (1)
- # clojure-japan (7)
- # clojure-russia (14)
- # clojure-spec (90)
- # clojure-uk (10)
- # clojurescript (73)
- # clojutre (1)
- # conf-proposals (8)
- # crypto (67)
- # cursive (9)
- # datomic (6)
- # editors-rus (1)
- # events (1)
- # figwheel (6)
- # funcool (2)
- # hoplon (19)
- # instaparse (37)
- # kekkonen (4)
- # lein-figwheel (2)
- # leiningen (5)
- # luminus (1)
- # off-topic (1)
- # om (10)
- # onyx (60)
- # protorepl (2)
- # re-frame (81)
- # reagent (10)
- # ring-swagger (15)
- # rum (6)
- # specter (17)
- # test-check (10)
- # uncomplicate (31)
- # untangled (12)
- # yada (6)
Hi, suppose I specify a clojurescript keyword as the first argument to history.pushState
and want to deserialize it back into a keyword in my popstate
handler. How would I go about doing so?
@johanatan: in general, I’d probably use pr-str
and read-string
(js/history.pushState #js {:state (pr-str data)})
and then (set! js/onpopstate (fn [e] (let [data (read-string (aget event “state” “state"))])))
i wouldn’t call it cheating, just necessary interop that you just write once
there is an issue in current CLJS regarding generating functions from specs, ex: (clojure.test.check.generators/sample (s/gen (s/fspec :args (s/cat) :ret int?)))
this code works on Clojure, but errors on Clojurescript: #object[TypeError TypeError: Cannot read property 'for_all_STAR_' of undefined]
There is a test
function in clojurescript: https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/core.cljs#L10339
How do I use it?
This is the code of test:
(defn test
"test [v] finds fn at key :test in var metadata and calls it,
presuming failure will throw exception"
[v]
(let [f (.-cljs$lang$test v)]
(if f
(do (f) :ok)
:no-test)))
How do I set the code of the test into (.-cljs$lang$test v)
?
@viebel See the first example at https://clojuredocs.org/clojure.core/test
But it doesn’t work
cljs.user=>(defn my-function "test" {:test #(assert false)} ([]))
cljs.user=> (test #'my-function)
:no-test
I ran it in a fresh repl with java -jar cljs.jar -m cljs.repl.node
I also tried in planck and in klipse
getting :no-test
What’s the meaning of (.-cljs$lang$test v)
? It is a javascript key, right?
@viebel It appears deftest
does the right thing, but perhaps work needs to be done to make :test
work
@viebel Interestingly, this appears to work:
(defn my-test
[v]
(let [f (:test (meta v))]
(if f
(do (f) :ok)
:no-test)))
Yeah. I noticed also.
Do you think I could submit a patch with it? Or it might break deftest
?
BTW, this is the implementation in clojure: https://github.com/clojure/clojure/blob/clojure-1.8.0/src/clj/clojure/core.clj#L4647
the CLJS implementation might have to do with the fact that you can’t add metadata to vars at runtime
hence the cljs$lang$test
I discovered something: with java -jar cljs.jar -m cljs.repl.node
the following works:
cljs.user=> (defn my-function "test" {:test #(assert true)} ([]))
#'cljs.user/my-function
cljs.user=> (test my-function)
:ok:
but this one doesn’t:
cljs.user=> (test #'my-function)
:no-test
But in planck and klipse both don’t work => :no-test
@wilkerlucio hrm, just seems like you haven’t loaded the test.check namespaces, if that isn’t true then file an issue
I'm wondering what do you folks use for your non-cljs build pipelines. Gulp? SASS? Postcss? Webpack? Assets story feels a bit neglected in CLJS-related posts so it would be nice to hear your stories :)
@si14 There are Less and Sass plugins both for Boot and Lein, e.g. https://github.com/Deraen/less4clj https://github.com/Deraen/sass4clj
@juhoteperi thanks! However, if I want to add e.g. autoprefixer + postcss-flexbugs-fixes to the mix, it becomes somewhat more complicated :) Same with image compressing
@dnolen you are right, requiring more namespaces fixed the issue, thanks
@juhoteperi: It's hacky, but I always fall back to this in a pinch - https://github.com/hyPiRion/lein-shell
@wilkerlucio Clojure can automatically loads those namespaces we cannot - we have some code to give a hint what went wrong but it probably needs more work
@juhoteperi : Similarly, if you want to make sure stuff is installed before you try to run shell commands, I use lein-npm
: https://github.com/RyanMcG/lein-npm
@nickt Reader conditionals: http://clojure.org/reference/reader#The%20Reader--Reader%20Conditionals
but my defs are just constant strings and numbers... I don't really need to differentiate between clj and cljs
ok so if I just make a cljc
file with a couple def
statements I should be able to require it in both clj and cljs?
didn’t even know that, although that makes sense as project.clj
doesn’t have ns
nor does build.boot
I thought that each namespace became a java class at compilation, so it was necessary somehow
Yeah I've only ever used it for one-off scripts. clojure uses that feature internally for things iirc
hm ok... completely unrelated question: Is there an option I can pass to cljs.build.api/build
that disables caching? Always rebuilds completely?
from my macros.clj
file I tried (ns-resolve 'iss.constants blah)
and it tells me "no namespace iss.constants found"
@xcthulhu @juhoteperi thank you (again) :)