Guest User

Untitled

a guest
Feb 24th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. export default function* rootSaga() {
  2. yield [
  3. helloSaga(),
  4. watchIncrementAsync()
  5. ]
  6. }
  7.  
  8. export default function* rootSaga() {
  9. yield fork(watchFetchUsers)
  10. yield fork(watchCreateUser)
  11. }
  12.  
  13. export default function* root() {
  14. yield [
  15. fork(getAllProducts),
  16. fork(watchGetProducts),
  17. fork(watchCheckout)
  18. ]
  19. }
  20.  
  21. const makeRestartable = (saga) => {
  22. return function* () {
  23. yield spawn(function* () {
  24. while (true) {
  25. try {
  26. yield call(saga);
  27. console.error("unexpected root saga termination. The root sagas are supposed to be sagas that live during the whole app lifetime!",saga);
  28. } catch (e) {
  29. console.error("Saga error, the saga will be restarted",e);
  30. }
  31. yield delay(1000); // Workaround to avoid infinite error loops
  32. }
  33. })
  34. };
  35. };
  36.  
  37. const rootSagas = [
  38. domain1saga,
  39. domain2saga,
  40. domain3saga,
  41. ].map(makeRestartable);
  42.  
  43. export default function* root() {
  44. yield rootSagas.map(saga => call(saga));
  45. }
  46.  
  47. import { fork, all } from 'redux-saga/effects';
  48. import firstSaga from './firstSaga';
  49. import secondSaga from './secondSaga';
  50. import thirdSaga from './thirdSaga';
  51.  
  52. export default function* rootSaga() {
  53. yield all([
  54. fork(firstSaga),
  55. fork(secondSaga),
  56. fork(thirdSaga),
  57. ]);
  58. }
  59.  
  60. // foo.js
  61. import { takeEvery } from 'redux-saga/effects';
  62. export const fooSagas = [
  63. takeEvery("FOO_A", fooASaga),
  64. takeEvery("FOO_B", fooBSaga),
  65. ]
  66.  
  67. // bar.js
  68. import { takeEvery } from 'redux-saga/effects';
  69. export const barSagas = [
  70. takeEvery("BAR_A", barASaga),
  71. takeEvery("BAR_B", barBSaga),
  72. ];
  73.  
  74. // index.js
  75. import { fooSagas } from './foo';
  76. import { barSagas } from './bar';
  77.  
  78. export default function* rootSaga() {
  79. yield all([
  80. ...fooSagas,
  81. ...barSagas
  82. ])
  83. }
Add Comment
Please, Sign In to add comment