This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-01
Channels
- # adventofcode (11)
- # aws (8)
- # beginners (70)
- # boot (2)
- # cider (9)
- # cljs-dev (29)
- # cljsrn (2)
- # clojure (67)
- # clojure-android (2)
- # clojure-dusseldorf (5)
- # clojure-greece (12)
- # clojure-italy (4)
- # clojure-nl (3)
- # clojure-poland (3)
- # clojure-russia (5)
- # clojure-spec (80)
- # clojure-uk (9)
- # clojurescript (73)
- # core-async (17)
- # cursive (1)
- # data-science (5)
- # datomic (29)
- # emacs (5)
- # fulcro (257)
- # graphql (2)
- # hoplon (2)
- # jobs (2)
- # klipse (3)
- # leiningen (9)
- # lumo (4)
- # nyc (1)
- # off-topic (48)
- # om (7)
- # other-languages (11)
- # pedestal (4)
- # re-frame (18)
- # remote-jobs (1)
- # rum (10)
- # shadow-cljs (5)
- # spacemacs (20)
- # sql (5)
- # test-check (44)
- # unrepl (8)
- # yada (9)
direct translate of your snippet should be (gdom/setProperties svg-dom #js {:x 20 :y 20})
Hi, I have a question. How to use beautifully UI(eg:[Ant Design](https://github.com/ant-design/ant-design)) within [reagent](https://github.com/reagent-project/reagent)? In addition, there is a better project for UI?
semantic-ui https://opensourcery.co.za/2017/02/12/using-semantic-ui-react-with-re-frame/
bootstrap like https://github.com/Day8/re-com
flexible layout https://github.com/gadfly361/re-surface
@U7DKLTCQJ it's cool, thanks. @U1VSXM85B it’s better for mobile apps, thanks
Is there a way to translate this code into cljs without atoms? var k = setInterval(function(){ clearInterval(k) }, 300);
@tomc what you need is cyclic references, and clojure is not very helpful about that. You can consider the following options : - use atoms, as you said - if you're in global scope, you can declare a var and define it later - I made a lib that can be used to solve problems of this kind https://github.com/leonoel/plop
@leonoel Thanks for the response. Interesting lib too. I'll reach for it if I ever need a lot of this type of thing, but for my purposes I think an atom will suffice.
@leonoel @tomc you can refer to a function from itself (fn foo [] (something foo))
is valid
cmd)dev:cljs.user=> ((fn foo [x] (if (> x 5) x (map foo (range (* 2 x) (* 3 x))))) 2)
((8 9 10 11) (10 11 12 13 14))
but it turns out `(fn k [] (js/setInterval #(js/clearInterval k) 300))` doesn’t work - it just looped on me
@noisesmith I'd like to be proven wrong, but I can't think about a strategy without any assignment of some kind
@leonoel I think it would work with a defn - not sure though
fn / defn already assign to the function object, but that seems not to work with setInterval (at least like that)
I’m curious if a truly abusive, evil, js*
hack would work:
(let [k (js/setInterval #(js/clearInterval (js* "k")) 300)])
the js*
hack definitely wouldn’t work under advanced compilation since variables get renamed all over the place. the reason @noisesmith’s `(fn k [] (js/setInterval #(js/clearInterval k) 300))` doesn’t work is because clearInterval
takes the numeric id returned by setInterval
, not the interval function. doesn’t seem like the clearInterval can be accomplished without some sort of assignment
ahh of course! - thank you
(def k (delay (js/setInterval #(js/clearInterval @k) 300))
might work in that case
if cljs has delay
@smith.adriane I wouldn’t actually use the js*
hack, but I can’t see how advanced would break it, given that it compiles to JavaScript that involves var k
and a later use k
. Are you seeing a definite reason it would break? (I’m mostly just curious.)
advanced compilation will rename variables
but not the string
(let [k (js/setInterval #(js/clearInterval (js* "k")) 300)])
gets turned into
(function (){var k = setInterval((function (){
return clearInterval(k);
}),(300));
return null;
})()
under advanced compilation?
That is the JavaScript that gets emitted prior to advanced, but if you passed that JavaScript to GCC, since it involves no string representing k
, GCC should rename both in a consistent way.
This differs, for example from (goog.object/get x "foo")
which turns into JavaScript that looks like goog.object.get(cljs.user.x,"foo")
and you have a "foo"
string that won’t be changed.
interesting
I stand corrected then
it does make the assumption that let
will always use the same variable name as your binding
If, for example you had this, it would break
(let [k 1 k (js/setInterval #(js/clearInterval (js* "k")) 300)])
weird, I just ran it through advanced compilation and got setInterval(function(){return clearInterval(k)},300);
with no assignment to k
Interesting that it leaves you with a k
at all. Under simple, I got
function (){var a=setInterval(function(){return clearInterval(a)},300);return null}
So, I’m writing a macro (to emit cljs), and I want to discover the methods of a protocol. The :sigs
entry is there in Clojure, so if the protocol is in a cljc file, I’m fine. Is there a public API that I can hit to ask the compiler about cljs-only protocols?
@tony.kay we produce an AST node for protocols I’m pretty sure, I would just look at that
the protocol will be a var in the ns and that var will have :protocol-info
, and in there you will have :methods
hello! just starting out with clojure(script), and stumbled upon this example: http://blog.klipse.tech/clojure/2016/10/10/defn-args-2.html
sadly, it doesnt seem to work anymore, could the spec of defn have changed since then?
when running (my.spec/defndoc foo "docs" {:something "sad"} [a b] (+ a b)) : #object[Error Error: No protocol method IAssociative.-assoc defined for type cljs.core/Keyword: :cljs.spec.alpha/invalid] Error: No protocol method IAssociative.-assoc defined for type cljs.core/Keyword: :cljs.spec.alpha/invalid at Object.cljs$core$missing_protocol [as missing_protocol]
what is the {:something "sad"}
?
doesn’t seem like that belongs
meta data needs the ^
, eg. ^{:something "sad"}
and the first part works just fine, but when i try to run the defndoc macro in the second part, it stops with that error
even with the meta data correction?
that’s really weird, because the only keyword is in the metadata map you provided
although, I guess I’m not that familiar with the defndoc
macro
so it’s barfing on (my.spec/defndoc foo "docs" [a b] (+ a b))
?
[org.clojure/clojure "1.8.0"] [org.clojure/clojurescript "1.9.671" :scope "provided"] [org.clojure/spec.alpha "0.1.143"]
seems like the above should work
the code on the page is live
you get the same error if the arguments to defndoc aren’t right
is it possible that the code isn’t being recompiled?