Merge branch 'master' into jori/cache

This commit is contained in:
Jori Lallo
2017-07-17 22:17:39 -07:00
committed by GitHub
23 changed files with 286 additions and 30 deletions

View File

@@ -26,7 +26,8 @@ class DocumentsStore {
@observable recentlyViewedIds: Array<string> = [];
@observable data: Map<string, Document> = new ObservableMap([]);
@observable isLoaded: boolean = false;
@observable isFetching: boolean = false;
errors: ErrorsStore;
cache: CacheStore;
@@ -50,6 +51,8 @@ class DocumentsStore {
/* Actions */
@action fetchAll = async (request: string = 'list'): Promise<*> => {
this.isFetching = true;
try {
const res = await client.post(`/documents.${request}`);
invariant(res && res.data, 'Document list not available');
@@ -63,6 +66,8 @@ class DocumentsStore {
return data;
} catch (e) {
this.errors.add('Failed to load documents');
} finally {
this.isFetching = false;
}
};
@@ -79,6 +84,8 @@ class DocumentsStore {
};
@action fetch = async (id: string): Promise<*> => {
this.isFetching = true;
try {
const res = await client.post('/documents.info', { id });
invariant(res && res.data, 'Document not available');
@@ -93,6 +100,8 @@ class DocumentsStore {
return document;
} catch (e) {
this.errors.add('Failed to load documents');
} finally {
this.isFetching = false;
}
};