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

Question about getModel() #1

Closed
lynnaloo opened this issue Sep 16, 2014 · 7 comments
Closed

Question about getModel() #1

lynnaloo opened this issue Sep 16, 2014 · 7 comments

Comments

@lynnaloo
Copy link

https://github.com/jhudson8/backbone-reaction/blob/master/backbone-reaction.js#L819
This is dependent on the model being sent to the form as a prop, but what about cases where the model is a property in the state?

For example, I have one form where the model changes depending on which item you select. Then I setState on the form component whenever a new item is selected. I'm trying to figure out if this is a use-case that you're just not supporting, or maybe there is a better way I can do this.

@lynnaloo
Copy link
Author

@jhudson8
Copy link
Owner

You can always call setModel directly (this method is exposed using the "modelAware" mixin. This will basically force-set whatever model you choose.

Additionally, you can choose to override the getModel method. This can be done because all of these mixins use react-mixin-manager

React.mixins.replace('modelAware', {
  getModel: function() { ... },
  setModel: function() { ... }
});

@lynnaloo
Copy link
Author

Thanks!

@lynnaloo
Copy link
Author

If I try to call setModel directly (from the parent component where the new model is located), then I get this error : "Invariant Violation: replaceProps(...): You called setProps or replaceProps on a component with a parent. This is an anti-pattern since props will get reactively updated when rendered." I'm going to put the model back in the component state and override that mixin.

@jhudson8
Copy link
Owner

ok I'll take a look at that. thanks

@jhudson8
Copy link
Owner

in that case I suppose that it does make sense to pull it from state so I can set it within the state if the setModel method is used. I actually put that method there but have never had the need to use it

@jhudson8
Copy link
Owner

0.9.2 has just been release which should resolve this problem (state is now used when setModel is called)

Also, you can use props.model or props.collection when associating a model with a component (if not using setModel)

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