Fork me on GitHub
#clojurescript
<
2016-05-25
>
pbaille09:05:27

Hi, what is the simplest way to convert js/Date to goog.Date?

pbaille09:05:39

i’m using cljs.time if it helps

anmonteiro09:05:03

I’m aware it’s not a direct answer to your question but I thought it might help

pbaille09:05:32

yes i’m receiving a transit datastructure from the server containing #inst object, that became js/Date instance on the client

pbaille09:05:55

and I would like to turn it into goog.Date

pbaille09:05:30

am i suppose to convert it to string and parse the string with cljs.time in order to create goog.Date instance?

Petrus Theron11:05:26

Is there something like react-refetch for ClojureScript? https://github.com/heroku/react-refetch

urbanslug13:05:28

Calling map on side effecty functions doesn’t work, does it?

anmonteiro13:05:35

@urbanslug: works, but probably best to use run!

anmonteiro13:05:37

same signature

urbanslug13:05:21

Hmm why would this fail (map (fn) (fn-that-returns-a-map)) ??

manutter5113:05:44

Returns a map? Not a seq?

anmonteiro13:05:06

@urbanslug: you probably want (map fn (fn-that-returns-a-map))

anmonteiro13:05:22

if (fn) doesn’t return another function, that is

anmonteiro13:05:28

hard to know without seeing it

urbanslug13:05:52

