-
Notifications
You must be signed in to change notification settings - Fork 330
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
Combine results React getInitialState and Reflux getInitialState #166
Comments
Hi, I also find myself in a similar situation: my store has all the models, but i want to use only that specified by an I was tempted to make another store with the single model. Or make the "all-models-store" having a For now, I put the code you are using, @max-mykhailenko, inside the render method – but I'm not 100% happy with this. |
@gpbl Now I have more interesting solution app.ModelView = React.createClass({
mixins: [Reflux.connect(AccessRightsStore, 'models')], // Don't want store models to state, but want to connect Store
getInitialState: function() {
return {model : AccessRightsStore.getModel(this.props.modelID)};
}, And in the store getModel : function (modelID) {
return _.find(this.models, function(model) {
return model.id === modelID;
});
},
// this will be called by all listening components as they register their listeners
getInitialState: function() {
if (this.models) {
return this.models;
} else {
this.models = Globals.models;
return this.models;
}
} It's a good pattern or anti-pattern? I don't now :) |
@max-mykhailenko that doesn't feel right - if you assume you have always that |
I don't want connect all models, but I don't know how to run store function I can't pass one model by props because model will be get from all models that I load in I need mixin that just run |
If you are getting it async then it won't work, because when your state changes (after the async stuff), the mixins: [Reflux.connect(AccessRightsStore, 'models')], no need to use app.ModelView = React.createClass({
mixins: [Reflux.connect(AccessRightsStore, 'models')], // Store models to state
render: function() {
var model = _.find(this.state.models, { id: this.props.modelID }); // Find the model you need
return <div>{model.id}</div>;
}
); |
I suggest further conversation be made in our discussion repo (https://github.com/reflux/discuss). @spoike and others– if there's a well-defined feature request in here that I'm missing, we can certainly reopen. |
How I can run React getInitialState after Reflux getInitialState?
The text was updated successfully, but these errors were encountered: