From 5cde22c842d5fccfb9adc3ea579a49c396af9cbc Mon Sep 17 00:00:00 2001 From: Yuki Kodama Date: Wed, 11 May 2016 13:22:03 +0900 Subject: [PATCH] Use takeEvery instead of take --- autocomplete/sagas.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/autocomplete/sagas.js b/autocomplete/sagas.js index 3c799fc..6197821 100644 --- a/autocomplete/sagas.js +++ b/autocomplete/sagas.js @@ -1,11 +1,12 @@ +import { takeEvery } from 'redux-saga'; import { call, put, fork, take } from 'redux-saga/effects'; import { REQUEST_SUGGEST, successSuggest, failureSuggest } from './actions'; import API from './api'; -function* runRequestSuggest(text) { - const { data, error } = yield call(API.suggest, text); +function* runRequestSuggest(action) { + const { data, error } = yield call(API.suggest, action.payload); if (data && !error) { yield put(successSuggest({ data })); } else { @@ -14,10 +15,7 @@ function* runRequestSuggest(text) { } function* handleRequestSuggest() { - while (true) { - const { payload } = yield take(REQUEST_SUGGEST); - yield fork(runRequestSuggest, payload); - } + yield* takeEvery(REQUEST_SUGGEST, runRequestSuggest); } export default function* rootSaga() {