redux-saga / redux-saga

An alternative side effect model for Redux apps

Home Page:https://redux-saga.js.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Buffer actions and send one big bulk request

krystiansliwa opened this issue · comments

Hi,
How I can buffer some actions with the same type within some time box and next execute some request?
I tried to use combination of actionChannels and debounce but it is not working properly.

Use case:

  • user is clicking on the button which mark some object on the backend as a alerted
  • backend supports batch update

Here is my code that is not working :/

function* workerAlert(action: Action) {
  const type = action.type;
  const channel = yield actionChannel(type);

  yield debounce(1000, type, function* () {
    const actions = yield flush(channel);
    console.log(actions);
    // call server bulk action
  });
}

function* watchAlert() {
  yield takeLatest('ALERT', workerAlert);
}

function* sagas() {
  yield all([watchAlert()]);
}

Greetings! Sorry for the late response. Do you still need help with this issue? What part of this code isn't working for you?

Closing for now. If you still need help with this issue then I'll reopen and continue the discussion! Thanks!