This code changes state in response to other state changes, so there is no 
place it can go other than IWillUpdate.  (It is updating :constrain to match 
:cell-dimension changes using size information read from the dom.) Further, 
:constrain is only read by the render phase (to pass down to a child 
component), so modifying it will not mess up react or om's change-detection.

Normally using set-state in in the WillUpdate phase is bad because 
WillReceiveProps and ShouldUpdate have already run and didn't see the new 
state. However if they do not depend on any state change you make in WillUpdate 
and only render needs to read these changes, you should be fine.

The docs are transliterated from the react docs: 
http://facebook.github.io/react/docs/component-specs.html#updating-componentwillupdate

React's component.setState() *will* complain if you try to set state, but 
om/set-state! does not use react's setState under the hood. (It modifies state 
directly.)

However you shouldn't make a habit out of changing state in IWillUpdate if you 
can avoid it.


On Wednesday, December 31, 2014 5:42:49 AM UTC-6, Andrew wrote:
> According to the docs for IWillUpdate:
> 
> Note:: You cannot update local component state in this method. If you wish to 
> change local state in response to prop changes use IWillReceiveProps.
> 
> I want to make sure I am interpreting this correctly. Seemed straightforward 
> until I saw this:
> 
> https://github.com/swannodette/om/blob/master/examples/sortable/src/core.cljs#L249
> 
> Is this not at odds with the docs? Unless the docs are to be taken literally 
> and update-state! cannot be used while set-state! can. I doubt that's the 
> issue, but hopefully someone can clear it up.
> 
> Andrew

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