Fork me on GitHub
#clojurescript
<
2022-02-17
>
jaide07:02:27

Is there a library out there for only transforming a graphql edn structure into a graphql query string. Looked at Luciana, seems solid but a bit more involved than what I need

jaide21:02:50

A friend found https://medium.com/@kirill.ishanov/poor-mans-graphql-client-for-clojurescript-apps-8dc4b04e8738 which worked as is aside from needing more advanced filtering support. Exactly what I was looking for!

Joshua Smock10:02:25

I’m trying to play around with the self hosted ClojureScript compiler, and I’m running into some issues around cljs.core . Whenever I call cljs.js/analyze-str , eval-str, or compile-str it succeeds but things like defn appear as variables in the analyzed/etc. namespace, rather than as from cljs.core , so instead of getting cljs.core.defn I’m getting e.g. test.ns.defn. I believe that I’ve set up everything correctly (I am binding *compiler* and passing it in as an option, and I’m not disabling dump-core). Any ideas what might be going on?

Joshua Smock15:02:53

Thanks @U05224H0W, yeah I’m using shadow, let me try that out and I’ll reach out in the #shadow-cljs channel if I run into any issues

Felipe Cortez13:02:26

is there any way to make set! work with some->? e.g., this works:

(when-let [logo (js/document.querySelector ".logo")]
    (-> logo .-style .-zIndex (set! "20")))
but this doesn't
(some-> (js/document.querySelector ".logo") .-style .-zIndex (set! "20"))
;; Can't set! local var or non-mutable field at line 1 ...

p-himik13:02:49

No, because some-> binds every step to a new name, which results in an expression like (set! x "20"). Instead, you can use

(when-some [logo (js/document.querySelector ".logo")]
  (set! (.-style logo) -zIndex "20"))

👍 1
Felipe Cortez16:02:30

ended up doing

(defmacro when-> [x & forms]
       `(when-let [x# ~x] (-> x# ~@forms)))
might be a bad name but it's the behavior I want, I think

Simon13:02:48

Refactoring ideas?

(condp <= v
    10E12 (str (.toPrecision (/ v 10E12) 3) "T")
    10E9 (str (.toPrecision (/ v 10E9) 3) "B")
    10E6 (str (.toPrecision (/ v 10E6) 3) "M")
    10E3 (str (.toPrecision (/ v 10E3) 3) "k")
    v)

p-himik13:02:53

LGTM. As an alernative:

(some (fn [[x s]]
        (when (<= x v)
          (str (.toPrecision (/ v x)  3) s)))
      [[10E12 "T"] [10E9 "B"] [10E6 "M"] [10E3 "k"]])

2
Felipe14:02:03

ohhh, some + when is clever. nice!

Felipe14:02:26

but you need to (or … v) not to get nil when it’s under 10E3, right?

p-himik14:02:39

Oh, of course, you're right! Good catch.

quoll16:02:27

As an aside… it’s “G”, not “B”

👍 3
Richard Bowen23:02:09

Hey, can someone give a basic illustration of using resizeObserver in cljs.

djblue23:02:34

Not sure if this is too much, but https://github.com/djblue/portal/blob/37a1e186740546786bb4bb2a585a5091a526d80f/src/portal/ui/viewer/vega.cljs#L82-L96 is how I used ResizeObserver in a cljs project of mine.

djblue23:02:18

I use it indirectly via a react hook and render based off of state.

phronmophobic23:02:36

If you're mostly interested in just how the interop will look, you can try plugging in js examples into https://mauricioszabo.gitlab.io/js2cljs/