Redux-saga: [Feature] Add takeFirst()

Created on 18 Jun 2017  路  3Comments  路  Source: redux-saga/redux-saga

takeEvery() and takeLatest() are already implemented, whereas takeFirst() is not.

fork(function* () {
  while (true) {
    const action = yield take(ACTION_TYPE)
    yield call(doSomethingAsync, action)
  }
})

I want to simplify it into:
(The signature concept is the same as takeEvery() or takeLatest())

takeFirst(ACTION_TYPE, function* (action) {
  yield call(doSomethingAsync, action)
})

I prefer builtin takeFirst() API to third-party ones.

Most helpful comment

@jpetitcolas
Its easily implemented on the user-side with implementation provided by @mpyw . I would suggest creating ur own set of saga helpers anyway, so you can add it to those and import them just like effects - just from the other module.

There are no plans at the moment to expand on the built-in 'helpers', as the focus is on something else and the time is rly limited. That being said - I would love to create more robust helpers library in the future.

All 3 comments

However, I also think it should be limited by user interface disabling rather than saga.

<button disabled={state.pending}>Submit</button>

We also need the takeFirst effect. Adding the logic on the component may be a good idea in some cases, yet it adds some complexity on components, which can be easily removed using this new effect.

@jpetitcolas
Its easily implemented on the user-side with implementation provided by @mpyw . I would suggest creating ur own set of saga helpers anyway, so you can add it to those and import them just like effects - just from the other module.

There are no plans at the moment to expand on the built-in 'helpers', as the focus is on something else and the time is rly limited. That being said - I would love to create more robust helpers library in the future.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brunolemos picture brunolemos  路  3Comments

NullVoxPopuli picture NullVoxPopuli  路  3Comments

Moeriki picture Moeriki  路  3Comments

andresmijares picture andresmijares  路  3Comments

brunobelotti picture brunobelotti  路  3Comments