Skip to content

Instantly share code, notes, and snippets.

@ciaoben
Created June 5, 2015 10:51
Show Gist options
  • Save ciaoben/e25af5fb59c454c22f9d to your computer and use it in GitHub Desktop.
Save ciaoben/e25af5fb59c454c22f9d to your computer and use it in GitHub Desktop.
// my component
var App = React.createClass({
getInitialState: function() {
CustomerQueries.isLogged();
return {};
},
render () {
//here my markup
}
});
// my cointainer
App = Marty.createContainer(App ,{
listenTo: CustomersStore,
fetch: {
auth: function () {
console.log("I am here!!!!"); // ---->>> it doesn't arrive here! It is like the container doens't notice the state change!
user_info = CustomersStore.for(this).getAuth();
return user_info;
}
},
failed(errors) {
console.log("failedddd", errors);
}
});
//my customersStore
var CustomersStore = Marty.createStore({
id: 'CustomersStore',
handlers: {
isLogged: UserConstants.IS_LOGGED // ----> This is the method called when with the query in my component in getInitialState()
},
getInitialState: function () {
CustomerQueries.isLogged(); // I am trying to call it even from here, and they both arrive to isLogged, because I see my state changing
},
isLogged: function (userData) { // if the resources of the response are null, is not logged
if(userData.resources){
this.setState({auth: 1});
}else{
this.setState({auth: 0});
}
},
// It never arrive here!!!!! I don't know why!
getAuth: function (){
console.log("Now I am here!!!");
return this.fetch({
id: "logged-in",
locally: function () {
return this.state;
},
remotely: function () {
return CustomerQueries.isLogged();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment