Trigger collection update when document gets updated (renamed)

This commit is contained in:
Jori Lallo
2017-09-12 19:54:22 -07:00
parent ce5b6e6ac8
commit e40d9cebda
2 changed files with 14 additions and 1 deletions

View File

@ -93,7 +93,7 @@ class Collection extends BaseModel {
}
};
updateData(data: Object = {}) {
@action updateData(data: Object = {}) {
this.data = data;
extendObservable(this, data);
}
@ -107,6 +107,14 @@ class Collection extends BaseModel {
this.on('documents.delete', (data: { collectionId: string }) => {
if (data.collectionId === this.id) this.fetch();
});
this.on(
'collections.update',
(data: { id: string, collection: Collection }) => {
// FIXME: calling this.updateData won't update the
// UI. Some mobx issue
if (data.id === this.id) this.fetch();
}
);
}
}