om-next

mavbozo 2017-01-12T16:29:39.000262Z

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

mavbozo 2017-01-12T16:31:30.000264Z

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

mavbozo 2017-01-12T16:32:54.000265Z

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

mavbozo 2017-01-12T16:33:31.000266Z

but the second query is the query of Graphic

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

mavbozo 2017-01-12T16:36:18.000267Z

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

mavbozo 2017-01-12T16:39:40.000268Z

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

mavbozo 2017-01-12T17:08:12.000270Z

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 ?

raspasov 2017-01-12T21:39:15.000271Z

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

raspasov 2017-01-12T21:40:14.000274Z

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

sova-soars-the-sora 2017-01-12T22:15:58.000275Z

@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-soars-the-sora 2017-01-12T22:16:07.000276Z

@raspasov *

raspasov 2017-01-12T22:17:16.000277Z

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

raspasov 2017-01-12T22:19:47.000278Z

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

sova-soars-the-sora 2017-01-12T23:35:06.000281Z

@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-sora 2017-01-12T23:59:49.000282Z

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