Fork me on GitHub
#re-frame
<
2020-04-01
>
Ramon Rios11:04:00

Hello everyone, each row that i receive cointains this type of data

{:customer-id "cid-1"
          :customer "Customer 1"
          :policy "Policy 1"
          :data [{:type "Term" :bruto-nr 300
                  :brio-nr 100}
                 {:type "Settlement" :bruto-nr 300
                  :brio-nr 100}]
I'm trying to implement something similiar on the image: This vector in the key "main" show this data without repeating the customer and police data twice. Is that possible. I'm struggling a lot to do it.

p-himik11:04:19

I have no idea what you mean. What "sub-vector" do you mean? What is the "main" data?

p-himik12:04:46

Those were not "yes/no" questions...

Ramon Rios12:04:39

I'm sorry. I edited the question to try make it more readable

Ramon Rios12:04:48

The "sub-vector" is the vector in the key :data and the "main data is the :customer and :police info

p-himik12:04:28

OK. What does it have to do with re-frame though?

Ramon Rios12:04:02

I'm using re-frame datatable library.

p-himik12:04:54

For the purpose of the question, it doesn't matter. The only thing that it tells me is that you want to end up having Hiccup that represents that table. So it's a question about transforming the data that you have into Hiccup. You need to reduce over the main vector of maps with "main" data and accumulate the rows. Each "main" vector would create N rows where N is the number of items in the "sub-vector", as you call it.

p-himik12:04:44

Something like this. Didn't check.

(letfn [(mk-row [item sub-item]
          [:tr
           [:td (:customer item)]
           [:td (:policy item)]
           [:td (:type sub-item)]
           [:td (:bruto-nr sub-item)]])]
  (reduce (fn [acc datum]
            (if (seq (:data datum))
              (-> (conj acc (mk-row datum (first (:data datum))))
                (into (map #(mk-row nil %) (rest (:data datum)))))
              acc))
    [] data))

Ramon Rios12:04:53

Thanks, i'll try that!

Quentin Le Guennec18:04:20

Hello, how do I lift a subscription into another subscription? Some kind of monad: • sub A • sub B depends on sub A

Thomas Karras18:04:11

somewhat buried but you can use a layer 3 subscription, an example is here, https://github.com/day8/re-frame/blob/master/examples/todomvc/src/todomvc/subs.cljs

Quentin Le Guennec18:04:39

@genothk that works, thanks a lot!

donyorm20:04:32

I need to create an event that creates multiple effects of the same type and therefore the same key (in this case I want it to dispatch multiple events), how do I do that?

p-himik21:04:31

There's a :dispatch-n effect, built into re-frame.

donyorm21:04:49

That might work, where are these built-in effects documented?

donyorm21:04:41

That works, thanks!