|
1 | | -import { UPDATE_COUNTER, UPDATE_COMPLETE } from "../actions/counterActions"; |
2 | | -import { delay } from "redux-saga"; |
3 | | -import { put, takeEvery } from "redux-saga/effects"; |
| 1 | +import { FETCH_ISSUES, fetchComplete, UPDATE_AVATAR, putAvatar } from "../actions/counterActions"; |
| 2 | +import { put, takeEvery, call } from "redux-saga/effects"; |
4 | 3 |
|
5 | | -export function* count(action) { |
6 | | - yield delay(1000); //Delay the Counter By 1 Second |
7 | | - yield put({ type: UPDATE_COMPLETE, payload: action.payload }); //Send the Final Payload to the Reducer |
| 4 | + |
| 5 | + |
| 6 | +export function* fetchIssues() { |
| 7 | + const response = yield call(fetch, "https://api.github.com/repos/facebook/create-react-app/issues"); |
| 8 | + const body = yield call([response, 'json']); |
| 9 | + const issuesTitle = body.map(item => [item.title]) |
| 10 | + // console.log(nameAndFullName) |
| 11 | + yield put(fetchComplete(issuesTitle)) |
| 12 | + // console.log(body); |
8 | 13 | } |
9 | 14 |
|
| 15 | + |
| 16 | +// export function* fetchAvatar(params) { |
| 17 | +// // console.log(params); |
| 18 | +// const response = yield call(fetch, `https://api.github.com/users/${params.payload}`); |
| 19 | +// const body = yield call([response, 'json']); |
| 20 | +// const avatar = [body.avatar_url, params.payload] |
| 21 | +// yield put(putAvatar(avatar)) |
| 22 | +// // console.log(body); |
| 23 | +// } |
| 24 | + |
10 | 25 | // Our watcher Saga: spawn a new incrementAsync task on each INCREMENT_ASYNC |
11 | 26 | export function* watchCounter() { |
12 | | - yield takeEvery(UPDATE_COUNTER, count); |
| 27 | + yield takeEvery(FETCH_ISSUES, fetchIssues); |
| 28 | + // yield takeEvery(UPDATE_AVATAR, fetchAvatar); |
13 | 29 | } |
| 30 | + |
| 31 | + |
0 commit comments