Fork me on GitHub

either way thanks @mikethompson and @musheddev for the insight


@lwhorton When dealing with derived data in the app-db, I find that it's best to use an interceptor to keep that data in sync. In every event that make changes to the original data, add an interceptor that will compute the derived data and update the db at the same time.


@yedi Yes, that's possible; clojure atoms can be watched for changes using add-watch... that said, not sure if it will be a very good idea to mix the redux & re-frame together. Depending on how many existing components you have, it might be way easier to just replace the connect redux wrappers with re-frame subscribe/dispatches.


instead of this:

export connect(
  state => ({
    myProp: getMyProp(state)
  dispatch => ({
    myDispatch: data => dispatch(myAction(data))
do this:
(defn MyReframeComponent []
  (let [my-prop (subscribe [:my-prop])
        my-dispatch (fn [data] (dispatch [:my-event data]))]
    (fn []
        {:myProp my-prop
         :myDispatch my-dispatch}])))


hmm reagent.core/track doesnt seem to be updating when a subscription value changes, as per mike above mentioned in his example


(defonce track-foo
  (reagent/track (fn [] (let [x @(subscribe [:foo] (dispatch [:foo/changed x]))


very peculiar, it’s like the reaction is not triggered when the values :foo point to in the db change… except if i get a reload in figwheel, in which case the track actually triggers


Hello everyone, I have a re-frame project and want to use it's components in some other project. I ran "lein install" in project a and added it as an dependency in project b. If I run project b I get an error "no such namespace". If I inspect the .jar file of project a, there are no cljs files. How do I specify, that I also want to package the cljs files? Or is there another way to use cljs files of local projects?


that normally just works @burke - have you looked inside the .jar file in your ~/.m2/respository archive to check that the .cljs files are there ?


oh, I found the mistake. :source-paths only had clj and cljc but not the cljs path.. Now its working. Thanks for answering


@mikethompson sorry to bother again, but with respect to your suggestion with (defonce a-tracker) .. is it enough to simply define this fn and use track on a subscription (ratom)? Or do I need to have this definition somewhere getting derefd every time something changes (like the db)? I can’t seem to get a simple case working with r/track


for example; if I just use a setInterval #(deref my-defonce-tracker) 1000 then everything flows properly and the subs/trackers update. but where do (or should I have to?) I wire in something to constantly be derefing this tracker? maybe inside the reg-sub definition of the thing itself that is being tracked?

Doug Kirk16:07:13

@lwhorton @mikethompson The Reagent docs for track indicates that it must be a top-level fn that you're tracking. It sets metadata on the var associated with the fn.


hmm i tried it with all sorts of variations; naming the function, tracking a ratom, to tracking a fn that tracks a ratom.. etc. I worked around it for now, but I’m not quite sure what you mean top-level fn?


unrelated; how does one reg-sub using the special :<- [:some-sub] such that the invoked fn can have the db still in the signature (is that possible)? (fn [db [some-sub]])


or do I have to (reg-sub :db identity) and do a :<- [:db] :<- [:some-sub] to get the db into my handler?

Doug Kirk17:07:18

@lwhorton top-level as in (defn named-func [&args] ...). Guess I really meant named.

Doug Kirk17:07:54

Only those get vars in the module in which they're defined, not anonymous fns.

Doug Kirk17:07:10

For instance, we have this:

(defn- defined-categories
  "reagent-trackable fn that returns a set of defined category names, in lower-case."
  (let [get-names (comp (map first) (map string/lower-case))]
    (transduce get-names conj #{} @(rf/subscribe [:taxonomy :taxonomy]))))
and then
(let [*cat-names    (r/track defined-categories)] ...)


@lwhorton Ahh, sorry, from what @kirked says it looks like my piece of code is wrong (using an annon fn). I've never had to use track myself.


This query happens enough these days that it almost warrants an FAQ entry.