Fork me on GitHub
#clojurescript
<
2017-02-01
>
richiardiandrea00:02:34

apparently there is a feed now, I am going to try it right away https://github.com/zealdocs/zeal/issues/170#issuecomment-269930023

aj taylor01:02:00

I’m trying to receive a request using cljs-http. While running my tests with lein doo phantom, I receive a -1 status and an empty string as the body. However, when I run the test in the repl, I am able to retrieve the request data. Is this because a channel is being returned first? Or maybe I need to implement a timeout to wait for the request to complete?

thedavidmeister03:02:03

the recommended approach in js is to check foo === foo, can i rely on the same behaviour in cljs? i.e. (= foo foo)

thedavidmeister03:02:46

a quick noodle in the cljs repl says this should be ok

thedavidmeister03:02:53

but are there edge cases i might need to consider?

anmonteiro03:02:55

@thedavidmeister you can use (== foo foo)

anmonteiro03:02:05

== is for numbers

thedavidmeister03:02:14

i didn't know about that one

anmonteiro03:02:28

cljs.user=> (== NaN NaN)
false
cljs.user=> (def foo NaN)
#'cljs.user/foo
cljs.user=> (== foo foo)
false

thedavidmeister03:02:11

oh actually looks really useful

thedavidmeister03:02:29

i've had to do some weird juggling of number types in the past because i didn't know about this

bones04:02:11

What interface do I have to implement in order to destructure HTMLCollection?

bones04:02:04

Hrm, I Implemented ISeqable, which enabled me to use “first” and “second”

bones04:02:46

But I really wanted to do [a b] (dom/getChildren switch) type thing

bones04:02:26

But when I try that I get “nth not supported”, so I’m trying to implement IIndexed

bones04:02:56

But now I get TypeError: coll.cljs$core$IIndexed$_nth$arity$3 is not a function

bones04:02:22

my implementation is `IIndexed (-nth [array i] (get (array-seq array) i)))`

anmonteiro04:02:24

@bones did you implement ISeq though?

bones04:02:38

`(extend-type js/HTMLCollection ISeqable (-seq [array] (array-seq array 0)) IIndexed (-nth [array i] (get (array-seq array) i)))`

anmonteiro04:02:49

I don't see ISeq

bones04:02:03

Do i still need ISeq atop ISeqable?

bones04:02:17

is that for next more and so on?

bones04:02:31

Should I be able to look up protocols from the REPL?

bones04:02:39

to see what they need?

bones04:02:55

like (doc IIndexed) ?

anmonteiro04:02:59

sure

cljs.user=> (doc ISeq)
-------------------------
cljs.core/ISeq
Protocol
  Protocol for collections to provide access to their items as sequences.

  -first
  ([coll])
  Returns the first item in the collection coll. Used by cljs.core/first.

  -rest
  ([coll])
  Returns a new collection of coll without the first item. It should
     always return a seq, e.g.
     (rest []) => ()
     (rest nil) => ()
nil

anmonteiro04:02:05

^ this is in Lumo

anmonteiro04:02:32

works in a normal (JVM) CLJS REPL too

bones04:02:02

Hrm, okay, I had to use find-doc “ISeq”

bones04:02:07

thanks for your help

thegeez12:02:18

when compiling clojurescript to .js files, how can I force macro namespaces to be compiled to .js files too? This is to then use the $macros.js with self hosting

thegeez12:02:29

@tomaas are you using CORS? sounds like your preflight route also requires the x-access-token and x-key headers

len13:02:21

We are building a couple of apps and parts will be common - panels / backend calls etc. is there anything I can read or any pointers on how to structure such a thing

Aron14:02:28

https://clojure.org/reference/datatypes - deftype and defrecord dynamically generate compiled bytecode for a named class

Aron14:02:33

what does that even mean??

Aron14:02:44

i feel that this page is talking about Java, not clojure

Aron14:02:49

is there a clojure version?

dnolen14:02:00

