Skip to content

Commit 67d84db

Browse files
committed
Added get method
1 parent 76cd165 commit 67d84db

3 files changed

Lines changed: 31 additions & 10 deletions

File tree

src/actions/Fetch.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ export default class Fetch extends Action {
2323
data,
2424
});
2525
})
26-
.catch(error => {
27-
commit('onError', error)
28-
})
26+
.catch(error => commit('onError', error))
2927

3028
return request;
3129
}

src/actions/Get.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
1+
import Axios from '../orm/axios';
12
import Action from './Action'
3+
import Context from '../common/context'
24

35
export default class Get extends Action {
4-
static call ({ state, dispatch }, params={}) {
5-
console.log(state, dispatch, params);
6+
/**
7+
* Call $get method
8+
* @param {object} store
9+
* @param {object} params
10+
*/
11+
static async call ({ state, commit }, params = {}) {
12+
const context = Context.getInstance();
13+
const model = context.getModelFromState(state);
14+
const endpoint = Action.transformParams('$get', model, params);
15+
const axios = new Axios(model.methodConf.http);
16+
const request = axios.get(endpoint);
17+
18+
commit('onRequest');
19+
request
20+
.then(data => {
21+
commit('onSuccess')
22+
model.insertOrUpdate({
23+
data,
24+
});
25+
})
26+
.catch(error => commit('onError', error))
27+
28+
return request;
629
}
730
}

src/vuex-orm-axios.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,23 @@ export default class VuexOrmAxios {
4747
return entity;
4848
});
4949

50-
context.components.Model.$fetch = async function (config = {}) {
50+
context.components.Model.$fetch = function (config = {}) {
5151
return this.dispatch('$fetch', config);
5252
};
5353

54-
context.components.Model.$get = async function (config = {}) {
54+
context.components.Model.$get = function (config = {}) {
5555
return this.dispatch('$get', config);
5656
};
5757

58-
context.components.Model.$create = async function (config = {}) {
58+
context.components.Model.$create = function (config = {}) {
5959
return this.dispatch('$create', config);
6060
};
6161

62-
context.components.Model.$update = async function (config = {}) {
62+
context.components.Model.$update = function (config = {}) {
6363
return this.dispatch('$update', config);
6464
};
6565

66-
context.components.Model.$delete = async function (config = {}) {
66+
context.components.Model.$delete = function (config = {}) {
6767
return this.dispatch('$delete', config);
6868
};
6969
}

0 commit comments

Comments
 (0)