clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
Andreas S. 2020-11-17T20:11:05.241Z

Hi! is it possible to load a local file with clojurescipt? Any ideas appreciated!

Andreas S. 2020-11-18T08:10:15.244Z

Hi @smith.adriane in the browser

phronmophobic 2020-11-18T08:34:50.246500Z

I would use javascript interop to get the file using the apis like https://web.dev/read-files/ . I would give a better answer but it’s pretty late here.

Andreas S. 2020-11-18T08:38:04.248600Z

Thanks for answering! Could you sketch out how I would call this from cljs? Take your time, you don’t have so answer right away :)

tomrbowden 2020-11-18T10:03:32.248800Z

Here’s a snippet that may help you (Reagent/Hiccup):

(defn get-file []
  (let [handle-change (fn [event]
                        (let [files (.. event -target -files)
                              file (first (js->clj files))]
                          (println file)))] ;; do something with file
    [:input {:type "file"
             :on-change handle-change}]))

Andreas S. 2020-11-18T20:09:14.259100Z

hi @tom.bowden thank you for answering! lets say I have a "README.md" in the same directory as my cljs file, where would I put file name and or path information in your function?

phronmophobic 2020-11-18T21:21:14.264Z

to do that, you would have to use a clojure macro that reads the file at compile time and makes the data available when the clojurescript code is eventually run in the browser

Andreas S. 2020-11-19T08:09:53.281300Z

Could I read the data into data script or something?

Andreas S. 2020-11-19T08:11:18.282600Z

I mean if I turn my markdown files into clojurescript source code files, then it should work?

phronmophobic 2020-11-17T20:21:57.241100Z

where are you running your clojurescript? in the browser? locally, with nodejs?