This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-04-07
Channels
- # beginners (166)
- # cider (6)
- # cljs-dev (12)
- # cljsrn (64)
- # clojure (71)
- # clojure-chicago (1)
- # clojure-spec (14)
- # clojure-uk (2)
- # clojurescript (25)
- # datomic (2)
- # docs (1)
- # duct (1)
- # emacs (4)
- # fulcro (5)
- # graphql (3)
- # java (46)
- # mount (5)
- # off-topic (29)
- # onyx (1)
- # portkey (10)
- # re-frame (12)
- # remote-jobs (1)
- # shadow-cljs (46)
- # spacemacs (1)
- # specter (4)
- # vim (2)
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])}
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 ?
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?
polite-ping @U051MTYAB
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
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.
See the domino 3 https://raw.githubusercontent.com/Day8/re-frame/master/images/Readme/6dominoes.png
thanks @pablore, regarding the local storage take a look here: https://github.com/jacekschae/conduit/blob/master/src/conduit/db.cljs 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
(re-frame.core/->interceptor
:id :inject-event-ns
:before (fn [context]
(let [[evt] (get-in context [:coeffects :event])]
(assoc-in context [:coeffects :ns] (keyword (namespace evt)))))))
(rf/reg-event-fx
:re-app/inc-counter
[ 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?Thanks @jacek.schae