Added event emitters and fixed document deletion

This commit is contained in:
Jori Lallo
2017-08-03 16:48:07 +03:00
parent 0851cf3fc2
commit ad44c67a46
9 changed files with 65 additions and 12 deletions

View File

@ -3,12 +3,13 @@ import { extendObservable, action, computed, runInAction } from 'mobx';
import invariant from 'invariant';
import _ from 'lodash';
import BaseModel from 'models/BaseModel';
import { client } from 'utils/ApiClient';
import stores from 'stores';
import ErrorsStore from 'stores/ErrorsStore';
import type { NavigationNode } from 'types';
class Collection {
class Collection extends BaseModel {
isSaving: boolean = false;
hasPendingChanges: boolean = false;
errors: ErrorsStore;
@ -85,8 +86,14 @@ class Collection {
}
constructor(collection: Object = {}) {
super();
this.updateData(collection);
this.errors = stores.errors;
this.on('document.delete', (data: { collectionId: string }) => {
if (data.collectionId === this.id) this.fetch();
});
}
}