Fixed flow errors and small refactor

This commit is contained in:
Jori Lallo
2017-07-09 11:26:17 -07:00
parent d72f73ab18
commit c4b41a9e07
12 changed files with 33 additions and 22 deletions

View File

@ -1,5 +1,5 @@
// @flow
import { observable, action, ObservableMap, runInAction } from 'mobx';
import { observable, action, computed, ObservableMap, runInAction } from 'mobx';
import { client } from 'utils/ApiClient';
import _ from 'lodash';
import invariant from 'invariant';
@ -14,6 +14,23 @@ class DocumentsStore {
@observable isLoaded: boolean = false;
errors: ErrorsStore;
/* Computed */
@computed get recentlyViewed(): Array<Document> {
return _.filter(this.data.values(), ({ id }) =>
this.recentlyViewedIds.includes(id)
);
}
@computed get recentlyEdited(): Array<Document> {
// $FlowIssue
return this.data.values();
}
@computed get starred(): Array<Document> {
return _.filter(this.data.values(), 'starred');
}
/* Actions */
@action fetchAll = async (request: string = 'list'): Promise<*> => {
@ -71,16 +88,6 @@ class DocumentsStore {
this.data.delete(id);
};
getStarred = () => {
return _.filter(this.data.values(), 'starred');
};
getRecentlyViewed = () => {
return _.filter(this.data.values(), ({ id }) =>
this.recentlyViewedIds.includes(id)
);
};
getById = (id: string): ?Document => {
return this.data.get(id);
};