Fork me on GitHub
#re-frame
<
2017-08-30
>
akiroz08:08:09

^ +1 But I guess it's probably easier to wrap an existing react DnD lib like this: https://github.com/atlassian/react-beautiful-dnd

reefersleep10:08:10

I used Html5 for dnd only to discover that it only worked in Chrome (or at least not in Firefox)

facundo12:08:10

Hi everyone, from reading the docs I understand one of the goals when writing re-frame apps is to keep the views as dumb as possible. When we need to do some processing over the db data, we should put that logic in the subscription handlers

facundo12:08:38

I’m currently working on a view that has some complex logic, but it’s not related to db data or an external data source

facundo12:08:13

specifically I’m building a calendar, which needs a lot of dates calculations to come up with the correct list and order of dates to display, etc

facundo12:08:24

that data doesn’t seem to fit in a subscription handler

facundo12:08:58

I wonder if the way to go is just to have helper functions and call them in the view

mccraigmccraig13:08:23

@facundo you can create a (perhaps parameterised) sub which returns the data for the view filtered and in the correct order

facundo13:08:15

ok, so you’d say it’s idiomatic to resort to subs even if you don’t need on external data

facundo13:08:34

like, hey this is the data I got for the view, process it so I can display it

mccraigmccraig13:08:41

not sure what you are meaning by "external data" - if it's a calendar view it will perhaps have something like the focus-month, which you would have in your app-db... then a sub could work with that to give lists of day/dates etc

facundo13:08:11

the thing here it’s that’s a whole year calendar

facundo13:08:14

I can have a focus year

facundo13:08:48

but then I need a function that takes year/month and shows the month’s calendar

facundo13:08:15

for context:

(defn month-view
  [year month]
  [:div.calendar
   [:div.calendar-nav [:div (format/month-string year month)]]
   [:div.calendar-container
    [:div.calendar-header
     (for [day [“Mon” “Tue” “Wed” “Thu” “Fri” “Sat” “Sun”]]
       [:div.calendar-date day])]
    [:div.calendar-body
     (for [day (month-seq year month)]
       [day-view month day])]]])

facundo13:08:44

that month-seq function is doing a bunch of calculations, that’s the candidate to go into a sub

mccraigmccraig13:08:40

if you really don't have any state then helper-fns will be fine - if there is some state then you can wrap those helper-fns in subs - it needn't make much difference to your view code

facundo13:08:50

that was my initial hunch, I’m using subs to query for stuff like what’s today’s date

leontalbot15:08:47

hello! Do you have a living example (source code) of larger re-frame app that has multiple events.cljs etc. ?

sandbags16:08:05

@leontalbot i can't think of any, but is there something in particular you are looking to understand?

sandbags16:08:24

re-frame is - in practice - pretty simple once you have the cycle clear in your mind, that's not really an issue of app scale although there are some good practice like namespacing your keys

leontalbot16:08:49

@sandbags Thank you for answering

leontalbot16:08:54

` src ├── core.cljs <--- entry point, plus history ├── db.cljs <--- schema, validation, etc (data layer) ├── subs.cljs <--- subscription handlers (query layer) ├── views.cljs <--- reagent components (view layer) └── events.cljs <--- event handlers (control/update layer) ├── panel1 ├── db.cljs <--- schema, validation, etc (data layer) ├── subs.cljs <--- subscription handlers (query layer) ├── views.cljs <--- reagent components (view layer) └── events.cljs <--- event handlers (control/update layer) ├── panel2 ├── db.cljs <--- schema, validation. etc (data layer) ├── subs.cljs <--- subscription handlers (query layer) ├── views.cljs <--- reagent components (view layer) └── events.cljs <--- event handlers (control/update layer)

leontalbot16:08:09

I have something like the following and want to know to manage projet.panel1.events without getting in conflict with projet.events

leontalbot16:08:55

I don’t see any name conflicts as such but my routing is behaving weirdly and it seems that I sometimes need to call projet.panel1.events in projet.panel1.views and sometime not

leontalbot16:08:03

only in core.cljs

akiroz16:08:03

@leontalbot usually you'd use fully-qualified keywords for larger re-frame apps

leontalbot16:08:05

@akiroz Thanks! Still i can’t see any name conflicts hmmm…

leontalbot16:08:52

I am sure it is obvious.

akiroz16:08:28

are you using any debugging tools like re-frisk to see what's going on in your app?

leontalbot16:08:56

yes I use refrisk

sandbags16:08:22

@leontalbot "I sometimes need to call projet.panel1.events in projet.panel1.views" <-- means?

sandbags16:08:57

One possible interpretation i can make is that you need to :require namespaces with events or subs from core because otherwise they won't get registered

sb19:08:06

(defn render-chart-placement
   []
   [:div {:style {:min-width "310px" :max-width "800px" 
                 :height "400px" :margin "0 auto"}}])

  (defn render-chart-fn 
   [this]
   (let [config-at (r/children this)]
       (prn "config-at" (pprint config-at))  
      
        #(js/Highcharts.Chart. (r/dom-node this) (clj->js config-at)) ))
  
;;
(defn render-chart []
  (r/create-class
    {:component-did-update render-chart-fn
     :component-did-mount render-chart-fn 
     :reagent-render render-chart-placement
     }))


;; data re-frame subscription test - counter
(defn render-chart-fn-container
    []
    (let [count (re-frame/subscribe [:count])
          config-at (reaction {:chart {:type :bar}
                               :title {:text (str @count)}
                               :xAxis {:categories ["Apples", "Bananas", "Oranges"]}
                               :yAxis {:title {:text "Fruit eaten"}}
                               :series [{:name "Jane" :data [1, 0, 4]}
                                        {:name "John" :data [5, 7, 3]}]})]
    (fn []
        [render-chart @config-at]
        ;(prn config-at) 
         )))

sb19:08:48

Could you help me? I see at r/children(reagent) nil. I don’t know why.

mikethompson22:08:00

@sb I know your question is about r/children but perhaps this higher level document will help: https://github.com/Day8/re-frame/blob/master/docs/Using-Stateful-JS-Components.md

sb23:08:12

Thanks!