This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-15
Channels
- # aws-lambda (3)
- # beginners (17)
- # boot (65)
- # cider (3)
- # cljs-dev (7)
- # cljsrn (82)
- # clojure (82)
- # clojure-italy (1)
- # clojure-russia (25)
- # clojure-spec (56)
- # clojure-uk (5)
- # clojurescript (52)
- # css (2)
- # datomic (6)
- # emacs (1)
- # hoplon (9)
- # jobs-discuss (5)
- # leiningen (8)
- # mount (2)
- # nginx (1)
- # off-topic (2)
- # om (1)
- # om-next (9)
- # perun (13)
- # portland-or (1)
- # re-frame (13)
- # reagent (20)
- # remote-jobs (2)
- # ring (5)
- # spacemacs (1)
- # specter (10)
- # untangled (5)
- # yada (6)
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!
========== 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__@qqq there should be a multimethod or protocol fn you could override
@qqq I would love that as well
If you find a solution, let me know
Clojure.pprint/pprint may behave differently from prn
oh I didn't notice the prettyprint part of the question
is there an idiomatic way to convert arbitrary js objects (e.g. google closure BrowserEvent
s) into cljs data structures? I know there’s js->clj
, but that only works on vanilla js objects
@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?
https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/core.cljs#L9896-9899
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
can you give an example of such an object?
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
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 😜
(defn obj->cljs [o] (into {} (for [k (js-keys o)] [k (clj->js (goog.object/get o k))])))
roughly this?
seems to work on BrowserEvent
not sure it's wise to convert that to a cljs data structure though
Unless you're writing a library, maybe you can just create a map of the keys you need.
yep I have something similar, makes sense. why do you think it’s unwise to convert to cljs tho?
you could also extend IEncodeClojure
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}"]}
as @dominicm mentioned, you could just explicitly get what you need from the object
yep I think I might just go with that. just curious if there was a different solution out there
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
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.
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.
@koolkk I haven’t tried this myself, but if you’re using transit you could use https://github.com/tonsky/datascript-transit
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
Also look into http://clojurescriptkoans.com/
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-timeI 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/
But I think re-frame is better to start https://github.com/Day8/re-frame