Skip to content

Commit

Permalink
Use takeEvery instead of take
Browse files Browse the repository at this point in the history
  • Loading branch information
kuy committed May 11, 2016
1 parent 8d84955 commit 5cde22c
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions autocomplete/sagas.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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() {
Expand Down

0 comments on commit 5cde22c

Please sign in to comment.