zloctb
zloctb

Reputation: 11186

how generate step by step call generator function in redux-saga?

function* mySaga() {

    const score1 = yield*  call(asyncTsec, 3);
    yield put({type:'ADD_ARTIST' , payload:score1 })

    const score2 = yield*  call(asyncTsec, 1);
    yield put({type:'ADD_ARTIST' , payload:score2 })

    const score3 = yield*  call(asyncTsec, 2);
    yield put({type:'ADD_ARTIST' , payload:score3 });
}

how generate step by step call this function by redux-saga like example ?

function* logGenerator() {
  console.log(yield);
  console.log(yield);
  console.log(yield);
}

var gen = logGenerator();


gen.next(); 
gen.next('pretzel'); // pretzel
gen.next('california'); // california
gen.next('mayonnaise'); // mayonnaise 

Upvotes: 1

Views: 852

Answers (1)

Vladislav Ihost
Vladislav Ihost

Reputation: 2187

how generate step by step call this function by redux-saga like example ?

For a start it is obviously necessary to separate that does redux-saga with effects and that is feature of generator functions. From caller side each generator is just a function which returns an iterator, and from internal behavior it's interruptible function with saving/resuming point of execution.

Redux-saga is just a way to describe asynchronous processes in yieldable style, depend on supposed effects list. Every yield action, like yield call(...) or yield put(...) just returns special object, depend on which saga process manager performs real action, for example, waiting promises / async functions, and return result into next step of generator function.

So simplest saga-like process manager can be rewritten as following: https://stackoverflow.com/a/47302202/7878274. It does not support yield* operator, but can be easily added with if-branch with duck-typing check on returning Iterable object

Upvotes: 1

Related Questions