Fork me on GitHub
#re-frame
<
2017-10-08
>
jvuillermet00:10:11

This would need confirmation but I think aget should be used for arrays

jvuillermet00:10:17

and use goog.get for object

danielcompton19:10:24

yep, use that in general. I don't think it's such a big problem for the specific case of -target -value, as those are properties of the JS events which aren't going to be renamed by the Closure Compiler. Nevertheless goog.get is probably a better default choice to use everywhere

madstap21:10:27

To render a page, i need to grab some data from an API (a CMS). How would you do this? In my app I just made an event, :foo/fetch, which gets the data from the api and puts it in the db where :foo/data knows where to get it. Is this a sane way to do this?

(ns foo.views
  (:require
   [re-frame.core :as rf]
   [reagent.core :as r]))

(defn foo-render [data]
  [:div data])

(defn foo-page []
  (r/with-let [_ (rf/dispatch [:foo/fetch])]
    (let [data @(rf/subscribe [:foo/data])]
      (when data [foo-render data]))))

mikethompson21:10:12

@madstap ^^^ You are trying to emulate what you have done in React which is to "load data on mount". But that's not the way we tend to do things in re-frame. Note in particular the link to: https://purelyfunctional.tv/article/react-vs-re-frame/

madstap22:10:59

Yeah, I actually have no experience with react, so I've independently invented this anti-pattern all on my own 🙂

madstap22:10:11

Since this is just the basic page data, maybe it would make more sense to do this fetching in my :routes/set-page handler then?

madstap22:10:55

Thanks for the links, they seem to say that, yes, definitely do this stuff wherever the page change event happens. That makes sense.