Fork me on GitHub
#clojurescript
<
2021-12-24
>
dharrigan11:12:53

Can anyone point me to the right place to ask about transit-js with javascript, not clojurescript? I'm banging my head against the wall on some interop...

p-himik12:12:59

There are #javascript and #js-interop channels but they are very small. I'd just ask the question within this thread.

dharrigan12:12:52

Ta. Well, the setup is that the client is javascript, no clojurescript. I'm trying to decode a transit json reply from the server. The raw response from the server is thus:

dharrigan12:12:07

[["~:foo/bar",["^ ","~:message","I received your message '92c93001-df2d-4556-8565-ce629ef71c56'. It was 'Hello World'."]]]

dharrigan12:12:32

When I read it, using transit-js, it comes out as:

dharrigan12:12:45

let decoded = transitReader.read(data)...

dharrigan12:12:54

:foo/bar,TransitMap {:message => "I received your message '92c93001-df2d-4556-8565-ce629ef71c56'. It was 'Hello World'."}

dharrigan12:12:17

yet, when I try to call decoded.get(":foo/bar"), I'm getting this:

dharrigan12:12:34

TypeError: decoded.get is not a function

dharrigan12:12:26

So, if anyone has any hints on what I need to do, then I would be grateful (the transit-js documentation seems to imply that I can call get on the object (which should be a map)).

dharrigan12:12:29

Thank you 🙂

thheller12:12:56

my transit reading is a little rusty but isn't this [[:foo/bar {:message "I received ..."}]]?

thheller12:12:28

so in JS a map inside an array inside another array?

thheller12:12:05

so not just a map to get a key out of?

dharrigan12:12:05

Let me try to pull that out of the enclosing arrays...

dharrigan15:12:00

Thank you, was able to delve deeper into it. I can sorta get there now, but tbh, it's a rpita.

dharrigan15:12:34

I was able to extract out what I wanted by having a handler for the keyword, as transit-js won't convert ma map key that is a keyword, to a string, you have to do it yourself, i.e.,

dharrigan15:12:47

const transitReader = transit.reader("json", {
    "handlers": {
        ":": function(v) {
            return `${v}`
        }
    }
});

dharrigan15:12:10

Then I'm able to use transit.mapToObject(....) to convert the payload into a regular JSON structure.

dharrigan15:12:44

However, thank you @U05224H0W you helped me solve it 🙂

p-himik17:12:23

No clue whether there's a roadmap, but this is the issue for that: https://clojure.atlassian.net/browse/CLJS-3299

gratitude 1
zeitstein17:12:37

Should've checked before doing a day's amount of work 😄

borkdude17:12:58

Maybe you can submit the patch to make your day's amount of work worthwhile ;)

zeitstein18:12:44

Probably a lot of work for a beginner?

borkdude19:12:41

Probably ;)

borkdude17:12:30

There is an issue for it in JIRA

gratitude 1
seltzer171723:12:12

ANN: just-maven-clojurescript-archetype 0.2-RELEASE - A Maven archetype for creating ClojureScript projects that only requires Maven.