Fork me on GitHub
#om-next
<
2017-01-12
>
mavbozo16:01:39

so, I'm playing around with Queries with Unions here https://github.com/omcljs/om/wiki/Queries-With-Unions. then I tried to set Graphic local state before mounting by using set-state! in componentWillMount

(defui Graphic
  static om/IQuery
  (query [this]
         [:id :type :title :image])
  Object
  (componentWillMount [this]
                      (om/set-state! this {:a 1}))
  (render [this]
    (let [{:keys [title image]} (om/props this)]
      (dom/div nil
        (dom/h3 nil (str "Graphic: " title))
        (dom/div nil image)))))

mavbozo16:01:30

then after the initial query, om.next calls defmethod read :dashboard/items again but the query inside is specific to Graphic component

mavbozo16:01:54

during the first query, the query is the query of DashboardItem

{:dashboard/post [:id :type :title :author :content :favorites],
  :dashboard/photo [:id :type :title :image :caption :favorites],
  :dashboard/graphic [:id :type :title :image :favorites]}}

mavbozo16:01:31

but the second query is the query of Graphic

[:id :type :title :image :favorites]

mavbozo16:01:18

Iinspect it by modify defmethod read :dashboard/items a bit

(defmethod read :dashboard/items
  [{:keys [state query] :as env} k _]
  (println "dashboard/items query" query)
  (let [st @state]
    {:value (into [] (map #(get-in st %)) (get st k))}))

mavbozo16:01:40

it looks like to me that setting Graphic local state also triggers om.next to re-query the DashboardItem component and Graphic component but om.next does not use the whole Union Query of DashboardItem component, just query needed by Graphic component

mavbozo17:01:12

if read :dashboard/items called with key`:dashboard/items` and query [:id :type :title :image :favorites], shouldn't it returns just the :dashboard/graphic data instead of the whole items ?

raspasov21:01:15

hey everyone, I just stumbled upon this article and I realized I can probably use this a lot https://facebook.github.io/react/docs/higher-order-components.html

raspasov21:01:14

is there “a good way/recommended way” to do this in om-next?

sova-soars-the-sora22:01:58

@rasparov Hmmmm... (defui ...) is the macro that makes components... or component blueprints. I think (om/factory ...) makes it a "react"component thingy so... my immediate naive approach is if you have some way of modifying your defui funkshns before you send them to various (om/factory)s. Maybe more experienced people can chime in

raspasov22:01:16

@sova I think you might be on the right track, yes

raspasov22:01:47

you can have… a macro that modifies the defui macro? 🙂 is that a good/possible idea? 🙂

sova-soars-the-sora23:01:06

@raspasov it sounds like a fun thing to do. i am not sure when i'd find the investment of (making a macro that funks with my other defuis) to be less than the investment of (making lots of distinct defui funkshuns). maybe if you need one million slightly different divs. i think my current "super-ambitious" app has probably 5-10 proper components. At that point I'd just make another one or two, or even 10 if I needed it. Depends on what you want to do, of course

sova-soars-the-sora23:01:49

i just learned of datascript today. such a generic term for a really cool thing. Anybody try nd pair datascript and om.next ?