Fork me on GitHub
#re-frame
<
2017-10-17
>
cmal02:10:31

Hi, does dispatch-nguarantees the order of the the events being dispatched?

cmal02:10:00

I want to make a tip to flash, whenever a button is pressed, and fadeout after that. If the button is pressed in succession, I want the tip to stop fadeout and show from the start(and then fadeout). I write a reg-event-db event handler in :dispatch to make the tip to show, and another event handler in :dispatch-later to make the tip to fadeout.

cmal02:10:55

I want to add a :deregister-event-handler to cancel the process of showing and fading out. and :dispatch again.

cmal02:10:01

Am I right to do this?

cmal02:10:43

So I want to write this: {:dispatch-n (list [:deregister-event-handler [:show :fadeout]] [:show]) :dispatch-later [{:ms 200 :dispatch [:fadeout]}]}

lovuikeng03:10:53

re-frame is used to drive deep learning development https://github.com/bpiel/guildsman

danielneal09:10:29

If I want to wrap every reframe event handler in a try-catch that reports, should I write my own , wrapper version of reg-event-fx?

danielneal09:10:06

(I'm on react native, and sometimes the only error reporting I have is "there was an error somewhere" - would love to narrow it down to a handler)

danielneal10:10:04

^ I did this

danielneal10:10:05

(defn reg-event-fx
  ([name f]
   (reg-event-fx name [] f))
  ([name interceptors f]
   (re-frame.core/reg-event-fx name interceptors (fn [& args] (try
                                                                (apply f args)
                                                                (catch :default e
                                                                  (throw (js/Error. (str "Error handling " name "\n\n" (oget e "message"))))))))))
(defn reg-event-db
  ([name f]
   (reg-event-db name [] f))
  ([name interceptors f]
   (re-frame.core/reg-event-db name interceptors (fn [& args] (try
                                                                (apply f args)
                                                                (catch :default e
                                                                  (throw (js/Error. (str "Error handling " name "\n\n" (oget e "message"))))))))))

danielneal10:10:32

is that a bad idea?

yury.solovyov12:10:35

Am I getting it right that routing in re-frame based app usually happens via setting some key in db and then matching components against it?

yury.solovyov12:10:24

Seems like secretary wants you to do that

mccraigmccraig12:10:50

yes, pretty much everything view-related in re-frame happens that way @yury.solovyov

lovuikeng14:10:58

yes, @yury.solovyov , you may use re-frame-template +routes which gives you secretary convention

;; event 
(re-frame/reg-event-db
 :set-active-panel
 (fn [db [_ active-panel]]
   (assoc db :active-panel active-panel)))

;; view   
(defn- panels [panel-name]
  (case panel-name
    :home-panel [home-panel]
    :about-panel [about-panel]
    [:div]))

(defn show-panel [panel-name]
  [panels panel-name])

(defn main-panel []
  (let [active-panel (re-frame/subscribe [:active-panel])]
    (fn []
      [show-panel @active-panel])))

yury.solovyov15:10:34

I have an app already, just need to add secretary I guess

lovuikeng15:10:40

np @yury.solovyov re-frame-template is like treasure hunt 🙂