shareDetailActions.js
960 Bytes
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict';
import ReactNative from 'react-native';
import Service from '../../services/ShareDetailService';
const {
SHARE_DETAIL_REQUEST,
SHARE_DETAIL_SUCCESS,
SHARE_DETAIL_FAILURE
} = require('../../constants/actionTypes').default;
export function shareDetailRequest() {
return {
type: SHARE_DETAIL_REQUEST
}
}
export function shareDetailSuccess(json) {
return {
type: SHARE_DETAIL_SUCCESS,
payload: json
}
}
export function shareDetailFailue(error) {
return {
type: SHARE_DETAIL_FAILURE,
payload: error
}
}
export function fetchShareDetail(params) {
return async (dispatch, getState) => {
let { app: { host } } = getState();
let data;
try {
data = await new Service(host).fetchShareDetail(params);
} catch(error) {
dispatch(shareDetailFailue(error));
}
dispatch(shareDetailSuccess(data));
}
}