Of course this does...you are triggering a re-render by swapping on the
atom that you pass into root. You could call this anywhere and it would
trigger a re-render because root sets up a watch on the data argument
that's passed in.
There are two things that I think are anti-patterns here which you
should avoid:
- calling swap!/reset!/etc. on the atom you pass in originally, inside
of component logic.
- doing anything other than setting initialization values for local
component state inside of init-state.
Can you explain why you would need to update the original value you pass
in, inside of a component, for any reason? If it needs initialization
before it can be used, that should probably happen before it's passed
into root. If it needs to get updated based on an event or a user
action, then it should get updated via transact! or update! triggered
via an event handler, or via a message passed inside a go block set up
in IWillMount.
DD
(2014/04/21 16:44), Sven Richter wrote:
> Hi,
>
> while exploring OM I found out that render-state is called twice if
> "init-state" changes the app-state.
> This small snippet demonstrates this effect:
>
> (def app-state (atom {:releases []}))
>
> (defn div-list [data owner opts]
> (reify
> om/IInitState
> (init-state [_]
> (println "init state")
> (swap! app-state assoc-in [:releases] "res"))
> ;)}))
> om/IRenderState
> (render-state [_ _]
> (println data)
> (dom/div nil "release div"))
> ))
>
> (om/root div-list app-state {:target (gdom/getElement "elem")})
>
> First "init state" is printed, then the empty "app-state" atom and then the
> "app-state" atom with the new data.
>
> Thinking about it I guess it's correct that render-state is executed twice,
> first on initialization and then after the change of the app-state.
> However I guess it would make sense too if render-state is executed only
> once, because it should be registered, after init-state was executed once.
>
> So is this expected behavior I am seeing?
> Btw. I use om 0.5.0.
>
> Best Regards,
> Sven
>
--
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.