Skip to content

Instantly share code, notes, and snippets.

@ThomasDeutsch
Last active November 13, 2015 16:30
Show Gist options
  • Save ThomasDeutsch/8a88f6d63063e892daee to your computer and use it in GitHub Desktop.
Save ThomasDeutsch/8a88f6d63063e892daee to your computer and use it in GitHub Desktop.
;; Tab-Menu scenario:
;; Show content based on a selected tab.
;; The reader is a simple datascript pull and :selected is a {:db/valueType :db.type/ref}.
;; Idea
;; If i could specify a component not to render if only a :db/id is received,
;; then i could simply pull and render - without the conditional logic in my render-fn.
(defn concat-queries [& args]
(->> (apply concat args)
distinct
(into [])))
(defui TabMenu
static om/IQuery
(query [this]
[{:selected (concat-queries [:db/id :image/title] ;; subquery from image component: (om/get-query Image) in a real app.
[:db/id :text/title] ;; subquery from text component.
[:db/id :video/title]}]) ;; subquery from video component.
;; this results in:
;;-> [{:selected [:db/id :image/title :text/title :video/title]}]
Object
(render [this]
(let [props (:selected (om/props this)]
(dom/div nil
(some-> (:image/title props)
(image props)) ;; call component "image"
(some-> (:text/title props)
(text props)) ;; call component "text"
(some-> (:video/title props)
(video props)) ;; call component "video"
))))))
@hiram-madelaine
Copy link

If I understand correctly you put in your DataScript the current selected ref under :selected.
So the the query [{:selected [:db/id :image/title :text/title :video/title]}] should return non nil value for the selected item ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment