Fork me on GitHub
#clojurescript
<
2018-10-01
>
schmandle09:10:17

Hi. Back in 2016, in ClojureScript 1.9.293, some changes were made to prevent problems with checking protocol membership when using :advanced builds (See https://groups.google.com/forum/#!topic/clojure/onmJ2uyQzC4 ). I'm not sure if these changes were expected to be a complete fix for the problems discussed in the mentioned thread, but I am experiencing them now with js->clj using cljs 1.10.339. There are some more details on an issue I filed against cljs-ajax: https://github.com/JulianBirch/cljs-ajax/issues/219 . Is this expected behavior, and I am supposed to avoid js->clj for external json data, or did just I stumble on to a cljs bug?

thheller09:10:25

@schmandle the issue was fixed for normal protocols yes but not "fastpath" protocols like ISeq so you can run still into it if the JSON data contains a field with a number that "accidentally" has the bits set of some protocol. eg. {"ab":4} when cljs$lang$protocol_mask$partition.. was renamed to ab

sb09:10:42

just for log: I got the answer in the beginner channels.

thheller09:10:34

js->clj is not safe for arbitrary json data

schmandle09:10:40

@thheller Right. I'll stick to using transit then. Thanks

TeMPOraL09:10:58

A question: is it possible to upload files (FormData) via re-frame-http-fx? I know it wraps around cljs-ajax, but it seems to be using only the simpler "ajax-request" API, and that API doesn't seem to specify necessary keys.

{:http-xhrio {:method :post
              :uri (api/api "path/to/upload-endpoint")
              :body formdata-with-file
              ;;:format (ajax/transit-request-format)
              ;;:response-format (ajax/transit-response-format)
              :response-format (ajax/raw-response-format)
              :on-success [::success-handler]
              :on-failure [::fail-handler]}}
This is how my invocation looks like; what I get in response is "unrecognized request format: nil".

TeMPOraL09:10:50

what I'm trying to achieve is essentially cljs-ajax's

(POST "/send-file" {:body form-data
                      :response-format (raw-response-format)})
but written as re-frame-http-fx

TeMPOraL10:10:27

ok, RE my question about file upload - turns out it's a case of PEBKAC, and I didn't notice my file data was actually nil (due a parameter being eaten somewhere upstack), so nevermind 🙂

Digital Baboon11:10:22

Hey guys! I'm using reagent, and have the following code calling a component, but instead of returning an object, I'd like to return a string, how would I go about this?

Digital Baboon11:10:06

It's returning an object right now

souenzzo11:10:48

@im defroute is a macro that apparently always returns a function https://github.com/gf3/secretary/blob/master/src/secretary/core.clj#L3

Digital Baboon11:10:28

@souenzzo ah so I can’t. Alright, I’ll figure another way out of this 😁. Thank you!

souenzzo11:10:38

@im checkout bidi and others routing libraries

Digital Baboon11:10:08

How would I go about calling a function like (defn content-dispatch [name] (content-{name})) ?

manutter5112:10:38

I would probably do something like

manutter5112:10:13

(def dispatch-map
  {"foo" content-foo
   "bar" content-bar
   ...}

(defn content-dispatch [name]
  (let [dispatch (get dispatch-map name)]
    (dispatch)))

manutter5112:10:18

Though it probably wouldn’t come up that often since you can pass around functions as easily as you can pass around strings.

jaawerth21:10:50

@im you could always set up a multimethod unless there are too many possible names for that to make sense, in which case yeah I'd do a hashmap lookup as in the above example