Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

componentWillUpdate prevState #71

Open
tommoor opened this issue Feb 4, 2015 · 3 comments
Open

componentWillUpdate prevState #71

tommoor opened this issue Feb 4, 2015 · 3 comments

Comments

@tommoor
Copy link
Contributor

tommoor commented Feb 4, 2015

Due to react not deep cloning objects (facebook/react#2914) and the way that Delorean passes entire stores into state this makes the prevState parameter of componentWillUpdate useless. The prevState is always the current state.

thoughts?

@darcyadams
Copy link
Collaborator

my thought is that this is an excellent point. For some reason I have not run into this yet. I think the solution is related to this issue. We need to create schema keys on a sub object and set those on state directly rather than dropping them all under state.stores.

@tommoor
Copy link
Contributor Author

tommoor commented Feb 4, 2015

Agreed. For those that come across this I actually overcame the limitation for my situation by reading the state in the parent component and passing the prop in individually.

@darcyadams
Copy link
Collaborator

Been giving this a lot of thought, and the main issue is that if you apply store state properties directly to component state, you risk name conflicts. Delorean's default behavior is to give every store's state to every component. IMO, using watchStores is a no-brainer, and it will certainly lower the risk of state name conflicts, but it still exists.

Pros for this change

  • full compatibility with React's lifecycle methods
  • no more of this obnoxiousness: var myStateProp = this.state.stores.myStore. myStateProp;

Cons

  • major breaking change (upgrade path would mean visiting every render method in an app)
  • state name conflicts across stores (this could potentially be mitigated with a console.warn when it occurs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants