2017-05-18 12 views
0

2 개의 상점, 즉 AttachmentStore 및 CommentStore가 있습니다.다른 상점에서 상점을 갱신하는 f}

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 
    } 

} 

은 내가 CommentStore의 관찰 가능한의 일부로 첨부 파일을 선언 할 수 있습니다 알고 있지만, 내가 CommentStore에서 관찰 할 수있는 첨부 파일을 업데이트 할 수있는 방법은 무엇입니까?

답변

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

위 답변입니다. 나는 그것을 업데이트하고자하는 상점에 상점을 전달함으로써 동일한 대답을 발견했다. – rechie