Fork me on GitHub
#re-frame
<
2021-09-17
>
Ryan19:09:40

If I have an effect that wants to assoc-in to a DB in two spots, whats the easiest way? It complaiend about me having two :db keys in the effect map

Ryan19:09:22

{:db (assoc-in db [:person :name] "Sally" :db (assoc-in db [:place :name] "France}

lispers-anonymous19:09:53

{:db (-> db
         (assoc-in [:spot-1] thing)
         (assoc-in [:spot-2] another-thing))}

🙏 2
p-himik19:09:20

Just replace those keywords with vectors because it's assoc-in and not assoc.

lispers-anonymous19:09:37

Yeah ^ quick example

Ryan19:09:24

Yup, I did that without even noticing, glad some things are starting to stick! 🙂

Ryan20:09:12

Ok, I have some JS React I need to try and leverage from re-frame that's a bit beyond my current interop understanding:

<Menu model={items} popup ref={menu} />
<Button label="Show" icon="pi pi-bars" onClick={(event) => menu.current.toggle(event)}/>
What I have so far:
(defn right-nav []
  (let [                                                    
        menu-items [{:label "Logout" :icon "pi pi-fw pi-times-circle"}
                    {:label "Help" :icon "pi pi-fw pi-question"}]]
    [:<>
     [:> Menu {:model (clj->js menu-items) :popup true}]
     [:> Button {:on-click (menu.current.toggle %)} "Menu"]]))

Ryan20:09:33

The UX Framework is Prime React

p-himik20:09:55

Go through Reagent examples in its repo - there are bound to be code samples of very similar things.

p-himik20:09:17

Also read about React refs if you haven't already.

p-himik20:09:19

The interop here is just getting a field from a JS object and then calling a function that belongs to the resulting value. Pretty much the very first two things in the JS-CLJS interop guides.

Ryan20:09:39

Perfect I'll start there!

Ryan20:09:52

At first its a bit disorienting to figure out what to look for in re-frame vs reagent

p-himik20:09:08

You probably meant "with" and not "vs". :) Re-frame is about the state of your application. Everything to do what your consider your app's state and also usually with all the interactions with the outside world that happen to be relevant to that state. Anything else should probably be done outside of re-frame, so probably at the Reagent level.

Ryan20:09:01

indeed 🙂

Ryan20:09:25

and that explanation makes it a lot easier! 🙂

👍 2