2

I have such terrible JavaScript code

response.items[0].fields.image.fields.file.url

I can convert it to ClojureScipt map, but to access that field I will have to type monstrous unreadable access. Is there a way to do it nice and elegant way way?

2 Answers 2

2
(-> (aget (.-items response) 0)
    (.. -fields -image -fields -file -url))

or if you have converted it to a Clojure data structure:

(-> response :items first :fields :image :fields :file :url)
Sign up to request clarification or add additional context in comments.

Comments

0

I recommend using cljs-oops library. It support nested "selectors" for your object graph, e.g.:

(oget o "k3.?k31.k311")
(oget o "k3" "?k31" :k311)
(oget o ["k3" "?k31" "k311"])
(oget o [["k3"] "?k31"] "k311")

2 Comments

I will investigate but from first sight I did say for myself "wtf" :D
I also use cljs-oops and do recommend it, but also wanted to show the vanilla cljs solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.