The last message were obviously few months ago. I'm not too sure what I was
thinking about then. What I do in my code is I have a pub/sub message bus
channel that's shared between all components, so doing this isn't a big
deal. But in absence of that, you're absolutely right: I'd either just pass
the parents owner or I'd pass a callback that captured the owner as a
closure. Keep simple things simple.

On Thu, 4 Dec 2014 10:31 Andrew <andrew...@gmail.com> wrote:

> While I can appreciate the core.async approach mentioned here, is it
> considered either bad practice or impossible to simply pass owner from a
> parent to a child component, perhaps the child stores owner in its own
> state and uses set-state! on this parent owner rather than its own owner?
>
> The advantage would be that for simple communication between a parent and
> child, you don't mess with the core.async "infrastructure" which involves
> the setup, putting, taking, and properly closing of channels, which, while
> useful perhaps for larger mechanisms, seems like overkill for quite simple
> needs.
>
> On Wednesday, May 28, 2014 2:55:53 AM UTC+2, Daniel Kersten wrote:
> > I use core.async for this - pass a channel to the child, have the child
> put messages on it when events occur and have the parent modify its own
> state in response to child events.
> >
> >
> > Something like this would work:
> >
> >
> >
> >
> >
> > (defn child [props owner {:keys [ch]}]
> >
> >
> >   (reify
> >     om/IInitState
> >
> >
> >     (init-state [_]
> >
> >
> >       {:text ""})
> >
> >
> >     om/IRenderState
> >     (render-state [_ {:keys [text editable?]}]
> >
> >
> >       (dom/div nil
> >
> >
> >         (if editable?
> >           (dom/input ...)
> >
> >
> >           (dom/div nil text))
> >
> >
> >         (dom/button #js {:onClick #(async/put! ch :no-edit)}
> >
> >
> >           "No Edit")))))
> >
> >
> >
> > (defn parent [props owner opts]
> >
> >
> >   (reify
> >     om/IInitState
> >
> >
> >     (init-state [_]
> >
> >
> >       {:ch (async/chan)
> >
> >
> >        :editable? true})
> >
> >
> >     om/IWillMount
> >     (will-mount [_]
> >
> >
> >       (async/go-loop []
> >
> >
> >         (when-let [value (async/<! (om/get-state owner :ch))]
> >
> >
> >           (condp = value
> >
> >
> >             :no-edit (om/set-state! owner :editable? false))
> >
> >
> >           (recur))))
> >
> >
> >     om/IRenderState
> >     (render-state [_ {:keys [editable? ch]}]
> >
> >
> >       (om/build child props {:state {:editable? editable?}
> >
> >
> >                              :opts ch}))))
> >
> >
> >
> >
> > In my own code, I always put [topic value] on my channel and have one
> channel shared between all of my components and components can subscribe to
> various topics using async/sub.
> >
> >
> >
> >
> >
> >
> >
> > On 28 May 2014 01:14, Jamie Orchard-Hays <jami...@gmail.com> wrote:
> >
> >
> > I have a component that uses om/build to render an editable section. The
> parent has :editable? local state. Is there a way for the child to set the
> true/false value of this on the parent? So far haven't discovered how this
> might be done.
> >
> >
> >
> >
> >
> > Cheers,
> >
> >
> >
> > Jamie
> >
> >
> >
> > --
> >
> > 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 clojurescrip...@googlegroups.com.
> >
> > To post to this group, send email to clojur...@googlegroups.com.
> >
> > Visit this group at http://groups.google.com/group/clojurescript.
>
> --
> 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.
>

-- 
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