Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. function* saveUnsavedFilesToServer(action) {
  2. //Don't even bother to try saving if we don't have an Internet connection
  3. let isConnected = yield call(NetInfo.isConnected.fetch);
  4. if (!isConnected) return;
  5.  
  6. //..send files to server
  7. }
  8.  
  9. function* watchToSaveFilesToServer() {
  10. yield throttle(
  11. 1000,
  12. [FILE_PROCESS_SUCCESS, NETWORK_INTERNET_ON],
  13. saveUnsavedFilesToServer
  14. );
  15. }
  16.  
  17. export function* throttleIfConnected(ms, pattern, task, ...args) {
  18. const throttleChannel = yield actionChannel(pattern, buffers.sliding(1));
  19.  
  20. while (true) {
  21. const action = yield take(throttleChannel);
  22. const isConnected = yield call(NetInfo.isConnected.fetch);
  23. if (isConnected) yield fork(task, ...args, action);
  24. yield call(delay, ms);
  25. }
  26. }
  27.  
  28. function* throttle(ms, pattern, task, ...args) {
  29. const throttleChannel = yield actionChannel(pattern, buffers.sliding(1))
  30.  
  31. while (true) {
  32. const action = yield take(throttleChannel)
  33. yield fork(task, ...args, action)
  34. yield call(delay, ms)
  35. }
  36. }
  37.  
  38. export function* callIfConnected(task, ...args) {
  39. let isConnected = yield call(NetInfo.isConnected.fetch);
  40. if (isConnected) yield call(task, ...args);
  41. }
  42.  
  43. const x = yield call(NetInfo.getConnectionInfo);
  44. if(x.type !== "none"){
  45. yield all([call(bestSellers), call(products)]);
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement