Fork me on GitHub
#re-frame
<
2017-08-21
>
rnagpal02:08:55

@mikethompson in the documentation line https://github.com/Day8/re-frame/blob/master/docs/SubscriptionFlow.md I see

(re-frame.core/reg-sub-raw   ;; it is part of the API
  :query-id     ;; later use (subscribe [:query-id])
  some-fn)      ;; this function provides the reactive stream
(defn some-fn 
  [app-db event]    ;; app-db is not a value, it is a reagent/atom
  (reaction (get-in @app-db [:some :path])))  ;; returns a reaction
Why do we have event as second param ?

rnagpal02:08:55

Also when we reg-sub and pass subscriptions like

(fn [query-v _]     
    [(subscribe [:todos])
     (subscribe [:showing])])
` Will the new result be only evaluated when something changes at the path in DB or anything changes in the DB ?

mikethompson04:08:18

@rnagpal > Why do we have event as second param ? Because sometimes additional parameters are supplied in the subscribe. For example the view might: (subscribe [:items "blue"]) So the additional value "blue" will change what is subscribed to. And that might be important in terms of the "inputs" fn. So the entire query vector is supplied to both the computation function and the inputs function, just in case. > Will the new result be only evaluated when something changes at the path in DB or anything changes in the DB ? Layer 2 nodes, which depend directly on app-db will ALWAYS be recalculated whenever app-db changes in any way. BUT further propagation through the signal graph (to Layer 3 and 4) will be pruned if the value extracted this time is the same as last time. Described here: https://github.com/Day8/re-frame/blob/master/docs/SubscriptionInfographic.md

cmal10:08:56

Hi, if I set a timer in the event handler and want to record the timer's id for later to clear the timer, can I use the following code ? I found it not pure but because reg-fx do not have return value so I can not set the timer in reg-fx and get the id. Is there a better way to do this?

(reg-fx
 :clear-timer
 (fn [timer]
   (when timer (js/clearInterval interval))))

(reg-event-fx
 :change-timer
 (fn [{:keys [db]} [_ old-timer time-interval-id]]
   {:clear-timer old-timer
    :db (assoc db
               :timer-id (js/setInterval
                          #(rf/dispatch [:inc-time])
                          (get time-intervals time-interval-id)))}))

andrea.crotti12:08:30

any suggestions about how to do localization (just a couple of languages) in a re-frame project?

andrea.crotti12:08:46

I saw tongue and tempura, any other suggestions?

mikethompson12:08:58

@cmal you should provide the id for the interval when you create it. And then, when you want to remove it, provide the id again to identify which one.

akiroz20:08:34

is there any way to dispatch an event only if it exists? some of my panels have an init event but some don't, I'd like to dispatch :<panel>/init only if it exists.'

akiroz20:08:50

my current workaround involves poking around with re-frame's private(?) / un-documented APIs

akiroz20:08:09

another question, is there an existing library that'll help me construct reg-event-* with extra interceptors? I seem to be using trim-v in every project. Thinking of something like this:

(def reg-event-fx
  (push-interceptors [trim-v] ;; add them to the back
    re-frame/reg-event-fx))

(def reg-event-fx
  (unshift-interceptors [trim-v] ;; add them to the front
    re-frame/reg-event-fx))

lepistane20:08:12

i am collecting resources for re-frame so far i found - docs(github readme), lamda island, http://pf.tv blogs 1 where can i find examples of web apps made using re-frame? maybe some of your personal projects that are public? 2 are there any introductory blogs, posts, resources besides those listed where i can learn more about it? the more basic the better. i like it when someone holds my hand for first 100 meters

mikethompson21:08:10

> is there any way to dispatch an event only if it exists? Not at the moment

mikethompson21:08:35

@lepistane please see "External Resources" document in /docs