Fork me on GitHub
#clojurescript
<
2020-04-09
>
wasser14:04:31

Hope everyone is healthy and safe. Has anyone worked with “worldwind-react-globe” or “worldwindjs”? I’m not understanding how to work with renderable layers and my Google-fu isn’t finding me any examples I can successfully translate to CLJS

Spaceman15:04:03

I'm running this example in clojurescript: https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_canvas_drawimage And I have the following. (Ignore what segmentation or segmented means):

(def run-segmentation (with-meta identity {:component-did-mount #(dispatch [:run-segmentation])}))
[run-segmentation
      [:div
       [:canvas {:id "img-editing"}]
        [:img {:src "/run-segmentation" :id "segmented"}]]]
The css file:
#segmented {
    border: 1px solid green;
    height: 277px;
    width: 220px;

}

#img-editing {
    border: 2px solid blue;
    width:240px;
    height:297px;
}
The event listener:
(reg-event-db
 :run-segmentation
 (fn [db _]
   (set! (.-onload img)
         (fn []
           (let [c (js/document.getElementById "img-editing")
                 ctx (.getContext c "2d")
                 img (js/document.getElementById "segmented")]
             (.drawImage ctx img 10 10))))
   db))
But the output isn't what is expected: What am I doing wrong?

FlavaDave16:04:52

running a reagent project in atom and it will only run a CLJ repl even when I switch to a specific cljs namespace it wont evaluate any CLJS or js interop. Anyone got any advice? Wont work in emacs either

dpsutton16:04:32

how did you start a cljs repl in emacs?

FlavaDave17:04:51

`cider-jack-in-clojurescript

jaide17:04:47

ClojureScript doesn't have a format function right? https://cljs.github.io/api/cljs.core/format What's the best alternative?

jaide17:04:10

Perfect thanks!

lilactown17:04:11

just took that from the source of the removed cljs.core/format

jaide17:04:30

Oof you're right, it's right there!

FlavaDave19:04:38

having a hard time understanding how to parse json in practice. the js->clj tutorial makes sense but I have all of the JSON in a different file. is there a way to pass my .json file into the function. sorta like this: (.parse js/JSON <file.json>)

lilactown19:04:25

you need to read the file in somehow, either via a network request (in a browser) or via reading form disk (node.js)

FlavaDave19:04:56

even if the json file is in my project directory?

phronmophobic19:04:53

you can potentially read it at compile time using a macro depending on your use case

lilactown19:04:37

yes if it is in your project directory, you need to serve the file somehow if you want to read the file at runtime.

lilactown19:04:02

if you want to read the file at compile time, that can also be done but is more complicated

FlavaDave19:04:26

i think runtime would be better

phronmophobic19:04:55

is this a web app or a nodejs program?

FlavaDave19:04:10

web app. reagent

lilactown19:04:42

I imagine you have some sort of public dir that you’re serving html/css/js files from

lilactown19:04:03

you can put that file in that same dir and then fetch the JSON

lilactown20:04:19

e.g. if you have the file structure:

src/
resources/
  public/
    index.html
    js/
    css/
    something.json
then in your code you can do:
(-> (js/fetch "/something.json")
    (.then #(.json %))
    (.then js->clj)
    (.then prn))
and it will fetch the something.json file, convert it to a CLJS data structure, and print it to the console/REPL