This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-12
Channels
- # aws (21)
- # aws-lambda (8)
- # beginners (53)
- # boot (56)
- # braveandtrue (1)
- # cider (49)
- # cljs-dev (8)
- # cljsjs (1)
- # cljsrn (57)
- # clojure (403)
- # clojure-austin (17)
- # clojure-dusseldorf (10)
- # clojure-greece (9)
- # clojure-spec (57)
- # clojure-uk (144)
- # clojurescript (60)
- # datomic (149)
- # docker (1)
- # emacs (1)
- # hoplon (23)
- # humor (1)
- # jobs (1)
- # leiningen (2)
- # luminus (1)
- # off-topic (1)
- # om (24)
- # om-next (15)
- # onyx (23)
- # protorepl (2)
- # re-frame (58)
- # reagent (90)
- # remote-jobs (1)
- # ring-swagger (4)
- # slackpocalypse (1)
- # spacemacs (2)
- # specter (18)
- # untangled (4)
- # vim (1)
- # yada (27)
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)))))
then after the initial query, om.next 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]}}
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 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
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 https://facebook.github.io/react/docs/higher-order-components.html
@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
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 om.next ?