Fork me on GitHub
#clojurescript
<
2017-01-15
>
seancorfield00:01:08

Hi… If there’s anyone here who uses the Expectations testing framework (in Clojure) and would like to help me get the ClojureScript version working properly, I’d appreciate the help in #expectations as I’m not familiar enough with cljs (and, in particular, .cljc behavior) to solve some problems getting the tests to run cleanly. Thanks!

qqq08:01:18

========== possible "bug" report (or I'm an idiot ==========

(defrecord foo [foo]) 
^^ above code, which I do not suggest anyone ever use, appears to work in clj, but throws an exception in cljs about self__

qqq09:01:08

in cljs, prettyprint on functions currently prints the source of the function

qqq09:01:16

is there a way to have it just say #function_blah_id ?

gfredericks12:01:18

@qqq there should be a multimethod or protocol fn you could override

pesterhazy12:01:09

@qqq I would love that as well

pesterhazy12:01:31

If you find a solution, let me know

pesterhazy12:01:36

Clojure.pprint/pprint may behave differently from prn

gfredericks12:01:54

oh I didn't notice the prettyprint part of the question

mss13:01:46

is there an idiomatic way to convert arbitrary js objects (e.g. google closure BrowserEvents) into cljs data structures? I know there’s js->clj, but that only works on vanilla js objects

darwin15:01:12

@mss I’m a bit skeptical if this even would be possible in a general case, if given js object is not a vanilla JSON object it probably has some state and mutable api, how would you convert such thing?

mss15:01:14

I mean a simple keys to values mapping from js to cljs was what I had in mind

mss15:01:22

crux of js->cljs not working for my use case is that equality check

mss15:01:18

but maybe you’re right and there’s some rationale that I’m missing about why arbitrary js objects shouldn't be converted to cljs data structures

pesterhazy15:01:30

can you give an example of such an object?

mss15:01:54

so google closure event handlers emit a specific object type

mss15:01:42

because the type of this event is a BrowserEvent, as opposed to a vanilla js object, there isn’t an easy way to parse this into a cljs data structure without writing your own custom parsing function

mss15:01:27

which is ok in theory, I just happen to be a mediocre programmer who'd rather lean on smarter people who’ve discovered edge cases already 😜

pesterhazy15:01:12

(defn obj->cljs [o] (into {} (for [k (js-keys o)] [k (clj->js (goog.object/get o k))])))

pesterhazy15:01:27

roughly this?

pesterhazy15:01:15

seems to work on BrowserEvent

pesterhazy15:01:37

not sure it's wise to convert that to a cljs data structure though

dominicm15:01:49

Unless you're writing a library, maybe you can just create a map of the keys you need.

dominicm15:01:54

You can always add more manually later

mss15:01:08

yep I have something similar, makes sense. why do you think it’s unwise to convert to cljs tho?

pesterhazy15:01:11

you could also extend IEncodeClojure

mss15:01:26

interesting

pesterhazy15:01:32

well it gives you a bunch of internals:

cljs.user=> (obj->cljs (goog.events.Event.))
{"type" nil, "target" nil, "currentTarget" nil, "propagationStopped_" false, "defaultPrevented" false, "returnValue_" true, "stopPropagation" #object[Function "function (){this.propagationStopped_=!0}"], "preventDefault" #object[Function "function (){this.defaultPrevented=!0;this.returnValue_=!1}"]}

pesterhazy15:01:53

as @dominicm mentioned, you could just explicitly get what you need from the object

mss15:01:57

yep I think I might just go with that. just curious if there was a different solution out there

mss15:01:06

thanks for all the feedback everyone. really appreciate it

darwin16:01:57

an alternative solution could be implementing needed cljs protocols like ILookup via (extend-type BrowserEvent …), but be careful doing this on top of mutable objects, it could confuse unsuspecting reader of your code

koolkk17:01:09

Does anyone know what are the steps to get some json into datascript. If you could point me in the right direction it would be great.

koolkk17:01:06

I have a client that recieves json and i would like to know what is the best way to get that into a datascript store. Thanks.

mruzekw17:01:17

@koolkk I haven’t tried this myself, but if you’re using transit you could use https://github.com/tonsky/datascript-transit

koolkk17:01:20

Thanks @mruzekw. I saw that but i have a client that get data from a json api.

mruzekw17:01:02

How about tranlating JSON in to clojure maps via https://github.com/dakrone/cheshire Use a keyword function to match the format Datascript expects. See this as an example of getting fixtures/data into DS: https://github.com/tonsky/datascript-chat/blob/gh-pages/src/datascript_chat/server.cljs#L14-L75

lorenzoi18:01:09

any online books to start clojurescript?

yo20:01:32

I am trying out this cljs tutorial and seem to have hit a block with the "Changing Queries Over Time" section. I get nil when I run the following in a repl:

(in-ns 'om-tutorial.core)
(om/get-query (om/class->any reconciler AnimalsList))
The tutorial link is - https://github.com/omcljs/om/wiki/Quick-Start-(om.next)#changing-queries-over-time

koolkk21:01:14

@yaw its not a cljs tutorial its an om next tutorial.

yo21:01:19

Oh yea. You're right.

koolkk21:01:34

I have no time to look into your problem and i don't know om next but this tutorials are good as well: http://read.klipse.tech/om-next-interactive-tutorial/ https://awkay.github.io/om-tutorial/

koolkk21:01:16

But I think re-frame is better to start https://github.com/Day8/re-frame

yo21:01:49

Thanks!

koolkk23:01:09

@mruzekw tanks for the info