Skip to content
This repository was archived by the owner on Apr 13, 2021. It is now read-only.
This repository was archived by the owner on Apr 13, 2021. It is now read-only.

Add 'deleteTodo' saga with confirmation yield #18

Description

@smeijer

Editing is fun; but deleting often requires confirmation. I would suggest to show the real power of sagas, and add a deleteTodo saga that takes a user confirmation before deleting anything.

Something like:

try {
  const { confirmed } = yield race({
    confirmed: take(CONFIRM_DELETE_TODO),
    cancelled: take(CANCEL_DELETE_TODO),
  });

  if (!confirmed) {
    put ({ type: DELETE_TODO_CANCELLED });
    return;
  }

  const { data } = yield call(api.delete, { payload });
  yield put({ type: DELETE_TODO_SUCCESS, payload: result });
}
catch (err) {
  yield put({ type: DELETE_TODO_ERROR, payload: { error: error.message } });
}

Bonus; race against a timeout to force the user to 'confirm' before x seconds.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions