Guest User

Untitled

a guest
Jan 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. // saga.js
  2. function* FetchData() {
  3. try {
  4. const AppData = yield call(fetch_Data, "LOAD_APP", App_Url);
  5. yield put({ type: "LOAD_APP", data: AppData })
  6. } catch (error) {
  7. console.log(error)
  8. }
  9. }
  10.  
  11. function* watchFetchAPI() {
  12. yield takeEvery("LOAD_ASYNC", FetchData)
  13. }
  14.  
  15. export default function* rootSaga() {
  16. yield all([
  17. watchFetchAPI()
  18. ])
  19. }
  20.  
  21. // action.js
  22. export function fetch_Data(type, url) {
  23. fetch(url, {
  24. method: 'GET',
  25. headers: {
  26. "Accept": "application/json",
  27. "Content-Type": "application/json"
  28. },
  29. contentType: 'json'
  30. }).then(function (res) {
  31. if (res.ok) {
  32. return res.json();
  33. } else {
  34. console.log("Failed. type: " + type + " Url: " + url);
  35. }
  36. }).catch(function (e) {
  37. console.log("Failed. type: " + type + " Url: " + url);
  38. console.log(e)
  39. })
  40. }
Add Comment
Please, Sign In to add comment