2017-05-18 2 views
0

Ich habe 2 Speicher nämlich AttachmentStore und CommentStore.So aktualisieren Sie einen Laden von anderen Speicherfunktion

export class AttachmentStore { 
    @observable attachments = [] 
} 

export class CommentStore { 
    @observable comments = [] 

    save_comment_and_attachment(comment, attachments) { 
    this.comments.push(comment); 
    //how can I push the attachment to the 
    //attachments observable 
    } 

} 

Ich weiß, ich Anhänge als Teil CommentStor Observablen erklären kann, aber ist es eine Möglichkeit, Anhänge beobachtbaren von CommentStor aktualisieren kann?

Antwort

1
export class AttachmentStore { 
    @observable attachments = []; 

    @action add(attachments) { 
    // ... 
    } 
} 

export class CommentStore { 
    @observable comments = []; 
    attachmentStore = null; 

    init(stores) { 
    this.attachmentStore = stores.attachmentStore; 
    } 

    @action save_comment_and_attachment(comment, attachments) { 
    this.comments.push(comment); 
    this.attachmentStore.add(attachments); 
    } 
} 

const stores = { 
    attachmentStore: new AttachmentStore(), 
    commentStore: new CommentStore(), 
}; 
Object.values(stores) 
    .filter(store => store.init) 
    .forEach(store => store.init(stores)); 
+0

Große Antwort. Ich habe die gleiche Antwort gefunden, indem ich den Laden an den Laden weitergeleitet habe, der ihn aktualisieren möchte. – rechie

Verwandte Themen