Fork me on GitHub
#clojurescript
<
2016-10-11
>
darwin00:10:48

@jasonjckn AFAIK implements? is cheaper, it just checks that property with munged protocol name exists, satisfies? will go and check the real type match, disclaimer: I might be completely wrong

jasonjckn00:10:27

the source code seems to match your understanding

jasonjckn01:10:24

@anmonteiro you were right there was no 'macro meta data'

iku00088806:10:20

Hi, is there a cljs way for 'popping up' an image on click?

pesterhazy08:10:21

@iku000888 nothing cljs specific about that - just do it as you would in javascript

iku00088808:10:34

@pesterhazy Thanks. The hope was finding a solid choice because I am confused what to do even in JS land (quick googling shows me like infinite alternatives...)

misha08:10:52

how can I def/`defn` things by var name (string) instead of symbol? something like (def (symbol "foo") 1), but actually working.

anmonteiro09:10:12

@misha: need a macro for that

anmonteiro09:10:14

(defmacro defvar [name init]
  `(def ~(symbol name) ~init))

anmonteiro09:10:29

Something like that should work ^

misha09:10:41

@anmonteiro yeah, trying similar, but I can't define macro in cljs repl, can I?

anmonteiro09:10:19

Macros need to be defined in Clojure

anmonteiro09:10:42

You can require them in the REPL after they've been defined

misha09:10:05

cljs.user=> (defmacro bar [] 1)
true
true is misleading then : )

anmonteiro09:10:43

Yeah if you try to invoke it you'll get wrong arity

misha09:10:06

which is even more misleading

anmonteiro09:10:27

It's because of &env and &form

anmonteiro09:10:57

Macros need to be defined in a separate compilation stage. Which is why they're defined in Clojure

anmonteiro09:10:18

They're expanded in Clojure (in the CLJS analyzer)

misha09:10:38

I remember that, didn't actually try to write any in cljs repl before. thank you, @anmonteiro

reefersleep09:10:41

@misha good point about true being misleading 🙂

misha09:10:46

sweet, that works, but I suspect, that's not a good production-ready macro, @anmonteiro kappa

misha09:10:23

at least I have a starting point now, thanks again

anmonteiro09:10:27

Well that was just an example to get you going :-)

anmonteiro09:10:37

Up tou you to make it production ready

chrisetheridge10:10:32

is it possible to create a function, with normal defn, but not namespace it in cljs?

chrisetheridge10:10:56

ie, if i have (defn foo [] ...) in foo.bar, i don't want to call it from js with foo.bar.foo()

martinklepsch10:10:08

@biscuitpants (set! js/foo foo) maybe?

martinklepsch10:10:06

I don't think you can defn straight into the global js namespace

chrisetheridge10:10:47

oh shit that worked! thank you so much @martinklepsch. did not know you could do that

moxaj10:10:26

are leftovers from previous cljs builds supposed to 'influence' new builds?

martinklepsch11:10:51

@moxaj depends on the build tool you're using

martinklepsch11:10:31

@moxaj I think with lein/figwheel/cljsbuild it's recommended to remove the previous build artifacts if something weird starts happening

martinklepsch15:10:13

Is there a way to get a kind of "namespace -> time to compile" map to figure out why incremental compiles take long?

dnolen15:10:07

@martinklepsch seems useful for :verbose true - I think I even considered it at one point

dnolen15:10:22

simple patch really

johanatan16:10:35

Hi, sorry if this has been discussed already but what does yarn mean for the CLJS (lein/boot) ecosystem?

dominicm17:10:50

Probably little? Npm is not interacted with much from cljs

dominicm17:10:15

I'm pretty sure it uses the npm repository too. So there's no migration period.

dominicm17:10:32

Unless I'm missing something @johanatan

dnolen17:10:25

for people who are using deps from NPM I suspect maybe someone will provide Boot/Lein plugins for Yarn

dnolen17:10:26

that’s about it

johanatan17:10:35

There is a lein plugin called "lein-npm"

dnolen17:10:40

but it doesn’t have anything to do with ClojureScript in general

johanatan17:10:11

Is there some alternative to "using deps from NPM"? i.e., if you're doing Node.js development, then it's almost a given that you will need some NPM modules (less so on frontend but, even there, there is that risk)

dnolen17:10:24

many people using ClojureScript aren’t using deps from NPM, if they are they building a single foreign dep

martinklepsch17:10:54

Been off twitter for the day and there's a new big thing in JS 😄

moxaj18:10:17

@mfikes re :const var failing with :parallel-build on .. One of my source files is compiled twice. It fails the second time. This is me right now: http://i.imgur.com/Br00TCn.gif

mfikes18:10:57

@moxaj The compiler takes the namespaces in all of your source files, forms a dependency partial order from them, and then a topological sort of that, and uses that for parallel compilation. So, it should compile each file once and only once.

dnolen18:10:54

@moxaj hrm, you should be able to see what is compiling twice without :parallel-build

dnolen18:10:07

and as @mfikes said, shouldn’t be happening

mfikes18:10:26

Perhaps it can happen if ns forms are not right in some way? Hrm.

mfikes18:10:16

This could also perhaps explain a race being provoked in gensym code...

pvinis18:10:18

how can i do apply in a dot function (js interop)

pvinis18:10:18

i wanna do (apply .alert (.-Alert ReactNative) title rest)

pvinis18:10:56

i get unexpected .

dnolen18:10:34

you can use primitive .apply

pvinis18:10:44

oh.. .apply

pvinis18:10:50

i dont know that

dnolen18:10:23

(.apply (.. ReactNative -Alert -alert) nil #js [title rest])

pvinis18:10:03

is there some documentation for .apply?

moxaj18:10:13

@mfikes but if I had a circular dependency, the compiler would surely warn me?

pvinis18:10:26

i did what you wrote, but i get a red screen with some json value

pvinis18:10:13

what is the nil doing actually?

mfikes18:10:36

@moxaj If all the ns forms are correct in all namespaces in your project, then yes you should get a warning if a circular dependency exists.

pvinis18:10:43

(.apply (.. ReactNative -Alert -alert) nil (clj->js (cons title rest)))) did it like that

pvinis18:10:57

i had to cons the title and rest

dnolen18:10:48

@pvinis #js [title rest] should work, that’s all your code is doing except less efficiently

pvinis18:10:14

for some reason i get a red box with that

pvinis18:10:36

btw, awesome that you are coming to vienna later this month. i will be in the meetup too

pvinis18:10:36

title is a string and rest is a vector. is that cool for your version?

johanatan18:10:46

#js does not recurse

dnolen18:10:02

@pvinis #js [title rest] compiles to a JavaScript array with two elements in it

pvinis18:10:17

ah, so maybe i get the red box because its clj stuff in there?

dnolen18:10:24

they will be whatever you provided

dnolen18:10:29

right I don’t know what those values are

dnolen18:10:34

or what they need to be

johanatan18:10:34

you need: #js [title #js rest]

dnolen18:10:44

@johanatan that’s not valid

pvinis18:10:45

i need an array with title, and rest1 rest2 etc

pvinis18:10:54

so i need to expand rest

johanatan18:10:05

then I suppose (clj->js [title rest]) it is

dnolen18:10:34

@pvinis ok, then what you have is fine

pvinis18:10:42

rest is [r1 r2 r3], and i need [title r1 r2 r3]

dnolen18:10:50

I would probably just write (into-array (cons title rest))

pvinis18:10:53

i got a bit confused before

pvinis18:10:13

awesome. thanks 😄

johanatan18:10:11

@dnolen oh, that's right. #js escapes so a double-escape wouldn't work

dnolen18:10:46

@johanatan nothing to do with escaping

dnolen18:10:53

the reason is much simpler

dnolen18:10:06

#js […] and #js {…} are the only valid options

johanatan18:10:41

oh, so would this work: #js [clj-val #js [another-clj-val]] ?

dnolen18:10:47

absolutely

johanatan18:10:54

oh interesting. Good to know.

pvinis18:10:29

yea, i think clj->js basically does what putting #js everywhere does, recursively

dnolen19:10:59

@pvinis but it’s important to understand one is runtime and one is compile time

dnolen19:10:15

you should be conservative with cljs->js, the perf hit is huge as your data structure increases in size

dnolen19:10:26

I never use it

pvinis19:10:50

oh, didnt know #js is compile time and clj->js is run time

pvinis19:10:53

good to know

moxaj19:10:01

@dnolen trying to insert printlns-s into cljs.compiler/compile-root, but apparently they have no effect. spit doesn't work either. Happen to know why?

dnolen19:10:18

@moxaj I don’t know why you are doing that

dnolen19:10:30

:verbose true compiler option should be enough

moxaj19:10:21

@dnolen already using that. And the reason - cljs.js-deps/dependency-order already receives the same namespace twice (for some reason, println works there), so I'm trying to track the input backwards

anmonteiro19:10:16

@moxaj the thing in cljs.compiler is that *out* is probably bound to the file your outputting

anmonteiro19:10:29

if you want to print something out you probably need to bind it to *err* first

moxaj19:10:47

@anmonteiro i'll give it a try, thanks!

anmonteiro19:10:15

that said, I don’t know what you’re trying to do

anmonteiro19:10:26

so you should probably listen to David first

moxaj19:10:40

tryint to see where my namespace gets duplicated during the compilation

dnolen19:10:18

@moxaj we need to see what the :verbose true output actually is

dnolen19:10:31

you say it’s the same file but is it?

moxaj19:10:00

@dnolen this is what dependency-order receives

moxaj19:10:50

@dnolen contains mikron.common.math twice - once with a java.io.File source, once with a java.net.URL source, strange

dnolen19:10:30

@moxaj well not completely unexpected to me at least - you’re compiling a directory of sources and then we also need to resolve stuff on the classpath

dnolen19:10:42

being on Windows is also another wrinkle

dnolen19:10:18

@moxaj it will be useful if you can minimize this issue into a simple project that someone else can run

dnolen19:10:45

without a way to reproduce - there’s too many possibilities to consider

moxaj19:10:07

@dnolen yeah, I feared windows is part of the problem 😕

dnolen19:10:18

I don’t know if it is

dnolen19:10:25

but at this point - impossible to say - we have no way to reproduce

moxaj19:10:08

@dnolen i'll keep digging. thanks for the help!

neurogoo20:10:28

I have been thinking of building program to stream my media, mini-plex basically, as a learning exercise. Is there any libraries that you recommend for streaming local video and/or audio?

yury.solovyov20:10:10

Is that ok when learning Clojure(Script) your code is more like procedural, rather than functional?

yury.solovyov20:10:32

I mean it feels like so

shaun-mahood20:10:13

@yury.solovyov: I think so, that's how I've learned / continue to learn - once it's working it's pretty easy and informative to refactor into a more idiomatic style.

yury.solovyov20:10:26

A while ago I looked for a way to make parameter optional, and I even found a similar question on SO, but it turned out that you just use multiple arity

dnolen20:10:29

@yury.solovyov I’m not sure what you are asking but if you’re trying to import JS idioms around optional parameters, then yes I would avoid that

yury.solovyov20:10:09

Nah, I just share my UXs

dnolen20:10:00

@yury.solovyov if the question is just more general - then yeah, picking up a more functional style takes some time

moxaj20:10:12

@dnolen I believe I have figured it out. in cljs.closure/add-dependency-sources, inputs has source files as java.io.Files. When we add the dependencies, those are java.net.URLs. So even though inputs is a set, many elements will be duplicated because they differ on :source-file. Casting those java.io.Files to java.net.URLs eliminated the error. Now to make a repro ..

thomas.williams20:10:36

Hi all, sorry, new around here. IS this an appropriate forum to ask clojurescript questions? I'm new to the community and having some issues.

dnolen20:10:53

@thomas.williams you’ve found the place 🙂

thomas.williams20:10:40

I was wondering, is there more extensive documentation for project.clj than the sample one provided on the clojurescript site? I am looking at some example project.clj files that use stuff like :

:npm {:dependencies [[react-d3-components "^0.6.0"]
                       [react-youtube "^5.0.0"]
                       [webpack "^1.12.9"]]

        :package
        {:scripts
         {:postinstall "npm run dev && npm run min"
          :dev "webpack --output-filename webpack-deps.js"
          :min "webpack --optimize-minimize --output-filename webpack-deps.min.js"}}}

thomas.williams20:10:57

I cannot find any documentation on how this :npm field works. Or exactly what it does.

dnolen21:10:13

@thomas.williams I’m assuming that requires this Lein plugin https://github.com/RyanMcG/lein-npm

dnolen21:10:32

@thomas.williams but more importantly, can you be more clear what you are asking about?

thomas.williams21:10:41

Is there a good way to find these plugins?

thomas.williams21:10:57

I am just trying to learn how to figure out how things work in this file 🙂

thomas.williams21:10:03

resources that are good for research

thomas.williams21:10:05

and documentation

thomas.williams21:10:16

So, for example, how did you find that plugin?

dnolen21:10:20

there’s a lot of stuff still just on the wiki https://github.com/clojure/clojurescript/wiki

dnolen21:10:28

fortunately there’s not that many common/popular plugins

shaun-mahood21:10:19

@thomas.williams: Anecdotally, I've been using CLJS for quite a while and have never needed to use any plugins - there's a ton of stuff available within the CLJS world, so unless you have the need to use a particular plugin it's probably safe to ignore that part of project.clj and work on other things for a while.

mac21:10:12

@juhoteperi Are you by any chance the person who created the pouchdb-find package?

darwin22:10:25

as part of Dirac documentation effort I wrote this article on REPLs: https://github.com/binaryage/dirac/blob/master/docs/about-repls.md

tomjkidd22:10:14

@darwin This is neat, what did you use to create your diagrams?

arohner22:10:13

I’m sure I’m doing something stupid, but in https://github.com/arohner/om-html/blob/master/src/om_html/html.cljc, when I try to call html/html, I’m seeing WARNING: Wrong number of args (1) passed to om-html.html/html at line 6

arohner22:10:19

In recent clojurescript (1.9.229), it’s legal to define a macro in .cljc, and require it without a require-macro, right?

jr22:10:15

you have to self require the macro in a cljs reader conditional

jr22:10:03

(ns my.namespace
  (:require-macros my.namespace))

arohner22:10:10

@jr I’m not using om.html/html in html.cljc, so why does it need to self-require?

arohner22:10:15

also why does the wrong number of args happen?

jr22:10:56

how are you invoking om-html.html/html?

arohner22:10:05

in .cljs, (:require [om.html :as html])) (html/html [:div.foo]))

arohner22:10:18

everything works fine in .clj

arohner22:10:29

so I suspect a CLJS macro issue that I don’t understand