'redux-observable'; 4 import { of } from 'rxjs'; 5 import { switchMap, map, catchError, tap, delay } from 'rxjs/ operators'; 6 import { ajax } from 'rxjs/ajax'; 7 export default action$ => 8 action$.pipe( 9 ofType('FETCH_TODOS_PENDING'), 10 switchMap(action => 11 ajax.getJSON('http://localhost:3000/dummy_todos.json').pipe( 12 map(response => { 13 return { 14 type: 'FETCH_TODOS_SUCCESS', 15 payload: response.data, 16 }; 17 }), 18 catchError(error => 19 of({ 20 type: 'FETCH_TODOS_FAILURE', 21 payload: error.message, 22 error: true, 23 }) 24 ) 25 ) 26 ) 27 ); 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 27