Fork me on GitHub
#clojurescript
<
2020-03-16
>
kwrooijen08:03:55

Hi all, i'm working with a Javascript object that seems to be recursive. If I println it, I get a too much recursion error. When I use js/console.log it gets printed, and there's one key that keeps nesting itself repeatedly. It seems to go infinitely. However my problem is that I want to access a specific portion of this data in the form of..

(-someChildren (-key1 obj))
This will give me a collection of objects, which also recur endlessly! But each one of these children has a property that I want. Basically I want to do this..
(map -someProp (-someChildren (-key1 obj)))
Of course this doesn't work, since it's a Javascript array. And I can't use js->clj or array-seq because of the infinite recursion. What's the best way to tackle this problem? One solution I could think of is using Clojure's loop + .pop until the array is empty, but maybe there's a cleaner way?

fricze08:03:47

if it’s a JS array you can just call JS Array.map , can’t you?

(.map (-someChildren (-key1 obj))
      #(-someProp %))

kwrooijen08:03:53

Ah wow, I feel pretty silly haha. Forgot JS has a map method. I think that would work, thanks 🙂

fricze09:03:42

glad I could help 😉 cheers

fricze09:03:38

JS interop is really quite nice in ClJS, but it’s easy to forget about when you write Clojure all the time 😉

kwrooijen10:03:44

Well I'm honestly not an expert in Javascript anyway 😄

ABeltramo11:03:18

Hello everybody, I need some help in end to end testing in clojurescript using shadow-cljs. I saw this https://github.com/bensu/doo/wiki/End-to-end-testing-example for doo is it possible to do something similar for shadow-cljs? I would like run the cljs tests from the test environment of the clojure backend, is that possible or should I migrate to doo?

jjttjj13:03:02

is there an example or walktrhough somewhere of starting a cljs repl from a clojure repl (not from the command line)?

jjttjj13:03:31

But it seems like this might just start a server?

Alex Turok13:03:49

I haven’t done any cljs for long, but used to do things as outlined in weasel’s readme. Worked for me - you may try it: https://github.com/nrepl/weasel/blob/master/README.md

jjttjj13:03:10

Thanks, but I'm specifically trying to get it to work with no external deps besides cljs. Which I know is possible somehow 🙂 It works if I use clj -m cljs.main from the command line. Just trying to cheat on reverse engineering that

Edmund14:03:49

Hi all. Having headaches with cljs-http. I'm playing with ring-compojure and got a server running on localhost:3000. I can make requests to this server via postman / direct in the browser and getting valid json responses. If I try the same request with cljs-http, I'm getting an empty response: '{:status 0, :success false, :body "", :headers {}, :trace-redirects ["http://localhost:3000/..." "http://localhost:3000/...."], :error-code :http-error, :error-text " [0]"} ' what could I be missing. I've looked around to no avail. This "(go (let [response (<! (http/get "" {:with-credentials? false }))] (prn response)))" however works. Only when I use my endpoint do I get this funny empty error.

Edmund15:03:25

Turned out to be a CORS issue. Adding cors middleware on the ring server fixed the problem.

jjttjj20:03:24

Anyone know how to use macros from an external, depended upon library with cljs.js/eval-str ? Is it possible to do it without using the source string? Ie, I want to use the library https://github.com/hoplon/javelin inside cljs.js/eval-str how do I do this?

(cljs.js/eval-str state
                  "
(do 
(ns myns (:require-macros [javelin.core]))
(def xx (javelin.core/cell 123)) 
@xx ;;works
;;(def yy (javelin.core/cell= (+ xx 123))) ;;cell= is a macro
;;@yy ;;doesn't work
)"
                  'foo.bar
                  {:verbose    true
                   :source-map true
                   :eval       cljs.js/js-eval 
                   }
                  (fn [{:keys [error] :as res}]
                    (if error
                      (do
                        (println error)
                        (println (.. error -cause -stack)))
                      (println res))))

kaosko22:03:59

anybody working with three.js & shaders / cljs / reagent? I've kind of gotten a hang of it but I'm still looking for guidance on how you've packaged your shaders and how you are manipulating the values? seems obvious to put the manipulatives in an atom but if there are any examples on how you've maybe structured the manipulation code and multiple shaders together, I'd be interested in taking a look

darwin22:03:41

this is maybe too far from your model, but I ported a few react-three-fiber demos to cljs: https://github.com/binaryage/cljs-react-three-fiber it is using modern react, so all shader updates would be implemented in react hooks - but none of ported demos needs that

darwin22:03:10

also using shadow-cljs so I’m able to keep shader sources as separate files and embed them into compiled cljs via inline macro: https://github.com/binaryage/cljs-react-three-fiber/blob/master/src/app/rtf_examples/demos/refraction.cljs#L44-L48

darwin22:03:36

you could do it in clojure macro as well, but this method is compilation-cache friendly

kaosko22:03:33

thanks @U08E3BBST last time I looked at the react-fiber not to mention the cljs pieces, it didn't look quite ready for primetime. shader updates in react hooks sounds great though. can you say anything about the performance compared to the stack renderer, perhaps especially related to three.js?

darwin22:03:52

unfornutaly I cannot, this is the only toy project I have at the moment, and I’m new to three.js

kaosko22:03:56

alright, thanks anyway. I'll keep your project in mind