Added event emitters and fixed document deletion
This commit is contained in:
@ -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(
|
||||
|
Reference in New Issue
Block a user