Hillary and Trump sagas
This commit is contained in:
parent
a2b8e7480e
commit
aac33139ba
5 changed files with 75 additions and 11 deletions
|
@ -1,6 +1,14 @@
|
|||
import { takeEvery, call, put } from 'redux-saga/effects'
|
||||
import { takeEvery, call, put, all } from 'redux-saga/effects'
|
||||
|
||||
export default function* watcherSaga() {
|
||||
yield all([
|
||||
worker(),
|
||||
workerHillary(),
|
||||
workerTrump()
|
||||
])
|
||||
}
|
||||
|
||||
function* worker() {
|
||||
yield takeEvery("DATA_REQUESTED", workerSaga)
|
||||
}
|
||||
|
||||
|
@ -13,12 +21,46 @@ function* workerSaga() {
|
|||
}
|
||||
}
|
||||
|
||||
function getData() {
|
||||
// return fetch("http://localhost:3030/api/twitter?hashtag=tesla").then(res1 =>
|
||||
// res1.json()
|
||||
// )
|
||||
function* workerHillary() {
|
||||
yield takeEvery("DATA_TRUMP_REQUESTED", workerTrumpSaga)
|
||||
}
|
||||
|
||||
function* workerHillarySaga() {
|
||||
try {
|
||||
const payload = yield call(getHillaryData)
|
||||
yield put({ type: "DATA_LOADED", payload })
|
||||
} catch (e) {
|
||||
yield put({ type: "API_ERRORED", payload: e })
|
||||
}
|
||||
}
|
||||
|
||||
function* workerTrump() {
|
||||
yield takeEvery("DATA_HILLARY_REQUESTED", workerHillarySaga)
|
||||
}
|
||||
|
||||
function* workerTrumpSaga() {
|
||||
try {
|
||||
const payload = yield call(getTrumpData)
|
||||
yield put({ type: "DATA_LOADED", payload })
|
||||
} catch (e) {
|
||||
yield put({ type: "API_ERRORED", payload: e })
|
||||
}
|
||||
}
|
||||
|
||||
function getData() {
|
||||
return fetch("https://jsonplaceholder.typicode.com/posts").then(response =>
|
||||
response.json()
|
||||
)
|
||||
}
|
||||
|
||||
function getHillaryData() {
|
||||
return fetch("http://localhost:3030/api/twitter?hashtag=Hillary%20Clinton").then(res1 =>
|
||||
res1.json()
|
||||
)
|
||||
}
|
||||
|
||||
function getTrumpData() {
|
||||
return fetch("http://localhost:3030/api/twitter?hashtag=Donald%20Trump").then(res1 =>
|
||||
res1.json()
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue