I'm having a problem with Om getting shared to propagate to child components.
The shared map gets passed to the root, but children of the root get nil on a
call to om/get-shared. I've tried a number of things, but have concluded it
must be the way I'm calling build on the children.
Seems like a long shot given the google results I (haven't) found, but I'm
curious if anyone else has had this problem.
Here's the code (it's my experiments with building up a table):
(defn- cell-builder [cell-props]
(fn [data owner]
(let [c (om/get-shared owner :click)]
(reify
om/IRender
(render [_] (dom/td (clj->js {:onClick #(put! c {:topic :click :text
(str data)})}) (str data)))))))
(defn- row-builder
([row-props] (row-builder row-props {}))
([row-props cell-props]
(fn [row-data owner]
(reify
om/IRender
(render [_]
(let [cols (:cols row-data)
data (map #(get (:data row-data) %) cols)]
(apply dom/tr (clj->js row-props)
(map #(om/build (cell-builder cell-props) %) data))))))))
(defn- extract-row [index cursor]
{:cols (mapv :key (:cols cursor))
:data (get-in cursor [:data index])})
(defn- extract-header-row [cursor]
(let [cols (:cols cursor)
col-keys (mapv :key cols)
display-names (mapv :display-name cols)]
{:cols col-keys
:data (zipmap col-keys display-names)}))
(defn table [app owner]
(let [cols (select-keys app [:cols])]
(dom/table nil
(dom/thead nil
(om/build (row-builder {} {}) app {:fn extract-header-row}))
(apply dom/tbody nil
(for [index (range (count (:data app)))]
(om/build (row-builder {}) app {:fn (partial extract-row index)}))))))
Here's the root call from another namespace (some vars not listed here):
(om/root
tbl/table
state
{:target (. js/document (getElementById "table"))
:shared {:click click-pub-chan}})
The call to table has the shared state. The calls to both row-builder and
cell-builder don't.
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.