Trigger collection update when document gets updated (renamed)
This commit is contained in:
@ -93,7 +93,7 @@ class Collection extends BaseModel {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
updateData(data: Object = {}) {
|
@action updateData(data: Object = {}) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
extendObservable(this, data);
|
extendObservable(this, data);
|
||||||
}
|
}
|
||||||
@ -107,6 +107,14 @@ class Collection extends BaseModel {
|
|||||||
this.on('documents.delete', (data: { collectionId: string }) => {
|
this.on('documents.delete', (data: { collectionId: string }) => {
|
||||||
if (data.collectionId === this.id) this.fetch();
|
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();
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,6 +160,11 @@ class Document extends BaseModel {
|
|||||||
this.updateData(res.data);
|
this.updateData(res.data);
|
||||||
this.hasPendingChanges = false;
|
this.hasPendingChanges = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.emit('collections.update', {
|
||||||
|
id: this.collection.id,
|
||||||
|
collection: this.collection,
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.errors.add('Document failed saving');
|
this.errors.add('Document failed saving');
|
||||||
} finally {
|
} finally {
|
||||||
|
Reference in New Issue
Block a user