Fork me on GitHub
#fulcro
<
2023-10-02
>
genekim03:10:33

I love the addition to the FulcroDemos, @tony.kay and @holyjak — here’s the one I tried to make, but I couldn’t get it to work. Any help appreciated! I actually tried to generate a demo showing how two components could share state, by having the same ident, as I asked about and learned here. Trouble is, I couldn’t get it to work — I think it’s because Workspaces partitions the components so they can’t share databases? I wanted to show how two components could share the same counter.

(defsc Demo [this {:keys [:demo/counter] :as _props}]
  {:query         [:demo/counter]
   :ident         (fn [] [:component/id :singleton])
   :initial-state (fn [_]
                    {:demo/counter 10})}
  (dom/div
    (str "Hello!  Counter accumulator: " counter)
    (dom/button {:onClick #(m/set-value! this :demo/counter (inc counter))} "+")))


(defsc Demo2 [this {:keys [:demo/counter] :as _props}]
  {:query         [:demo/counter]
   :ident         (fn [] [:component/id :singleton])
  (dom/div
    (dom/p
      (str "Hello!  Counter accumulator: " counter))))
The intended point of the demo: show two controls, and updating the counter to either one updates the others.

tony.kay17:10:04

Each workspace card starts a separate app, FYI. If you want two different CARDS to share the same app, then you’d have to pre-create the app, and have it manage both cards, which is bit technical. The easy way to do it is to make one card and use css to split that one card into two halves or something. If you really want two cards then the easiest thing to do is (defonce) and app in the ns, then use plain react cards, and use the vanilla integration stuff to have fulcro manage two different trees in the two cards. E.g. hooks/use-component

genekim03:10:23

@holyjak I also wanted to write a sample Fulcro RAD report showing pagination, controls, etc. But I didn’t have time to figure out how to write a simple enough resolver. I thought it would be amazing to have a resolver return 500 records, and show how to make a dropdown that changes page sizes (I do this all the time), filter on fields, etc. I’d love some help generating some of the skeleton for this, and I can run with it from there! Thank you!