forked from bamlab/react-native-testing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsagas.ts
More file actions
23 lines (20 loc) · 868 Bytes
/
sagas.ts
File metadata and controls
23 lines (20 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { put, takeEvery, delay, call, all } from 'redux-saga/effects';
import { MoviesActionTypes } from './types';
import { MoviesActions } from './actions';
import { addLoader } from '../loading/sagas';
import { LoaderName } from '../loading/types';
import { MoviesApi } from '../../api/movies';
function* getMoviesSaga() {
try {
// eslint-disable-next-line @typescript-eslint/unbound-method
const [movies] = yield all([call(MoviesApi.getMovies), delay(2000)]);
// delay is used here for testing purposes to demonstrate how to use jest timers
const movieTitles = movies.results.map(movie => movie.title);
yield put(MoviesActions.getMoviesSuccess(movieTitles));
} catch (err) {
console.log(err);
}
}
export function* getMoviesWatcher() {
yield takeEvery(MoviesActionTypes.GET_MOVIES, addLoader(getMoviesSaga, LoaderName.Movies));
}