Fork me on GitHub
#clojurescript
<
2017-12-01
>
qqq00:12:07

@thheller: what do you mean by 'native dom fn' ?

albert.lai00:12:45

direct translate of your snippet should be (gdom/setProperties svg-dom #js {:x 20 :y 20})

rainmote06:12:49

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?

rainmote02:12:02

@U7DKLTCQJ it's cool, thanks. @U1VSXM85B it’s better for mobile apps, thanks

tomc17:12:11

Is there a way to translate this code into cljs without atoms? var k = setInterval(function(){ clearInterval(k) }, 300);

leonoel17:12:11

@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

leonoel17:12:35

(place [k (js/setInterval #(js/clearInterval k) 300)])

tomc17:12:26

@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.

noisesmith17:12:13

@leonoel @tomc you can refer to a function from itself (fn foo [] (something foo)) is valid

noisesmith17:12:57

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))

noisesmith18:12:36

but it turns out `(fn k [] (js/setInterval #(js/clearInterval k) 300))` doesn’t work - it just looped on me

leonoel18:12:22

@noisesmith I'd like to be proven wrong, but I can't think about a strategy without any assignment of some kind

noisesmith18:12:54

@leonoel I think it would work with a defn - not sure though

noisesmith18:12:42

fn / defn already assign to the function object, but that seems not to work with setInterval (at least like that)

mfikes18:12:11

I’m curious if a truly abusive, evil, js* hack would work:

(let [k (js/setInterval #(js/clearInterval (js* "k")) 300)])

phronmophobic19:12:37

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

noisesmith19:12:36

ahh of course! - thank you

noisesmith19:12:25

(def k (delay (js/setInterval #(js/clearInterval @k) 300)) might work in that case

noisesmith19:12:46

if cljs has delay

mfikes19:12:11

@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.)

phronmophobic19:12:53

advanced compilation will rename variables

phronmophobic19:12:09

but not the string

mfikes19:12:13

Well, if it renamed k to, say a, it would name both places

mfikes19:12:19

Oh… the main aspect is no string is involved

mfikes19:12:02

(let [k (js/setInterval #(js/clearInterval (js* "k")) 300)]) gets turned into

(function (){var k = setInterval((function (){
return clearInterval(k);
}),(300));
return null;
})()

phronmophobic19:12:19

under advanced compilation?

mfikes20:12:31

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.

mfikes20:12:44

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.

phronmophobic20:12:01

I stand corrected then

phronmophobic20:12:20

it does make the assumption that let will always use the same variable name as your binding

mfikes20:12:23

No problem. Was just curious if you were seeing something I wasn’t.

mfikes20:12:33

Yes, the js* hack is fragile.

mfikes20:12:03

If, for example you had this, it would break

(let [k 1 k (js/setInterval #(js/clearInterval (js* "k")) 300)])

phronmophobic20:12:04

weird, I just ran it through advanced compilation and got setInterval(function(){return clearInterval(k)},300);

phronmophobic20:12:32

with no assignment to k

mfikes20:12:30

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}

tony.kay20:12:16

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?

dnolen20:12:19

@tony.kay we produce an AST node for protocols I’m pretty sure, I would just look at that

dnolen20:12:55

the protocol will be a var in the ns and that var will have :protocol-info, and in there you will have :methods

ranmacar22:12:56

hello! just starting out with clojure(script), and stumbled upon this example: http://blog.klipse.tech/clojure/2016/10/10/defn-args-2.html

ranmacar22:12:48

sadly, it doesnt seem to work anymore, could the spec of defn have changed since then?

ranmacar22:12:51

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]

phronmophobic22:12:57

what is the {:something "sad"} ?

phronmophobic22:12:08

doesn’t seem like that belongs

ranmacar22:12:35

just dummy metadata, doesnt affect the error 🙂

phronmophobic22:12:57

meta data needs the ^, eg. ^{:something "sad"}

ranmacar22:12:17

ok, thanks, still need to learn the syntax quirks

ranmacar22:12:09

what i tried is to go along the 2 part example

ranmacar22:12:52

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

phronmophobic22:12:14

even with the meta data correction?

ranmacar22:12:37

yeah, even without any metadata there

phronmophobic22:12:12

that’s really weird, because the only keyword is in the metadata map you provided

phronmophobic22:12:30

although, I guess I’m not that familiar with the defndoc macro

ranmacar22:12:37

thats just a toy example from the article, extends defn to "decorate" the docstring

phronmophobic22:12:51

so it’s barfing on (my.spec/defndoc foo "docs" [a b] (+ a b))?

ranmacar22:12:46

i am running it in lighttable from a chestnut project

ranmacar22:12:07

[org.clojure/clojure "1.8.0"] [org.clojure/clojurescript "1.9.671" :scope "provided"] [org.clojure/spec.alpha "0.1.143"]

phronmophobic22:12:36

seems like the above should work

phronmophobic22:12:46

the code on the page is live

phronmophobic22:12:03

you get the same error if the arguments to defndoc aren’t right

phronmophobic22:12:31

is it possible that the code isn’t being recompiled?

ranmacar22:12:43

maybe, how would i see that?

ranmacar22:12:49

I've copied all the code over to lighttable, and ran the examples