Fork me on GitHub
#re-frame
<
2017-02-21
>
escherize03:02:02

Here's a question I havn't seen or considered before: How do you setup a http request to download a file from re-frame? Is it possible? Is there an fx handler for it?

curlyfry06:02:58

@escherize Hmm, l'm not sure what part of this would be specific to re-frame. I think the most common way to download a file is to just use a html link. Could you give a more specific example of what you want to do?

escherize06:02:27

Yeah, we are using a link as it is. 🙂 Ideally I'd have (dispatch [:xxx]) -> download a file. but the way it is now we use a bit of html to provide a link to click that sends the request that does it.

curlyfry08:02:57

escherize: What kind of request is that? It's not just an attribute on the html element?

piotr-yuxuan09:02:50

(reg-event-fx
  :download-file
  (fn [{:keys [db]} [_ file-url]]
    {:db db
     :http-xhrio {:headers {:Authorization (str "token " EXAMPLE_TOKEN)}
                  :uri file-url
                  :method :get
                  :timeout 8000
                  :response-format (json-response-format {:keywords? true})
                  :on-success [:println "file downloaded"]
                  :on-failure [:identity]}}))

[:button {:on-click #(dispatch [:download-file ""])} “download”]

piotr-yuxuan09:02:33

I’m not sure why it wouldn’t be more difficult than this simple snippet 🙂

mccraigmccraig09:02:41

@escherize dyu mean your re-frame app is serving the file, or you want your app to download the file to the local filesystem or memory ?

piotr-yuxuan10:02:48

ha ha yeah I know it works — on my machine at least ^_^

negaduck12:02:45

hm. When I have (enable-re-frisk!), then nothing gets rendered at all in ios safari.

negaduck13:02:41

and they are different every time

negaduck14:02:26

Does anyone run cljs code in ios safari? I’m not sure, but it seems it just loads resources in a random order and I get errors because of this, different set of errors on every page reload.

mccraigmccraig15:02:44

@negaduck i run cljs code on ios safari and cordova+wkwebview

mccraigmccraig15:02:27

i haven't seen any errors like that though

negaduck15:02:08

@mccraigmccraig, I love cordova, used to play with cljs code in it. It worked flawlessly a while ago.

negaduck15:02:35

can’t understand what happened, I just run a simple re-frame example

mccraigmccraig15:02:16

does it work ok if you do some cljs optimisations ? :simple or :whitespace ?

mccraigmccraig15:02:27

i.e. concatenate all the js

negaduck15:02:01

mccraigmccraig, it works if I do $ lein cljsbuild min once, it does :optimizations :advanced

negaduck15:02:31

I don’t see any optimizations for dev build

negaduck15:02:05

added :optimizations :none to see what happens

mccraigmccraig15:02:53

no, dev builds are normally :optimizations :none for speed and so that cljs reloading works - but :none produces one output js for each input cljs

negaduck15:02:45

mccraigmccraig, btw I configured cordova to get resources from webserver on my laptop so 1. I didn’t have to rebuild the app and 2. figwheel worked — that was awesome

mccraigmccraig15:02:21

sounds interesting @negaduck - can you point to any docs on how to do that ?

mccraigmccraig15:02:25

i could have done with that yesterday - i do most of my debugging in chrome, but i had to debug some cordova local file handling

negaduck15:02:44

@mccraigmccraig, it’s mainly <content src="redirect.html" /> in config.xml + <allow-intent href="*" />: https://github.com/koddo/ryctoic/blob/master/client-mobile/config-dev.xml

mccraigmccraig15:02:33

that looks interesting