Fixed flow errors and small refactor
This commit is contained in:
@ -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);
|
||||
};
|
||||
|
Reference in New Issue
Block a user