Fork me on GitHub
#re-frame
<
2017-07-13
>
lwhorton00:07:30

either way thanks @mikethompson and @musheddev for the insight

akiroz02:07:38

@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.

akiroz02:07:14

@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.

akiroz02:07:20

instead of this:

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

lwhorton05:07:07

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

lwhorton05:07:48

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

lwhorton06:07:55

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

burke10:07:54

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?

mccraigmccraig10:07:02

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 ?

burke10:07:02

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

lwhorton15:07:18

@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

lwhorton15:07:22

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.

lwhorton16:07:21

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?

lwhorton16:07:19

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]])

lwhorton16:07:04

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)] ...)

mikethompson22:07:36

@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.

mikethompson22:07:31

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