Actually, it turns out if you call a child with a merged {:shared ...} argument 
to pass shared values down the subtree.  

(om/build child app {:shared {:actions (merge-actions owner {...})}})

You can tighten this up with macros, etc.  Hopefully David won't make this 
impossible in future versions because I find it INSANELY useful both for 
testing and for selective overrides of default state.   

For example, I've had issues with the somewhat non-deterministic behavior and 
operational latency of core.async particularly in the mobile app / browser 
context at scale (especially on the abandoned Pedestal App 0.3 which we have in 
limited production).  

In our current project, we've dropped core.async and instead manage all side 
effects via direct transacts on cursors and calls to "actions" which are passed 
in shared state from the root of the tree via shared.  We use controller 
components to coordinate the behavior of sets of related components (like all 
the authentication screens of a mobile app) which capture all the child actions 
and then call the service layer actions passed into the root.  Most of our 
interactions fall into these camps:

Event -> om/set-state!
Event -> om/transact!
Event -> Action -> Service Call -> (swap! data ...)
Event -> Action -> Service Call -> Callback -> om/transact!
Event -> Action -> Parent Handler -> Action -> Service Call ...

Actions are synchronous and explicitly named, so short and easy to reason 
about.  We added callbacks to handle things like 'loading' notifications, error 
handling, etc.  Again, lightweight.  For heavy interactions, the service calls 
just side effects the top level atom, or....

We manage most of our state in a client-side database (NativeStore) that does 
per-query dependency tracking so we can automatically call refresh! on 
components that have stale state (open source project at github 
vitalreactor/derive).  We'll post about this when we get our app done and roll 
out v0.2 of the derive library and nativestore.



On Tuesday, September 23, 2014 4:38:33 AM UTC-7, Michiel Borkent wrote:
> What I would like to see is something like :shared but only shared within a 
> subtree, so for example:
> 
> (defn child [app owner]
>   (om/component
>     (dom/p nil (str "Yo, I've got"
>                            (om/get-shared owner :some)
>                            :state))))
> 
> (defn parent [app owner]
>   om/IShared
>   (shared [_]
>      {:some :state})
>   om/IRender
>   (render [_]
>     (om/build child app))
>  
> This way you can share state with child components and you don't have to deal 
> with channels/callbacks as much in certain situations. What do you think?

-- 
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 clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to