@ashnur many things just got copied over from Clojure, feel free to send PRs with corrections

dnolen14:02:09

you just need to have submitted your CA

Aron14:02:17

again, asking the newbie to do the work of the pros

moxaj14:02:54

@ashnur you linked the clojure related stuff, I don't see the problem

Aron14:02:18

moxaj i don't even know which documentation to use

Aron14:02:46

trying to figure out how to use protocols

moxaj14:02:54

@ashnur regarding your question, deftype and defrecord generate actual java classes

manutter5114:02:57

@ashnur I believe the description you linked to is saying that, under the hood, deftype and defrecord are building what java would call a class

manutter5114:02:13

or technically “the same bytecode that would have been generated by a Java class"

moxaj14:02:28

also, "again, asking the newbie to do the work of the pros" -- i'm sorry?

Aron14:02:17

moxaj every time i ask something sooner or later i am told that i should write the docs

Aron14:02:40

no wonder the docs suck if the newbies are writing it, is my usual reply, i don't see the logic behind the concept

moxaj14:02:07

first off, this is the clojurescript channel, so @dnolen assumed you've found something that was incorrectly ported over from the clojure docs

Aron14:02:13

@moxaj, and i used the clojure docs because i did not found clojurescript specific documentation about defprotocol or protocols

Aron14:02:17

also, i watched this, but it only tells half the story https://vimeo.com/11236603

dnolen14:02:43

@ashnur oh sorry I missed you were talking about http://clojure.org

dnolen14:02:04

@ashnur what are you looking for specifically? most of the deftype docs for Clojure apply to ClojureScript

dnolen14:02:27

we could make a page for ClojureScript specifically about the small differences + document specify

dnolen14:02:39

someone should do that - and anyone can, not suggesting it should be you @ashnur

Aron14:02:33

@dnolen i am just trying to understand how protocols can be used, i have to implement a graph lib and i would like to do it nicely

moxaj15:02:02

@dnolen I get WARNING: Cannot infer target type in expression (. Foo -prototype) ... for a simple (defrecord Foo []), I assume this is not intended? This seems like it should be common enough, but I don't see a jira ticket.

kardan15:02:58

(to learn about protocols)

Aron15:02:33

i tried to read that book so many times, but it's not for me

Aron15:02:47

anyway, will try to read again, at least that part

dnolen15:02:55

@moxaj a minor ticket yes

dnolen15:02:08

what we currently have wasn’t designed to mix interop nses with normal nses

moxaj15:02:12

@dnolen just to clarify, you mean there's a minor ticket already (which I can't find), or that i'm free to file one?

thegeez15:02:45

@dnolen is there a way to get the closure compiler to compile all macro namespaces for use with self hosting? So that you can have load-fn use a .js and cache file for macros instead of clj/cljc sources?

dnolen15:02:28

@thegeez perhaps - but we’re not changing anything around self-hosting

dnolen15:02:14

@thegeez hrm, I don’t really understand what you’re asking for - mislead here by your mention of Closure Compiler

dnolen15:02:25

I’m pretty sure you can compile macro nses into js and cache files

dnolen15:02:32

@mfikes could confirm

thegeez15:02:04

hmm yes, I should have said clojurescript compiler

thegeez15:02:04

I mean when cljs.js is required, then core$macros.js is generated. I was hoping there was a way to get all macro namespaces to be generated as such

mfikes15:02:14

@thegeez You can, as an AOT step, require macros namespaces and then cache the results. This is in fact what Planck and Lumo do for certain namespaces so that they can subsequently be required w/o actually having to convert them to JS. More info is here http://blog.fikesfarm.com/posts/2016-02-03-planck-macros-aot.html

thegeez15:02:09

@mfikes thanks, I'll try going down that route

Aron15:02:33

ok, so now i understand the syntax (i think) but i have this issue that i can't see the difference between the protocol and the record. I both want them named Graph

Aron15:02:38

what am i missing still?

Aron15:02:12

