Ah, sorry, one correction - this line:
(dom/input ...)
*IS* incomplete and you will need to edit it to your needs.


On 20 June 2014 22:10, Daniel Kersten <dkers...@gmail.com> wrote:

> Re: opts vs component local state, opts does not take part in the normal
> Om state management (its not a cursor, its not component local state) and
> does not trigger rerenders. Nor is it global like the shared state which is
> shared between all components. opts seems to be commonly used for
> configuration data.
>
> Whether to pass channels through opts or local state seems to be a matter
> of personal taste. Unless it can change there's no real reason I can think
> of to prefer local state.
>
> On the other hand, the parent component does store it in local state (in
> the same way that the tutorial does) and this is done because the parent
> owns the channel and local state allows it to control its lifecycle (create
> it in init-state, close it in will-unmount, replace it with om/set-state!
> etc).
>
> Re: incomplete code. Looks strange in what way? Its a fairly minimal
> example and it omits the namespace declaration, app state definition and
> call to om/root, but those two components are complete (except the :opts
> typo!)
>
>
> On 20 June 2014 20:24, Tony Tam <ttasteri...@gmail.com> wrote:
>
>> Your example looks a bit unusual. Is it incomplete? (Not saying that it's
>> wrong, just strange)
>>
>> On Tuesday, May 27, 2014 5:55:53 PM UTC-7, 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