On Thursday, June 18, 2015 at 5:21:18 PM UTC+10, Atamert Ölçgen wrote:
> Hi,
> 
> 
> Reagent makes it easy to manage the state but I couldn't find a clean and
> straightforward way to manage a component tree. I have a component with local
> state that may be installed at some point (or not at all) and then may become
> unnecessary later. Say, I have a parent-component and child-component both 
> follow this template:
> 
> 
> (defn component [state-atom & other-config]
>   (reset! state-atom initial-state)
>   (let [... other bindings here ...]
>     (fn []
>       ... rendering ...)))
> 
> 
> 
> 
> This way I can write my component like it has isolated local state, or I
> can add a second arity and create my ratom there to make it really local. But
> state is not my main issue.
> 
> 
> Question 1: I create my event handlers in the let and then assign them by name
> in rendering function to avoid having them re-created every time rendering
> function is called. Does this make sense? Is it better to just define them
> inline and why?

Either way is fine.  It depends what values you want to "close over" in your 
event handlers. 

> 
> Question 2: child-component is created in the let block of parent-component. 
> As
> far as I understand the child-component will be mounted and unmounted based on
> whether parent-component's rendering function calls its rendering function. Is
> this true?

Each component (child and parent in your case) has its own (React) lifecycle 
functions and can be rendered separately.

If the parent is re-rendered, then the hiccup for the child will be returned. 
If that hiccup is the same as last time  (same parameters) then the renderer 
for the child will not be re-run. 


> 
> 
> Question 3: What is the idiomatic way to dispose of a component itself? Should
> I use an atom and reset! it to nil when I'm done?

You don't have to actively dispose of components. When they are no longer a 
part of the hiccup tree, they disappear. Nothing you need to do. 


--
Mike

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