-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsaga.js
33 lines (27 loc) · 774 Bytes
/
saga.js
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
import { all, call, delay, put, take, takeLatest } from 'redux-saga/effects'
import { actionTypes, failure, loadDataSuccess, tickClock } from './actions';
const fetch = require("node-fetch");
function* runClockSaga() {
yield take(actionTypes.START_CLOCK)
while (true) {
yield put(tickClock(false))
yield delay(1000)
}
}
function* loadDataSaga() {
try {
const res = yield fetch('https://currencyapi.net/api/v1/rates?key=Pu2adq0vvTMQ4UhU3sRA8kBlluu7fok94EQU')
console.log(res)
const data = yield res.json()
yield put(loadDataSuccess(data))
} catch (err) {
yield put(failure(err))
}
}
function* rootSaga() {
yield all([
call(runClockSaga),
takeLatest(actionTypes.LOAD_DATA, loadDataSaga),
])
}
export default rootSaga