Fork me on GitHub
#clojurescript
<
2016-10-29
>
mathpunk02:10:42

I am making AJAX calls from the browser in cljs to a server in clj, but I keep getting [object Object] in my UI and I should probably try and understand what's happening instead of randomly adding str and clj->js calls on both sides of the connection until things work.

mathpunk02:10:29

Note that my http knowledge is also limited so maybe I'm supposed to be getting :body data out or something?

mathpunk02:10:37

I think I'm confusing data with strings or something

bbss02:10:51

@mathpunk that looks like the toString of javascript, try the difference between cljs.pprint/pprint, print and js/console.log.

bbss02:10:51

and you can try logging (type whatever-you-are-printing)

bbss02:10:00

if it's string you know the toString has already been called

mathpunk02:10:43

uh... whoa, the result of my ajax request is of type `#object[Function "function (opt_xmlHttpFactory) { goog.net.XhrIo.base(this, 'constructor'); ....a bunch more stuff`

mathpunk02:10:36

which is funny b/c my route should just be a string?

bbss02:10:40

Hmm could it be that you didn't instantiate the request object

bbss02:10:44

maybe paste some code

bbss03:10:01

are you seeing the request in the network tab?

pesterhazy10:10:53

@wwajerowicz clj->js has been subject to controversy lately

pesterhazy10:10:24

in you case, if you're building a single value, why not ust #js instead?

pesterhazy10:10:59

then you can pick and choose how to convert values

wwajerowicz11:10:13

@pesterhazy: I figured out what the problem was anyway, I was using js/Date instead of js/Date.

pesterhazy11:10:33

haha, a javascript error 🙂

pesterhazy11:10:08

cljs.user=> (js/Date)
"Sat Oct 29 2016 13:01:57 GMT+0200 (CEST)"
cljs.user=> (js/Date.)
#inst "2016-10-29T11:02:00.014-00:00"

pesterhazy11:10:13

such a weird language

wwajerowicz11:10:51

Yep, I was hoping to avoid these JS peculiarities in ClojureScript

pesterhazy11:10:28

there's no way around being friendly with the host, but with cljs you can avoid daily confrontations

kah0ona11:10:11

although the occasional confrontation you will get will make you appreciate more that you're further away from plain JS than you used to be in '09 😉

baptiste-from-paris17:10:48

hello guys, anyway to see how my cljs code compile to javascript ?

baptiste-from-paris17:10:15

e.g =>

(let [[a b] [1 2]]
  (+ a b))

baptiste-from-paris17:10:26

some function tells me how it translates into js

rauh18:10:17

@baptiste-from-paris Wrap it in a fn and eval it in the repl

jrheard18:10:16

i use it all the time for specifically that

jrheard18:10:46

if you write cljs code in the top left and press ctrl enter, you see the generated js in the top right

baptiste-from-paris18:10:17

heard of it and never realized it’s value

jrheard18:10:28

yeah, pretty handy!

wielderofmjolnir19:10:33

Is there anyone here well-versed in the ways of Re-frame? 🙂

kah0ona20:10:43

Altho disclaimer

kah0ona20:10:01

I just had a long diner with friends and wine :-)

kah0ona20:10:35

But ive built two fairly sizeable webapps in it, so might be able to help

wielderofmjolnir20:10:16

Haha, thanks 🙂 I'm currently building a dashboard-like web-app, which has a sort of "personal public profile" for any person registered on it. The relative URI (using Secretary) for any such profile is then /person/:person-url-slug. I want to have anchors to sub-views of the profile (e.g. /person/person-url-slug/general), and thus need to have access to the person-url-slug in one of the child-components. Now to the actual question, is it a "bad" idea to have a map in app-db, which is used to hold any data associated with the current page/view, in this case, the peron-url-slug? I'm thinking I could also have specific maps for each page, but that means I have to be doing a lot of manual cleanup when changing the page, right?

shaun-mahood21:10:05

@wielderofmjolnir: Bring all your questions over to the #re-frame channel, it’s usually active and helpful. I think there are a few different options for what you need to do, and I’ve got time right now to chat a bit about them if you come over there.

wielderofmjolnir21:10:30

Oh, will do! Should I copy-paste the question?

shaun-mahood21:10:09

@wielderofmjolnir: Yeah, then everyone else will have a chance to help too