Fork me on GitHub
#re-frame
<
2017-09-20
>
danielneal09:09:18

I want to log the last x events to my app-db, to include in a crash report

danielneal09:09:24

I originally wrote an interceptor

danielneal09:09:30

(def log-events
  (->interceptor
    :id :debounce
    :before (fn [context]
              (let [db (get-in context [:coeffects :db])
                    event (get-in context [:coeffects :event])
                    log (get-in db db-path [])
                    new-log (cond-> (conj log event)
                              (= (count log) max-events) (subvec 1))]
                (assoc-in context (into [:coeffects :db] db-path) new-log)))))

danielneal09:09:50

But this is not capturing all events - for example those dispatched and handled by async-flow

danielneal09:09:04

What would be the correct approach?

danielneal09:09:14

I've thought of using add-post-event-callback, but that wouldn't have access to the db

achikin12:09:34

Hi everyone! I have an issue and don’t know how to solve it. I have two fields in app db and an event that fires a request using data from those two fields. I want to fire a request every time when one of those fields is updated. It should be something like

(reg-event-fx
  :update-field1
  (fn {db :db} [_ new-value])
    {:db (assoc db new-value)
     :dispatch [:fire-request]})

(reg-event-fx
  :update-field2
  (fn {db :db} [_ new-value])
    {:db (assoc db new-value)
     :dispatch [:fire-request]})

(reg-event-fx
 :fire-request
 (fn [{db :db} [_ _]]
   {:http-xhrio {:field1 (:field1 db)
                 :field2 (:field2 db)})
But as soon as event order is undetermined I get nils or previous values from db in :fire-request event. Is there any reliable way to update db first and than send a request?

kasuko13:09:06

@achikin That should work. The db will be updated synchronously with the event and the dispatch would go on to a queue to be handled later so it would have the new DB.

kasuko13:09:46

Are you sure that the :fire-request event has a nil :field1 if it was dispatched from the :update-field1 event?

kasuko13:09:19

It is possible that :fire-request would happen before both fields are processed

achikin13:09:50

Let me try. I got that from my collegue who stated that he gets nil/previous value in the handler.

achikin13:09:24

@kasuko, yes you’re right the order of updates is determined. Is it stated somewhere in the documentation?

profgra13:09:09

Hi all, I'm trying to use a react lib in my re-frame project (https://github.com/tom-s/react-drag-sortable) but I don't understand how to mimic the code in the snippet below:

profgra13:09:09

I tried with a [:span ... but the tag name is merged with its content. like [:span "bla"] becomes spanbla. Any idea about what I am missing?

achikin13:09:24

try to wrap it into (reagent.core/as-element)

genekim19:09:05

@l1sp3r @sandbags: FWIW, I tried using re-frame-datatable, and found it incomprehensible and gave up… I ended up rendering tables by hand, which turned out to be very easy. (Not quite relevant to your question, but wanted to share my experiences…) OTOH, if you actually got it working, I’d love to see how you did it! 🙂

sandbags21:09:09

@genekim i know i found the instructions a little vague on a couple of points when i used it, but it wasn't too bad and the results are very useful

genekim21:09:12

Wow! Cool, @sandbags — congrats on getting it running! Thanks!

genekim21:09:41

@sandbags: can you share the db.cljs (or whatever) that you’re using re-frame-datatable to render? I couldn’t ever figure out how to bind the library correctly to my data. Thx!

sandbags22:09:07

@genekim my db looks like {:contacts [{:gn "Matt" :ln "Mower" :em "<mailto:[email protected]|[email protected]>" :co "Mower/Valdemarin" :ti "Managing Partner" :ke 0 :rt "Blah"} ...]}

sandbags22:09:41

@genekim ^^^ that's the :results subscription which is referenced in dt-results-table as [:results] and the source of the data