Fork me on GitHub
Drew Verlee00:10:15

Whats everyones favorite way to get track state in the front end? Currently i'm using binarayage's tools, though im thinking about upgrading to I also just do a fair amount of storing state in atoms so i can inspect it.

Drew Verlee01:10:13

Now that it comes down to it, im worried i can't use drac devtools because it says you have to install it in your "Chrome Canary" Which is the nightly build for developers and "isn't supported on linux"


On Linux you can use google-chrome-unstable for that.


what are you looking for in dirac?

Drew Verlee01:10:19

A debugger that can track state, let me fiddle with it in a cljs repl, would be nice. Right now, i end up saving state to atom to do that. I dont think there is anything wrong with that strategy. I'm also making sure i'm not missing some set of insight that could be helping me. I find a lot of my headaches are when i encounter something i dont understand and i'm looking for fast ways to poke at it.


I think i remember wanting to try vals scope capture


Nice to turn off figwheel auto reload and then state can persist. I remember that turning it back on requires a page refresh unfortunately

Drew Verlee01:10:51

err dirac seems to not play nice with shadow cljs projects.


Indeed. But you use a CLJS REPL that goes with shadow-cljs. Of course, it won't be in the Chrome DevTools console, but you will still be able to see all your state.

David Pham04:10:39

Did you try reframe-10x?


Hi, I'm trying to render a d3 graph in a div generated by reagent. I'm triggering the render in the :component-did-update but somehow it often tells me that the div I am looking for doesn't exist...


I'm not sure how to fix this


How do you refer to the target div?


(.querySelector js/document (str "#" selector "-graph")) (the reagent generates [:div#selector [:div#selector-graph] [:div.other-divs])


Try using a React ref (`let [ref (react/createRef)] ...)`) and check that it has been set before using it (`(when-some [n (.-current ref)] ...)`).


I still have this error, could it be the id that has a weird format?


(I'm logging the reference of the element)


I'm not sure. Why do you need to set the ID at all? Can you show your code?


because the user will create many of such divs, each with its own graph


(defn update-command
  (fn [ev]
    (let [text (.-value (.-target ev))]
      (cond (or
             (= (.-keyCode ev) 8)
             (= (.-keyCode ev) 32)
             (= (.-keyCode ev) 13))
            (com/expand-query text cur-command)))))

(defn draw-command-line
  [card-uuid cur-command refs]
  (fn []
     [(keyword (str "div#" card-uuid "-graph.graph"))
      {:ref #(swap! refs assoc :graph-area %)}]
       (fn [{node :name}]
         [:p.qnscore {:key (str "k-" node)} node])
       (get-in @cur-command [:expansion :inferred]))]
       {:on-key-down (update-command cur-command)}]
      [:p.overlay (:text @cur-command)]]]))

(defn new-command-line
  (let [new-command (r/atom {:text "" :expansion {} :status :current})
        refs (r/atom {})]
     {:display-name (str "command-line-" card-uuid)
      (fn [this old-argv]
        (when (:graph-area @refs)
          (.log js/console (:graph-area @refs))
          (let [new-exp (graph/prep-graph (:expansion @new-command))]
            (graph/remove-svg card-uuid)
            (graph/trigger-draw-graph card-uuid new-exp)
      :reagent-render (draw-command-line card-uuid new-command refs)})))


That doesn't really mean that you have to use IDs. You can still use refs and forgo IDs altogether. Well, assuming that D3 accepts not only ID strings but also DOM nodes. Also, yeah - it seems that IDs cannot start with a digit, I just tested it in Chrome. MDN says: "Though this restriction has been lifted in HTML5, an ID should start with a letter for compatibility"


I think I know what's the problem, elements ids can not start with a number, and because I use random-uuid, sometimes it does


yes you are correct 😛


I'm not sure if d3 can use DOM nodes, I'll check. Thank you for the help!


But still - the current version of your code seems backwards to me. It seems that draw-command-line can manage its own state - there's no need for its parent to do anything. But if the code you actually use has more going on, then maybe it's OK. No problem.


I'm not sure how draw-command-line could trigger the redrawing of the graph automatically when the content of the input field changes without the use of :component-did-update :thinking_face:


It looks like you could just move the contents of the :component-did-update function to the draw-command-line component itself. You will have to turn it into a form-2 component and use reagent.ratom/run! to spy on the changes of the ratom. new-command-line shouldn't care about what happens inside draw-command-line at all. Another thing - don't write (keyword (str "div#" card-uuid "-graph.graph")). Just write [:div {:id "...", :ref ...} ...]. The whole :div.class1.class2#id syntax is a mess IMO.


ok thank you, I will look into the run! function


If I understood your intentions correctly, here's how I would do it. Note that it definitely won't work right away since I used expand-query differently. And probably there are errors, so this is just to give you a general idea.

(defn new-command-line []
  (let [expansion (r/atom nil)
        update-command #(when (#{8 32 13} (.-keyCode %))
                          (let [text (.-value (.-target %))]
                            (reset! expansion (com/expand-query text))))
        ref (react/createRef)]
      ;; `@` has to be outside of any condition to let the `run!` magic work.
      (when-some [expansion @expansion]
        (when-some [node (.-current ref)]
          (let [new-exp (graph/prep-graph expansion)]
            ;; Assuming these functions can accept DOM nodes.
            (graph/remove-svg node)
            (graph/trigger-draw-graph node new-exp)))))
    (fn []
      [:div {:class :command-line}
       [:div {:ref ref}]
       [:div {:class :explanation}
        (for [{node :name} (:inferred @expansion)]
          ^{:key (str "k-" node)}
          [:p {:class :qnscore}
       [:div {:class :command}
        [:input {:class       :typing
                 :on-key-down update-command}]]])))


Ah, but since expansion is also used in the rendering function, maybe the explanation part has to be moved into its own component that accepts the expansion ratom. Just so that React doesn't re-render the main component when expansion's value changes.


wow thank you! I'll try it, that looks much cleaner than what I have


What tools or patterns would one use to build a reusable library with ClojureScript that renders a simple modal and makes ReSTful calls?


@U117LQ849 http-kit for the web server liberator for making the RESTful api reagent for the frontend modal Possibly re-frame, if you plan on using the library in larger projects A decent and quick starting point would be to create a project from the chestnut template Hope this helps


Appreciate it, wasn’t sure if re-frame was overkill for this type of library


I'm getting and error when calling async/<!! that the symbol doesn't exist, has it been removed ?

Alex Miller (Clojure team)15:10:36

did you include the core.async library and require it?


yes, I can use go and <!


clojurescript does not support the blocking variants of take/put, so no <!! or >!!


I get Invalid :refer, var cljs.core.async/<!! does not exist


Oh ok thank you

Ramon Rios16:10:28

Did someone here works with Yada? Is this has some code example for set basic role-access authentication?


hi everyone, trying to extend protocol for js/Object and getting warning

Extending an existing JavaScript type - use a different symbol name instead of js/Object e.g object


does that mean I should always extend js/Object as object?


the basic built-in types yes. object, number, string, array, function


ok, thanks!


I've been looking around, but haven't seen the (self-hosted) ClojureScript variants for clojure.repl/doc and clojure.repl/source. Noodle around with cljs.repl and clojure.browser.repl but neither of these looks appropriate. Anyone have any information on this?


@jsa-aerial While self-hosted ClojureScript can be used to implement a REPL, it doesn’t inherently provide REPL-specific functionality.


Take a look at Lumo or Planck to see how they implement these functions.

👍 4