omcljs / om

ClojureScript interface to Facebook's React
6.65k stars 364 forks source link

A component that implements IQuery needs data returned, otherwise even statically defined dom elements do not get rendered. #891

Open livtanong opened 7 years ago

livtanong commented 7 years ago
(defmulti read om/dispatch)

(defmethod read :default
  [{:keys [state]} k _]
  (let [st @state]
    {:value (get st k)}))

(defmethod read :foo
  [{:keys [state query]} k _]
  (let [st @state]
    (if-let [d (get st k)]
      {:value (when-let [d (get st k)]
                (om/db->tree query d st))}
      {:remote true})))

(defui SomeComponent
  static om/IQuery
  (query [_]
    [:foo
     ;; The text in the render function will only show up if either :foo has a value, or :bar is added to this query.
     ])
  Object
  (render [this]
    (dom/div nil "No matter what, this should render")))

(def parser (om/parser {:read read}))

(def reconciler
  (om/reconciler
   {:parser parser
    :state {:bar 42}}))