I haven't tried pub/sub with this yet, so much fun :-).

On Tue, May 27, 2014 at 8:55 PM, Daniel Kersten <[email protected]> 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 <[email protected]> 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 [email protected].
>> To post to this group, send email to [email protected].
>> 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 [email protected].
> To post to this group, send email to [email protected].
> 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to