Fork me on GitHub

so, I'm playing around with Queries with Unions here 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])
  (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)))))


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


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


but the second query is the query of Graphic

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


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


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


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 ?


hey everyone, I just stumbled upon this article and I realized I can probably use this a lot


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


@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


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


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


@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


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