Fork me on GitHub
#beginners
<
2017-05-07
>
tbaldridge13:05:14

@lepistane I should mention though, that Joy of Clojure is "advanced" in that it uses more less-known functions to produce very concise code. It's not advanced in the "let's use a monadic stack to transform a free applicative into a dual functor" (yes, I made that up). So you'll stare at the code a lot, but by breaking it down and thinking of how the data flows, it'll make sense.

tbaldridge13:05:22

I can't find it now, but I remember the JOC's implementation of the Game of Life requiring me to sit and think about it for about an hour before I said "oh wow..." and it suddenly all made sense.

timo16:05:34

how can it be, that in a cljs-function you write a function without a function body but only with a map of keywords like this?

(reg-event-fx
  :contract/fetch-compiled-code
  interceptors
  (fn [{:keys [db]} [on-success]]
    {:http-xhrio {:method :get
                  :uri (gstring/format "/contracts/build/%s.json"
                                       (get-in db [:contract :name]))
                  :timeout 6000
                  :response-format (ajax/json-response-format {:keywords? true})
                  :on-success on-success
:on-failure [:log-error]}}))

timo16:05:02

I don't get the curly-braces-part

noisesmith16:05:52

@timok {} in clojure or clojurescript is a hash-map literal value

lepistane16:05:03

@tbaldridge great!! i am going to read joy of clojure next!! THANK YOU SO MUCH!

noisesmith16:05:15

inside a value binding, it's a destructuring of the input

timo16:05:06

but in a function you would have some kind of body where something is done, right? in this eventhandler above there is only a map in the function-body. what am i missing?

timo16:05:52

ok...I got it...the on-success is supposedly a function so there is a request and on success the function in on-success is called.

noisesmith16:05:05

a map as a function body is valid - it just means "when called, create and return this data"

noisesmith16:05:16

on-success is not called by that code

noisesmith16:05:29

it is returned under the key :on-success

noisesmith16:05:02

I don't know this context well enough to say for sure, but I'd hazard a guess that hte hash-map is used to create the parameters for an xhr, and the on-success is registered as the xhr success callback

noisesmith16:05:12

but someone else is doing that, somewhere else

timo17:05:37

yeah great, thanks for your help!