Fork me on GitHub
#re-frame
<
2021-10-28
>
Ryan16:10:06

Hey all, one of the last struggles Im facing with reframe is making sure there's a :key for lists.. Where would I annotate the key in the following map:

(map #(vec (person-detail-one-up (util/labelize-keyword (:type %)) (:name %))) (:established-providers person))
(defn person-detail-one-up [label1 value1]
  [:div {:className "p-formgrid p-grid"}
   [:div {:className "p-field p-col"}
    [:label {:className "p-col-6 detail-label two-col"} label1]
    [:span value1]]])
:established-providers [{:id 1 :type :primary-care :name "Dr. Larry Arbogast"}
                           {:id 2 :type :cardiologist :name "Dr. Mantis Toboggan"}
                           {:id 3 :type :pulmonologist :name "Dr. Pembry"}
                           {:id 5 :type :ob-gyn :name "Dr. Jack Carmichael"}
                           {:id 6 :type :physical-therapy :name "Dr. Horniker"}]

Ryan16:10:53

I'm assuming the annotaiton itself would be like

^{:key (:id %)} ?

lilactown16:10:31

it's hard to know because you're generating your elements using seq ops

lilactown16:10:47

it's easier to read if you use for

lilactown16:10:10

(for [provider (:established-providers person)]
  [person-detail-one-up (util/labelize-keyword (:type provider)) (:name provider))])

lilactown16:10:37

using [] around the person-detail-one-up component allows us to add the key annotation

Ryan16:10:59

That makes sense

Ryan17:10:08

And you put the annotation in front of the vector, correct?

Ryan17:10:32

hmm, that didnt do the trick, nor did making it first element of vector

Ryan17:10:22

Ah, of course, can't use % without map in this case so this works

Ryan17:10:33

(for [provider (:established-providers person)]
  ^{:key (:id provider)}  [person-detail-one-up  (util/labelize-keyword (:type provider)) (:name provider)])

Ryan17:10:40

Thanks @U4YGF4NGM 🙂

lilactown17:10:27

yeah the % is related to using #()

đź‘Ť 1
Drew Verlee19:10:19

will have a nil in the dispatch-n vector do anything? we want do things conditionally. e.g dispatch-n [(when x y)]

dpsutton19:10:48

sounds reasonable to just filter the vector

dpsutton19:10:10

at my last spot we would (cond-> [] condition? (conj [:event ...])). and you could also (into [] (filter some? [(when ...)]))

Lu19:10:46

Pretty sure nils are just ignored. Also I’d use fx vs dispatch-n

Drew Verlee19:10:24

@dpsutton i should have been more clear about the use case, it's my understanding that the order matters in our dispatch-n and so conjing wont work because it needs to be somewhere specific.

Lu19:10:40

In your dispatch-n the order matters as long as you don't perform side effects in your handlers. In that case, there's no guarantee one side effect will take place before the next handler call. Also, what @dpsutton wrote would still ensure the order .. you just do it programmatically

Lu19:10:42

regardless you can have nils :)

Drew Verlee19:10:22

the filter with some would, yes, i didn't see that example. Thanks 🙂

dpsutton19:10:18

(cond-> [] true (conj 1) false (conj 2) true (conj 3)) doesn’t introduce arbitrary order.