Reputation: 15464
I have 2 stores like below
store 1
export default class ContactInformationModel {
@observable id;
@observable type;
@observable description;
@observable mode;
constructor(id,type,description,mode,show) {
this.id=id;
this.type=type;
this.description=description;
this.mode=mode;
}
}
export default class ContactInformationController {
@observable contact_informations = [];
addContactInformation(data){
var id= data.hasOwnProperty("id") ? data.id: this.getInsertedId(data.mode); //auto increment for store mvc;
var type=data.type;
var description=data.description;
var mode=data.mode;
this.contact_informations.push(new ContactInformationModel(id,type,description,mode));
}
@computed get SellerContact(){
return this.contact_informations.filter(c => c.mode == 'seller');
}
}
Store 2
import ContactInformationController from './ContactInformationController';
var contact_information_store=new ContactInformationController();
export default class SellerController {
@observable seller = {}; //only one entry
saveSellerContact(){
//pull contact_information_store
var contact_information=contact_information_store.SellerContact;
}
}
when I print contact_information it is blank array however it is rendered in jsx . I am still new on react / mobx , any help will be appreciated . Thanks
Upvotes: 2
Views: 1116
Reputation: 112777
I think the issue is that you have two different instances of the ContactInformationController
class. It will be resolved if you export an instance of ContactInformationController
instead, so you use the same instance over the entire app.
class ContactInformationModel {
@observable id;
@observable type;
@observable description;
@observable mode;
constructor(id, type, description, mode, show) {
this.id=id;
this.type=type;
this.description=description;
this.mode=mode;
}
}
class ContactInformationController {
@observable contact_informations = [];
addContactInformation(data){
var id= data.hasOwnProperty("id") ? data.id: this.getInsertedId(data.mode); //auto increment for store mvc;
var type=data.type;
var description=data.description;
var mode=data.mode;
this.contact_informations.push(new ContactInformationModel(id,type,description,mode));
}
@computed get SellerContact(){
return this.contact_informations.filter(c => c.mode == 'seller');
}
}
export { ContactInformationModel };
export default new ContactInformationController();
Upvotes: 2