like, i want a graph lib that has methods such as erdos-renyi or watss-strogatz that generate random graphs

thheller15:02:20

@ashnur it is fairly common to prefix the protocol with an I to indicate what would be an interface in java. ie. (defprotocol IGraph ...) and (defrecord Graph ...)

Aron15:02:00

ok, so by convention i should just put an I in front of the protocols name so i can have IGraph protocol and Graph record

Aron15:02:48

i never used interfaces, not in java not elsewhere, so that part i don't know

thheller15:02:35

people use all sorts of naming but the I version is most common I think. clojure and cljs do that all over the place

Aron15:02:48

i see, thanks

nrako18:02:24

How might one get the data attribute from the DOM? I keep seeing record-id = null.

thheller18:02:35

@nrako that is an attribute, so (-> target (.getAttribute "data-record-id")) should work

nrako18:02:10

It does indeed work. Many thanks...

thheller18:02:36

depending on the browser you can do (.. target -dataset -dataRecordId) but getAttribute is safer

thheller18:02:46

also that won't survive advanced comp

thheller18:02:51

so stick with attribute 😉

borkdude19:02:34

In lumo, should I use (.-argv js/process) to get the command line args?

anmonteiro19:02:34

there's also lumo.core/*command-line-args*

borkdude19:02:54

@anmonteiro is that available from a script?

anmonteiro20:02:07

but depends on what you want

anmonteiro20:02:35

*command-line-args* works like clojure.main

borkdude20:02:28

@anmonteiro I get this: WARNING: No such namespace: lumo.core, could not locate lumo/core.cljs, lumo/core.cljc, or Closure namespace "" at line 3 W

anmonteiro20:02:42

need more info

anmonteiro20:02:48

Lumo version, did you require lumo.core?

borkdude20:02:10

Ah, that’s it 🙂

borkdude20:02:19

@anmonteiro Should the cache work if I run lumo only with a script?

anmonteiro20:02:35

What do you mean? Can you paste the command you're running?

borkdude20:02:05

@anmonteiro I mean, say you have a file script.cljs with only (println “foo”) and you call it with lumo -K script.cljs

borkdude20:02:20

@anmonteiro should this compile anything into the cache

anmonteiro20:02:23

Probably not

anmonteiro20:02:40

Only of you require stuff

borkdude20:02:56

@anmonteiro this is my script now: https://gist.github.com/borkdude/a6a87796dfe26218a5e9164a84545790 I call it with ./node_modules/lumo-cljs/bin/lumo -K script.cljs <some-file>, but the cache stays empty. Maybe lumo only caches compiled things from the “init path” or “class path". But with the -i option I couldn’t pass a command line arg.

anmonteiro20:02:52

@borkdude: I'm busy right now, but feel free to open an issue with an example that I can look at later

borkdude20:02:12

@anmonteiro ok, I will and thanks!

piotr-yuxuan21:02:32

I’ve been trying to use Leiningen and Stuart's "Clojure Reloaded" workflow so I got a file user.clj on my source path that transitively requires a couple of Java classes in my project and despite some efforts I keep stumbling upon ClassNotFoundException. It appears to be reported in some issues (e.g. https://github.com/technomancy/leiningen/issues/1245) but unfortunately there are no well-known solutions 😕 How have you guys deal with this?

dnolen21:02:00

@piotr2b might want to also try #clojure for that particular question

dragoncube22:02:04

is there any JS or CLJS library for GraphQL which could be used from CLJS out-of-the-box?

michael.heuberger22:02:07

does anyone know a cljs lib that has a deep merge fn for maps?

mfikes22:02:26

@michael.heuberger Like merge-with but deeper?

michael.heuberger22:02:16

but hasnt been ported yet

mfikes22:02:13

That one seems to work just fine in ClojureScript

mfikes22:02:24

(Assuming you copy it.)

michael.heuberger22:02:28

yeah, could do but dont want to copy/reinvent or so if possible