well it’s really (map #(…) (fn-that…))

anmonteiro13:05:10

care to post a minimal case of what’s not working for you?

urbanslug13:05:22

Let me try to.

manutter5113:05:37

So the anonymous function is going to get a vector containing a key/value pair, is that what it’s expecting?

urbanslug13:05:55

No it’s going to get a list

urbanslug13:05:27

hmm I guess I was doing something like (fn [n] (prn n))

anmonteiro14:05:24

should work too

manutter5114:05:59

You might want something like (map (fn [[k v]] (do-something-with k v)) (fn-that-returns-a-map)), so your keys and values get destructured into separate args

urbanslug14:05:09

hmmm think I see the issue. map returns a sequence (lazy) but takes a collection is there a difference between this? There has to be. Also I’ll force a vector with (vec (map…))

anmonteiro14:05:36

@urbanslug: my preferred approach is to use into with a transducer

anmonteiro14:05:54

e.g.: (into [] (map fn) coll)

anmonteiro14:05:48

whenever I want a vector out, that is

arkh14:05:14

(vec (map ...)) and (into [] (map fn) coll) is also equivalent to (mapv ...)

urbanslug14:05:18

arkh: Nice I didn’t know about (mapv …)

arkh14:05:00

(into ...) is more generally applicable but (mapv ..) is more succinct

urbanslug14:05:46

(let [keys (into [] (map #(str "ba" %) ["br" "bro"]))]
  (println “br”)
  (map #(println %) keys))

urbanslug14:05:05

br prints but second one doesn't

arkh14:05:46

map is lazy so it needs to be realized

urbanslug14:05:14

I knew this had to do with laziness!

urbanslug14:05:27

more like had a hunch

arkh14:05:23

in your code above, you'll notice that it doesn't print anything but it will return a LazySeq

arkh14:05:24

and that LazySeq is map 'ready' to run your function over its collection

urbanslug14:05:37

@arkh: Thanks a ton it makes sense

vinnyataide20:05:56

hello, i've come uppon this particular code in om next and having a hard time figuring what .. means

(om/set-query! ac
  {:params {:query (.. e -target -value)}})

vinnyataide20:05:13

I can see it applies the event to those arguments but i cant see how the - and e works with it

vinnyataide21:05:19

and macroexpand dont seems to work

noonian21:05:50

the .. is a macro built into Clojure. Its basically method chaining in javascript i.e. e.target.value

vinnyataide21:05:11

yeah i could see. but why is it so funky

noonian21:05:19

you have to use (.-propName obj) syntax for properties in cljs

vinnyataide21:05:36

oh so its in clojure? I've searched the docs and couldnt find anything

noonian21:05:46

yeah, but you don’t see it as often with Java interop in my experience because you are rarely grabbing instance properties (usually just grab methods or static members): http://clojure.org/reference/java_interop

rohit21:05:36

Hi all, I am experiencing a really strange clojurescript bug.

rohit21:05:52

I’ve created a repo explaining it here: https://github.com/ducky427/cljs-bug

rohit21:05:43

essentially a map I am getting back from converting an edn string to a map using cljs.reader/read-string isn’t behaving like a map at all

rohit21:05:10

and this weirdness only occurs under some very very particular circumstances

rohit21:05:29

I’ve been able to able to narrow it down to as little user code as possible.

rohit21:05:54

and its possible to reproduce it without the use of lein or boot or any library

rohit21:05:30

Any help would be really appreciated. A co-worker and I have spent better part of 2 days to figure it out and are completely lost now

richiardiandrea21:05:52

@rohit: good job at shrinking down the example, probably you can drop it in #C07UQ678E as well

richiardiandrea21:05:44

Or open a jira ticket directly

rohit21:05:10

I’ll do that as well. I thought if someone can identify the actual issue, then its worth creating a jira issue.

richiardiandrea21:05:57

Yeah well it looks like part of the reader, but I will leave the scene to core devs ;)

darwin21:05:47

I’m not sure how to run it, java noob here, have been happily living with lein for 1+ yrs

rohit21:05:13

lol. ok let me also create a project.clj for it

richiardiandrea21:05:40

I many times had strange behaviours with disparate node versions, especially regarding IO...in replumb I stick with 0.12.7 for now...

rohit22:05:19

just pushed a project.clj file

rohit22:05:51

lein cljsbuild once dev and then node main.js should get you to the error

rohit22:05:45

@darwin: figured out why it didn’t work the first time around - i hadn’t committed the .jar file. d'oh

rohit22:05:54

its done now

darwin22:05:40

have to go...

rohit22:05:07

cool. glad you were able to reproduce it

peterschwarz22:05:52

@rohit might be helpful if you start reducing the values in the edn file you have, just to narrow it down. When I run it with empty values

{:pnodes []
 :settings {:monitor false, :validation false},
 :sdata {}
 :data-files #{ },
 :version "1.5"}
I get
java -cp cljs.jar:src clojure.main node.clj
node main.js
(:settings :sdata :data-files :pnodes :version)
1.5
:version key is present

rohit22:05:26

@peterschwarz: thing is if i do that, it works as expected

rohit22:05:36

so its something about the size

peterschwarz22:05:40

Maybe not size, but perhaps something in the data? It's not really a huge string...

rohit22:05:41

it almost feels like (in a very unscientific) the large datastructures somehow push cljs over a limit of some sort.

rohit22:05:57

so just commenting out some code, makes the program work as expected

rohit22:05:10

so it isn’t just the data

rohit22:05:05

I arrived on how to get rid of the error by just trial and error.

rohit22:05:14

and it makes no sense to me

richiardiandrea22:05:46

@rohit another idea would be to check what the code compiles (transpiles sorry) to and try to execute it in node or even some JavaScript engine, maybe you've done that already

rohit22:05:41

i’ve done that already. i could create a browser based test but then it would require a remote call to get the data

rohit22:05:24

let me see if i can embed that string into a cljs file safely

richiardiandrea22:05:38

Just to check if it is cljs on node only

rohit22:05:19

i’ve got the code translated for the browser as well here: https://github.com/ducky427/cljs-bug-browser

rohit22:05:28

still the exact same behaviour

richiardiandrea22:05:20

great this is more likely to be a Cljs bug then

rohit22:05:44

the bug feels like its in when the cljs.core/PersistentHashMap datastructure is being created

rohit22:05:26

if i make the result a cljs.core/PersistentArrayMap, it behaves as it should.

richiardiandrea22:05:04

after the read-string?

rohit22:05:23

the read-string returns a cljs.core/PersistentHashMap

rohit22:05:37

i convert it to a cljs.core/PersistentArrayMap and it all works

rohit22:05:14

array-map has just a performance improvement over hash-maps for small maps

rohit22:05:21

so an implementation detail

rohit22:05:29

the behaviour is supposed to be exactly the same

richiardiandrea22:05:33

what if you try tools.reader there?

richiardiandrea22:05:42

yes but it is probably copying it over

richiardiandrea22:05:14

[org.clojure/tools.reader "1.0.0-beta1"]

rohit22:05:21

let me try that

richiardiandrea22:05:34

[clojure.tools.reader :as reader]

rohit22:05:14

its [cljs.tools.reader :as reader] it seems

rohit22:05:26

nope it has the same behaviour

richiardiandrea22:05:27

well, I would then report all these results in #C07UQ678E and maybe open a JIRA ticket

rohit22:05:46

@richiardiandrea: thanks for the help.

rohit22:05:55

gonna call it a night now.

richiardiandrea22:05:59

I wish I could have helped more 😉

rohit23:05:57

its fine.

rohit23:05:13

really appreciate it