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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| import FeedService from '../../services/FeedService'; import { createAction, createActions, handleActions } from 'redux-actions'; import { put, call, takeEvery } from 'redux-saga/effects';
const options = { prefix: 'd-code/feed', };
const { success, pending, fail } = createActions( { SUCCESS: feeds => ({ feeds }), }, 'PENDING', 'FAIL', options );
export const getFeeds = createAction('GET_FEEDS');
function* fetchFeedLists() { try { yield put(pending()); const { data: feeds } = yield call(FeedService.getList); yield put(success(feeds.data)); } catch (error) { console.log('error : ', error); yield put(fail(error)); } }
export function* feedSaga() { yield takeEvery(getFeeds, fetchFeedLists); }
const initialState = { feeds: null, loading: false, error: null, };
const feed = handleActions( { PENDING: state => ({ ...state, loading: true, error: null, }), SUCCESS: (state, action) => ({ feeds: action.payload.feeds, loading: false, error: null, }), FAIL: (state, action) => ({ ...state, loading: false, error: action.payload, }), }, initialState, options );
export default feed;
|