-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.js
27 lines (24 loc) · 838 Bytes
/
data.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import Models from 'Stores/models'
import { DomainStore } from '@ngyv/re-modelr'
import { decorate, observable, computed } from 'mobx'
class DStore extends DomainStore {
_fetchAll(params) {
return this._api.get(params, {}, 'include')
}
_fetchOne(params) {
return this._api.get(params, {}, 'include')
}
}
function store(modelClasses) {
decorate(DomainStore, {
entries: observable,
entriesArray: computed,
})
return Object.keys(modelClasses).reduce((store, modelClassName) => {
const modelName = modelClassName.replace('Model', '');
store[`${modelName}Store`] = new DStore(modelClasses[modelClassName], { basePath: 'https://my-json-server.typicode.com/ngyv/re-modelr-mobx-demo', modelName: modelName.toLowerCase() });
return store;
}, {});
}
const Store = store(Models);
export default Store;