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

@ -11,6 +11,7 @@ import { client } from 'utils/ApiClient';
import _ from 'lodash';
import invariant from 'invariant';
import BaseStore from 'stores/BaseStore';
import stores from 'stores';
import Document from 'models/Document';
import ErrorsStore from 'stores/ErrorsStore';
@ -22,7 +23,7 @@ type Options = {
cache: CacheStore,
};
class DocumentsStore {
class DocumentsStore extends BaseStore {
@observable recentlyViewedIds: Array<string> = [];
@observable data: Map<string, Document> = new ObservableMap([]);
@observable isLoaded: boolean = false;
@ -122,6 +123,8 @@ class DocumentsStore {
};
constructor(options: Options) {
super();
this.errors = stores.errors;
this.cache = options.cache;
@ -131,6 +134,10 @@ class DocumentsStore {
}
});
this.on('document.delete', (data: { id: string }) => {
this.remove(data.id);
});
autorunAsync('DocumentsStore.persists', () => {
if (this.data.size) {
this.cache.setItem(