Fork me on GitHub
Vincent Cantin01:04:56

Supposing that I wrote a leaflet reagent component, is it possible to send it an event when someone click a button? So far, I only saw components reacting to data subscribtions, not event.


Sure, {:on-click #(dispatch [:user-says-yes])}

Vincent Cantin05:04:30

I misformulated my problem, I can send the event, but I don't know how to make the component receive it. According to re-frame's documentation, the event handler (domino 2) is the one which will receive the event, not the component (dominos 4, 5 and 6). In my case, I would like the map to receive the event. Is it possible without transforming the event into a state in the db ?

Vincent Cantin05:04:04

Or .. I am thinking that maybe I could dynamically create an effect handler when my leaflet reagent component is instantiated and destroy it when its component is destroyed. Would it be the right way? does re-frame allow that?


Whats the cleanest way to persist the db on local storage? Is making an impure sub an option? I could make an interceptor, but I don’t want to make my events.cljc impure

Vincent Cantin05:04:50

I am still a novice with re-frame and I am not sure if I am correct, but it seems that you need to create (or use) an effect handler to persist the db to the local storage.


thanks @pablore, regarding the local storage take a look here: hope it helps!


@al.vyguzov I am working on something along these lines, but haven't had tie to sit down and finish it

(def data-model
  {:re-app {:counter 0}})

(def inject-event-ns
    :id      :inject-event-ns
    :before  (fn [context]
                 (let [[evt] (get-in context [:coeffects :event])]
                      (assoc-in context [:coeffects :ns] (keyword (namespace evt)))))))
  [ inject-event-ns]
  (fn [{:keys [db ns]} [_]]
           {:db (update-in db ns :counter]  inc )}))
I am gonna wrap it in a macro re-event-ns that will inject the ns automatically... ( so the interceptor feels overkill as i can extract event ns when registering the event)... and Also reg-sub-raw brings a namespaced event keyword so a reg-sub-ns will just partial apply the ns to the db to get the correct path.. what do you think?


when doing fn-trace is it recommended to throw it indiscriminately on very event or be judicious about it. for example I have several toggle events just for if the menu is minimized or not.